Spring boot Apache Camel-Java DSL app reads messages from Kafka topic.
@Component
public class KafkaTopicService extends RouteBilder {
public void configure(){
from("kafka:myTopic?brokers=localhost:9092")
.log("Message received from Kafka: ${body}")}
}
If I stop Kafka I get org.apache.kafka.common.errors.DisconnectException
I looked into onException(...class).handled(true)
but Im not sure how to implement handling of the exception in my code. Can someone give me few implementation examples? What options are available? For example logging the message or reattempting to read message?
Documentation also mentions Quarkus. Do I need Quarkus to use onException()
?
You can do something like (have not tried running it so please take care of any typos)
Please note that I have added
bridgeErrorHandler=true
. Normally exception handling happens afterfrom
. In most of the case usingbridgeErrorHandler
we can useonException
function for those.Also note that I have defined onException outside your route, so the exception handling logic which you add would be global and applicable to all routes wherever you encounter
DisconnectException