This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector-examples.git
The following commit(s) were added to refs/heads/master by this push: new 7054a1d Added a simple DLQ example 7054a1d is described below commit 7054a1df90efd6cd8556b38110cc33a87a42ee20 Author: Otavio Rodolfo Piske <opi...@redhat.com> AuthorDate: Wed Jan 20 16:30:22 2021 +0100 Added a simple DLQ example --- other-examples/error-handling-sink/README.adoc | 87 ++++++++++++++++++++++ .../config/CamelSjms2Invalid.properties | 31 ++++++++ 2 files changed, 118 insertions(+) diff --git a/other-examples/error-handling-sink/README.adoc b/other-examples/error-handling-sink/README.adoc new file mode 100644 index 0000000..173b740 --- /dev/null +++ b/other-examples/error-handling-sink/README.adoc @@ -0,0 +1,87 @@ +# Camel-Kafka-connector Error Handling Example + +## Introduction + +This shows how to use dead letter queues for sink error handling with Camel Kafka Connector. +It tries to send a message to an invalid JMS message broker. Because the message broker does +not exist, the message will be routed to the dead letter queue (DLQ). + +## What is needed + +- Kafka + +## Running Kafka + +``` +$KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties +$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties +$KAFKA_HOME/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic mytopic +``` + +## Setting up the needed bits and running the example + +You'll need to setup the plugin.path property in your kafka + +Open the `$KAFKA_HOME/config/connect-standalone.properties` + +and set the `plugin.path` property to your choosen location + +In this example we'll use `/home/oscerd/connectors/` + +``` +> cd /home/otavio/connectors/ +> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-sjms2-kafka-connector/0.7.0/camel-sjms2-kafka-connector-0.7.0-package.zip +> unzip camel-sjms2-kafka-connector-0.7.0-package.zip +``` + +Open the SJMS2 configuration file + +``` +name=CamelJmsSinkConnector +topics=mytopic +tasks.max=1 +connector.class=org.apache.camel.kafkaconnector.sjms2.CamelSjms2SinkConnector +key.converter=org.apache.kafka.connect.storage.StringConverter +value.converter=org.apache.kafka.connect.storage.StringConverter + +camel.sink.url=sjms2://queue:myqueue + +camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory + +# Note the invalid address below +camel.component.sjms2.connection-factory.brokerURL=tcp://invalid-host.some-domain.com + +# This is the topic where they will be sent on errors +errors.deadletterqueue.topic.name=example-dlq +errors.deadletterqueue.topic.replication.factor=1 +``` + +And add the correct address for the server. + +Now you can run the example + +``` +$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelSjms2Invalid.properties +``` + +To read the messages from the DLQ, first open a consumer attached to it: + +``` +$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic example-dlq +``` + +On a different terminal run the kafka-producer and send a message to your Kafka Broker. + +``` +bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic +Invalid messsage +``` + +On the consumer, you should receive the message that was routed to the DLQ because it could +not be delivered to the JMS broker. + +``` +$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic example-dlq +Invalid messsage +``` + diff --git a/other-examples/error-handling-sink/config/CamelSjms2Invalid.properties b/other-examples/error-handling-sink/config/CamelSjms2Invalid.properties new file mode 100644 index 0000000..e8cd36b --- /dev/null +++ b/other-examples/error-handling-sink/config/CamelSjms2Invalid.properties @@ -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. +# + +name=CamelJmsSinkConnector +topics=mytopic +tasks.max=1 +connector.class=org.apache.camel.kafkaconnector.sjms2.CamelSjms2SinkConnector +key.converter=org.apache.kafka.connect.storage.StringConverter +value.converter=org.apache.kafka.connect.storage.StringConverter + +camel.sink.url=sjms2://queue:myqueue + +camel.component.sjms2.connection-factory=#class:org.apache.activemq.ActiveMQConnectionFactory +camel.component.sjms2.connection-factory.brokerURL=tcp://invalid-host.some-domain.com + +errors.deadletterqueue.topic.name=example-dlq +errors.deadletterqueue.topic.replication.factor=1 \ No newline at end of file