This example shows how to read a Kafka topic, using the camel kafka component, and logs the messages to the console.
- A running Kafka cluster
- A topic named
test-topicwith some messages in it
- Open the
kafka-to-log.camel.yamlfile and set thebrokers,topicandsaslJaasConfigvalues to match your Kafka cluster 1.1. This example uses theSCRAM-SHA-256SASL mechanism. If you are using a different mechanism, you need to change thesaslJaasConfigvalue accordingly 1.2. This example expects to have a secret namedkafka-user-passwordswith aclient-passwordskey containing the password for the Kafka cluster - Run the integration using the Camel CLI extension, or by executing the following command:
jbang '-Dcamel.jbang.version=4.5.0' camel@apache/camel run kafka-to-log.camel.yaml --dev --logging-level=info --local-kamelet-dir=.You can pass the Kafka consumer parameters as plain values, environment variables or secrets. Here is an example of how to pass the parameters as plain values:
parameters:
brokers: kafka-cluster-name:port
clientId: camel-route-client
saslJaasConfig: org.apache.kafka.common.security.scram.ScramLoginModule required username="user1" password="password";
saslMechanism: SCRAM-SHA-256
securityProtocol: SASL_PLAINTEXTHere is an example of how to pass the parameters as secrets:
parameters:
brokers: kafka-cluster-name:port
clientId: camel-route-client
saslJaasConfig: org.apache.kafka.common.security.scram.ScramLoginModule required username="user1" password="{{secret:kafka-user-passwords/client-passwords}}";
saslMechanism: SCRAM-SHA-256
securityProtocol: SASL_PLAINTEXT