This workshop aims to help you have your first hands-on experience with Camel K and the important concepts such as Kamelets, KameletBinding and Knative.
Before we start going through the workshop, make sure that you have VSCode or VSCodium installed on your machine.
If you are familiar with Git, you can clone this GitHub Repository and open it with VSCode.
We need to install the VSCode extensions -- Extension Pack for Apache Camel by Red Hat for later use.
In this workshop, we will create and run all the Camel K integrations on the OpenShift cluster.
We need to use the following CLI to execute the integration files later on, therefore, make sure that you installed all the following CLIs on your machine:
We need the following operators installed on the OpenShift cluster:
- Red Hat Integration - Camel K
- Red Hat OpenShift Serverless
First, we need to login to the OpenShift cluster from both web console and terminal.
Note: we will elaborate on this during the workshop.
This example demonstrates a simple Camel K integration that periodically prints a "Hello World from Camel K"Open the terminal in the VSCode
☐ Open the terminal in the VSCode
☐ Login to OpenShift in the terminal
☐ oc new-project userX-helloworld
- create a new project with userx-helloworld
☐ oc get csv
- you should see the Camel K operator running
☐ Create a helloworld.groovy file
We will elaborate on the integration file during the workshop
☐ kamel run helloworld.groovy
- run the integration using kamel
It might take up to 3min for the integration running.
☐ oc get integrations
- check if the integration is running
☐ kamel logs helloworld
- get the logs of the running integration
You will see the hello world message printing out in the terminal each 3 seconds If you run
kamel run helloworld.groovy --logs
in the beginning, you will see the logs showing in the terminal as well
☐ kamel run helloworld.groovy --dev
- alternatively, run the integration in the dev mode
☐ change the from('timer:tick?period=3000')
to from('timer:tick?period=5000')
in the helloworld.groovy
file
The running integratino will reload itself first, a few seconds later you will see the hello world message printing out in the terminal every 5 seconds
☐ oc delete project userx-helloworld
- clean up the namespace
This example demonstrates how to create a simple Chuck Norris Kamelet source and how to integrate it with telegram. Our goal is to receive some funny jokes on our telegram.
Note: if you haven't used telegram before, you can simply download the
Telegram
mobile app and create a new account there. Remember to create an unique username as well.
We still need two things:
- A telegram bot
- Chat ID
☐ Search for username @BotFather
☐ Start the chat (/start)
☐ Send /newbot to @BotFather
☐ Follow the instruction of @BotFather and create a name and username for the bot.
☐ Once the bot is created, we will get a token to access the HTTP API, keep the token secure and store it safely.
☐ You should search for your newly-created bot and click /start to initiate the conversation with the bot.
☐ Search for username @RawDataBot with name Telegram Bot Raw
☐ Start the chat (/start)
☐ You will receive a message from the @RawDataBot, store the "id"
in the "chat"
section somewhere safe.
Once we get the telegram bot token and the chat ID, remember to save it somewhere that you can find them. We will need them in the following examples.
☐ oc new-project userX-chuck-norris
- create a new project for the second example
☐ Create a chuck-norris-source.kamelet.yaml
More details will be present during the workshop.
☐ oc apply -f chuck-norris-source.kamelet.yaml
- use the kamel
to create the chuck norris source kamelet
You can use
kamel init xxxx-source.kamelet.yaml / xxxx-sink.kamelet.yaml
to instantiate a kamelet template for creating your own custom kamelet.
☐ oc get kamelets
- check if the chuck norris source is ready
☐ create a chuck-norris-example.groovy
☐ kamel run chuck-norris-example.groovy --dev
- run the integration using chuck norris kamelet in the "dev mode"
You should see the jokes appearing in the terminal. All the supported languages for Camel K integration
☐ Change the .to('log:info')
to .to("telegram:bots?authorizationToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&chatID=XXXXXXXXXXXXX")
- run the integration with telegram, provide the bot Token and chat ID
You should see the jokes sending to your telegram.
☐ oc delete project userX-chuck-norris
- clean up the project
In this example, we will create a simple telegram source Kamelet
and use KameletBinding
to bind the source to a Knative channel. Then we will create a Printer that prints out the messages sent to the telegram source.
☐ oc new-project userX-message-printer
- create a new project for the message printer example
☐ oc get csv
- make sure the Camel K and Serverless is running in your namespace
We will elaborate more on the Serverless and Knative during the workshop.
☐ create a telegram-simple-source.kamelet.yaml
☐ oc apply -f telegram-simple-source.kamelet.yaml
- create the telegram source kamelet
More explanation for the kamelet file will be present in the workshop.
☐ oc get kamelets
- check if the source kamelet is ready
☐ Create a telegram-channel.yaml on the cluster
☐ oc apply -f telegram-channel.yaml
- create a Knative InMemory Channel
☐ create a telegram-source-binding.yaml that binds the Knative channel to the telegram source
☐ oc apply -f telegram-source-binding.yaml
- create the binding between the Knative channel and the telegram source
☐ oc get integrations
- check the status of the kamelet binding
☐ kamel run printer.groovy - create the integration that prints out the messages sent to the telegram bot
We will explain it in details during the workshop. You should see the printer running in one pod first
☐ Send some messages to your telegram bot
☐ kamel logs printer
- check the logs of the printer
You can also go to the OpenShift web console and check the logs of Printer pod.
☐ Stop sending messages to the telegram bot
☐ Printer pod autoscales to zero
☐ oc delete project userX-message-printer
- clean up the namespace