This is an automated email from the ASF dual-hosted git repository. tsato pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git
commit 4b323df3537ff401e49725643f75ca3afc573e00 Author: Kuthumi Pepple <[email protected]> AuthorDate: Wed Jul 27 18:58:58 2022 +0100 fix error and improve kafka example README.md --- generic-examples/kafka/README.md | 48 +++++++++++++++++++-------- generic-examples/kafka/application.properties | 2 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/generic-examples/kafka/README.md b/generic-examples/kafka/README.md index a651849..98d7388 100644 --- a/generic-examples/kafka/README.md +++ b/generic-examples/kafka/README.md @@ -1,30 +1,52 @@ -# Kafka Camel K examples +# Camel K with Kafka examples -This example shows how Camel K can be used to connect to a Kafka broker. +These examples show how to connect to a Kafka broker in a Camel K integration. + +You can find more information about Apache Camel and Apache Camel K on the [official Camel website](https://camel.apache.org). + +## Before you begin + +Read the general instructions in the [root README.md file](/README.md) for setting up your environment and the Kubernetes cluster before looking at this example. + +Make sure you've read the [installation instructions](https://camel.apache.org/camel-k/latest/installation/installation.html) for your specific +cluster before starting the example. + +## Additional Requirements for running the examples +**A Kafka broker**: handles the storage and passing of messages. ## Authentication to Kafka -We have a dedicated section to show [how to authenticate Camel K to Kafka](./sasl_ssl/). +To use Kafka with authentication, we have a dedicated section to show [how to authenticate Camel K to Kafka](./sasl_ssl/). \ +For a simple use case without client authentication, continue with this guide. + +## Understanding the example +- [SampleKafkaConsumer.java](./SampleKafkaConsumer.java): contains a route that reads message from a kafka topic and logs the message +- [application.properties](./application.properties): holds properties required to connect to kafka broker and read from topic. ## Simple usage -To run this example first set-up Kafka on your k8s cluster. -A convenient way to do so is by using the Strimzi project, if you are using minikube follow these instructions at https://strimzi.io/quickstarts/minikube/ +To run this example, first set-up Kafka on your k8s cluster. +A convenient way to do so is by using the Strimzi project. Visit https://strimzi.io/quickstarts/ for set-up instructions. For the instructions on the linked site, it will suffice to only apply the Strimzi installation file and provision the kafka cluster. -For convenience create a configmap to contain the properties: +IMPORTANT: The `kafka.host` value in `application.properties` needs to be set to the CLUSTER-IP address of the my-cluster-kafka-bootstrap service in the kafka namespace. To do this run: ``` -kubectl create configmap kafka.props --from-file=examples/kafka/application.properties +kafkaip=`kubectl get svc/my-cluster-kafka-bootstrap -n kafka -ojsonpath="{.spec.clusterIP}"`; sed -i "/kafka\.host/s/<.*>/$kafkaip/g" application.properties +``` + +Create a configmap to contain the properties: +``` +kubectl create configmap kafka.props --from-file=application.properties ``` -IMPORTANT: The kafka.host value in application.properties needs to be set to the CLUSTER-IP address of the my-cluster-kafka-bootstrap service in the kafka namespace: - `kubectl get services -n kafka | grep my-cluster-kafka-bootstrap | awk '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/ {print $3}'` + Finally run this sample using the command: ``` -./kamel run examples/kafka/SampleKafkaConsumer.java --config=configmap:kafka.props +kamel run SampleKafkaConsumer.java --config=configmap:kafka.props --dev ``` -To create messages to be read use the producer command from the Strimzi page: +To create messages to be read, use the producer command from the Strimzi page. Run in another terminal: +``` +kubectl -n kafka run kafka-producer -ti --image=quay.io/strimzi/kafka:0.30.0-kafka-3.2.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic ``` -kubectl -n kafka run kafka-producer -ti --image=strimzi/kafka:0.11.1-kafka-2.1.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic -``` \ No newline at end of file +You should see a prompt where you can type messages to be sent to the `my-topic` topic. \ No newline at end of file diff --git a/generic-examples/kafka/application.properties b/generic-examples/kafka/application.properties index 5723932..74959e2 100644 --- a/generic-examples/kafka/application.properties +++ b/generic-examples/kafka/application.properties @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -kafka.host=<see SampleKafkaConsumer.java for value to set here> +kafka.host=<Kafka Bootstrap IP> kafka.port=9092 consumer.topic=my-topic consumer.maxPollRecords=5000
