This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch release-1.4.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a38979b7695fa134ada2cf9dcb1233b6efef1c1c Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Thu Apr 29 12:21:45 2021 +0200 doc(examples): Kafka SASL SSL consumer --- examples/kafka/sasl_ssl/README.md | 23 +++++++++++++++++ examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java | 31 +++++++++++++++++++++++ examples/kafka/sasl_ssl/application.properties | 25 ++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/examples/kafka/sasl_ssl/README.md b/examples/kafka/sasl_ssl/README.md new file mode 100644 index 0000000..28251af --- /dev/null +++ b/examples/kafka/sasl_ssl/README.md @@ -0,0 +1,23 @@ +# Kafka Camel K SASL SSL example + +This example shows how Camel K can be used to connect to a generic Kafka broker using SASL SSL authentication mechanism. Edit the `application` properties file with the proper values to be able to authenticate a Kafka Broker and use any Topic. + +For convenience create a secret to contain the sensitive properties in the `application.properties` file: + +``` +kubectl create secret generic kafka-props --from-file application.properties +``` + +Finally run this sample using the command: + +``` +kamel run --secret kafka-props SaslSSLKafkaConsumer.java --dev +``` + +A consumer will start logging the events found in the Topic: + +``` +[1] 2021-04-29 08:57:16,894 INFO [FromKafka] (Camel (camel-1) thread #0 - KafkaConsumer[my-first-test]) Producing message #1096 +[1] 2021-04-29 08:57:18,995 INFO [FromKafka] (Camel (camel-1) thread #0 - KafkaConsumer[my-first-test]) Producing message #1097 +[1] 2021-04-29 08:57:20,879 INFO [FromKafka] (Camel (camel-1) thread #0 - KafkaConsumer[my-first-test]) Producing message #1098 +``` \ No newline at end of file diff --git a/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java b/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java new file mode 100644 index 0000000..6e14539 --- /dev/null +++ b/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// kubectl create secret generic kafka-props --from-file application.properties +// kamel run --secret kafka-props SaslSSLKafkaConsumer.java --dev + +import org.apache.camel.builder.RouteBuilder; + +public class SaslSSLKafkaConsumer extends RouteBuilder { + @Override + public void configure() throws Exception { + log.info("About to start route: Kafka Server -> Log "); + from("kafka:{{consumer.topic}}") + .routeId("FromKafka") + .log("${body}"); + } +} diff --git a/examples/kafka/sasl_ssl/application.properties b/examples/kafka/sasl_ssl/application.properties new file mode 100644 index 0000000..533271d --- /dev/null +++ b/examples/kafka/sasl_ssl/application.properties @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Kafka config +camel.component.kafka.brokers = *********************.kafka.my-cloud.service.com:443 +camel.component.kafka.security-protocol = SASL_SSL + +camel.component.kafka.sasl-mechanism = PLAIN +camel.component.kafka.sasl-jaas-config=org.apache.kafka.common.security.plain.PlainLoginModule required username=*** password=***; + +consumer.topic = my-first-test \ No newline at end of file