The quickstart can run with any Kafka instance. However we want to focus how to connect a Red Hat OpenShift Streams for Apache Kafka to Camel. In order to use it, you must login to the Red Hat Cloud (Beta). Please, consider the due limitations of this offering at the time of writing this tutorial.
In order to setup an instance and your first topic, you can follow up the UI quickstart or use the rhoas CLI.
Note: we assume in this tutorial that you are creating a topic named
test
. You can use any other name, just make sure to reflect the name chosen in thecamel.karaf.rhosak.cfg
configuration file.
Once you’ve setup your first topic, you must create a set of credentials that you will be using during this quickstart:
At this stage you should have the following credentials: a
kafka bootstrap URL
, a service account id
and a
service account secret
. You may also want to take note of the
Token endpoint URL
if you choose to use SASL/OAUTHBEARER
instead
of SASL/PLAIN
authentication method.
This example demonstrates using the camel-kafka component with Red Hat Fuse on Karaf to produce and consume kafka messages.
In this example, a Camel route produce at a fixed rate of 5s, String messages that are sent to kafka. A second route is subscribed to the kafka topic and print out the messages received.
-
Maven
-
A jboss fuse server installed
-
Configured kafka instance, topic and credentials on RHOSAK
-
A java version that support TLS 1.3 protocol, eg. from Oracle JDK 8u261-b12 or AdoptOpenJDK 8u272-b10 or java 11 (
fuse-karaf-openshift-jdk11-rhel8
image is used to build in java 11)
To run the example
-
Change your working directory to
resources
directory. -
edit
camel.karaf.rhosak.cfg
with parameters from RHOSAK, in particular:## Modify value of kafka.host and kafka.port before running application kafka.host=<FILLE_ME> kafka.port=<FILL_ME> # Service Account info sa.client.id=<FILL_ME> sa.client.secret=<FILL_ME> sa.token.endpoint.uri=<FILL_ME>
-
Build the project
mvn clean install
-
Start fuse:
For Linux:
${JBOSS_HOME}/bin/fuse clean
For Windows:
%JBOSS_HOME%\bin\fuse clean
-
Deploy config file
cp src/main/resources/camel.karaf.rhosak.cfg ${JBOSS_HOME}/etc
-
Deploy and start the bundle
From Karaf shell:
karaf@root()> feature:install camel-kafka
karaf@root()> bundle:install -s mvn:io.fabric8.quickstarts/karaf-camel-rhosak/1.0-SNAPSHOT
In the logs, you should see somethig like this:
karaf@root()> log:tail 15:28:43.489 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate 15:28:48.489 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate 15:28:53.556 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate 15:28:58.573 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate 15:29:03.518 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate 15:29:08.508 INFO [Camel (kafka-consumer) thread #106 - KafkaConsumer[test]] Greetings at fixed rate
Important
|
You need to run this example on Container Development Kit 3.3 or OpenShift 3.7. Both of these products have suitable Fuse images pre-installed. If you run it in an environment where those images are not preinstalled follow the steps described in Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images. |
To deploy this quickstart to a running OpenShift cluster:
-
Download the project and extract the archive on your local filesystem.
-
Log in to your OpenShift cluster:
$ oc login -u developer -p developer
-
Create a new OpenShift project for the quickstart:
$ oc new-project MY_PROJECT_NAME
-
Change the directory to the folder that contains the extracted quickstart application (for example,
my_openshift/karaf-camel-rhosak
) :$ cd my_openshift/karaf-camel-rhosak
-
Build and deploy the project to the OpenShift cluster:
$ mvn clean -DskipTests oc:deploy -Popenshift
-
List all the running pods:
$ oc get pods
-
Find the name of the pod that runs this quickstart. Output the logs from the running pods and see the messages sent by Camel:
$ oc logs <name of pod>
A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.
If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.
-
Log in to your OpenShift cluster:
$ oc login -u developer -p developer
-
Create a new OpenShift project for the quickstart:
$ oc new-project MY_PROJECT_NAME
-
Import base images in your newly created project (MY_PROJECT_NAME) according to documentation.
-
Change the directory to the folder that contains the extracted quickstart application (for example,
my_openshift/karaf-camel-rhosak
) :$ cd my_openshift/karaf-camel-rhosak
-
Build and deploy the project to the OpenShift cluster:
$ mvn clean -DskipTests oc:deploy -Popenshift -Djkube.generator.fromMode=istag -Djkube.generator.from=MY_PROJECT_NAME/fuse7-karaf-openshift:1.10
-
In your browser, navigate to the
MY_PROJECT_NAME
project in the OpenShift console. Wait until you can see that the pod for thekaraf-camel-rhosak
has started up. -
On the project’s
Overview
page, navigate to the details page deployment of thekaraf-camel-rhosak
application:https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/pods/karaf-camel-rhosak-NUMBER_OF_DEPLOYMENT?tab=details
. -
Switch to tab
Logs
and then see the messages sent by Camel.