Apache Camel source
All Camel Sources use Apache Camel K as the runtime engine.
Install the Operator in any namespace where you want to run Camel sources.
The preferred version that is compatible with Camel sources is Camel K v1.0.0-M4.
Installation instructions are provided in the . Documentation includes specific instructions for common Kubernetes environments, including development clusters.
Install the Camel Source from the in the Eventing Sources release page:
All the CamelSource
examples use some test resources for the purpose of displaying the generated events. The following resources need to be created:
- a simple Knative event display service that prints incoming events to its log
- an in-memory channel named
camel-test
that buffers events created by the event source - a subscription to direct events from the test channel to the event display service
Deploy the :
kubectl apply --filename display_resources.yaml
The samples directory contains some sample sources that can be used to generate events.
The simplest example of CamelSource
, that does not require additional configuration, is the timer source.
The timer source periodically generates “Hello world!” events and forwards them to the provided destination.
Install the timer CamelSource from source:
Verify that the published events were sent into the Knative eventing system by looking at what is downstream of the CamelSource
.
kubectl logs --selector serving.knative.dev/service=camel-event-display -c user-container
If you have deployed the timer source, you should see new log lines appearing every 3 seconds.
One of the 300+ Camel components that you can leverage is , based on the Eclipse Paho open source project.
A source based on Paho (like the provided ) allows to bridge any MQTT broker to a Knative resource, automatically converting IoT messages to Cloudevents.
To use the MQTT source, you need a MQTT broker running and reachable from your cluster. For example, it’s possible to run a Mosquitto MQTT Broker for testing purposes.
First, edit the and put the correct address of the MQTT broker in the brokerUrl
field. You also need to provide the name of the topic that you want to subscribe to: just change paho:mytopic
to match the topic that you want to use.
You can also scale this source out, in order to obtain more throughput, by changing the value of the replicas
field. By default it creates 2 replicas for demonstration purposes.
To reduce noise in the event display, you can remove all previously created CamelSources from the namespace:
Install the mqtt CamelSource:
You can now send MQTT messages to your broker using your favourite client (you can even use Camel K for sending test events).
You can verify that your messages reach the event display by checking its logs:
kubectl logs --selector serving.knative.dev/service=camel-event-display -c user-container
Another useful component available with Camel is the Telegram component. It can be used to forward messages of a chat into Knative channels as events.
Before using the provided Telegram CamelSource
example, you need to follow the instructions on the Telegram website for creating a Telegram Bot. The quickest way to create a bot is to contact the , another Telegram Bot, using your preferred Telegram client (mobile or web). After you create the bot, you will receive an authorization token that is needed for the source to work.
First, edit the telegram CamelSource and put the authorization token, replacing the <put-your-token-here>
placeholder.
To reduce noise in the event display, you can remove all previously created CamelSources from the namespace:
kubectl delete camelsource --all
Install the :
Now, you can contact your bot with any Telegram client. Each message you send to the bot will be printed by the event display as a Cloudevent.
You can verify that your messages reach the event display by checking its logs:
kubectl logs --selector serving.knative.dev/service=camel-event-display -c user-container
CamelSources are not limited to using a single Camel component. For example, you can combine the Camel Timer component with the to periodically fetch an external API, transform the result into a Cloudevent and forward it to a given destination.
The example will retrieve a static JSON file from a remote URL, but you can edit the HTTP poller CamelSource to add your own API.
If you have previously deployed other CamelSources, to reduce noise in the event display, you can remove them all from the namespace:
The event display will show some JSON data periodically pulled from the external REST API. To check the logs: