Hi

This is expected. onException in the route builder only happens when
you have a Camel exchange/message to route. And you dont have that
because you cannot connect to Kafka.

See for example the CiA2 book error handling chapter which talks about
this, and how some Camel components allow to bridge and report this as
a Camel exchange with the exception so you can deal with it using
onException.

On Thu, Nov 16, 2017 at 3:13 PM, Schondorf, Yacov
<yschond...@forcepoint.com> wrote:
> I am configuring Kafka as a source in my RouteBuilder. My goal is to handle 
> Kafka disconnection issues. My RouteBuilder is as follows:
> new RouteBuilder() {
>         public void configure() {
>             onException(Exception.class).process(exchange -> {
>                 final Exception exception = exchange.getException();
>                 logger.error(exception.getMessage());
>                 // will do more processing here
>             });
>             from(String.format("kafka:%s?brokers=%s:%s", topicName, host, 
> port)).bean(getMyService(), "myMethod")
>             .process(new Processor() {
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>                     // some more processing
>                 }
>             });
>         }
>     };
>
> I am configuring Kafka as a source in my RouteBuilder. My goal is to handle 
> Kafka disconnection issues. My RouteBuilder is as follows:
>
> new RouteBuilder() {
>
>         public void configure() {
>
>             onException(Exception.class).process(exchange -> {
>
>                 final Exception exception = exchange.getException();
>
>                 logger.error(exception.getMessage());
>
>                 // will do more processing here
>
>             });
>
>             from(String.format("kafka:%s?brokers=%s:%s", topicName, host, 
> port)).bean(getMyService(), "myMethod")
>
>             .process(new Processor() {
>
>                 @Override
>
>                 public void process(Exchange exchange) throws Exception {
>
>                     // some more processing
>
>                 }
>
>             });
>
>         }
>
>     };
>
> I provided wrong host and port, and expected to see an exception. However, no 
> exception is seen in the log, and the onException processing is not get 
> called. Any idea what I am doing wrong?
>
> A similar problem can be reproduced by running 
> https://github.com/apache/camel/blob/master/examples/camel-example-kafka/src/main/java/org/apache/camel/example/kafka/MessageConsumerClient.java
>  locally without any Kafka server running. Doing so results in a constant 
> flow of messages:
>
> Connection to node -1 could not be established. Broker may not be available.
> Is there a way to have an exception thrown? Any help would be appreciated.
>
> YACOV SCHONDORF
> Sr. Software Engineer
>
> FORCEPOINT
> ph: +972.9.776.4233
> fax:
> www.forcepoint.com<http://www.forcepoint.com>
>
> FORWARD WITHOUT FEAR
>
>
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to