camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Handling Exceptions not handled by the DeadLetterChannelBuilder
Date Wed, 23 Nov 2016 09:03:03 GMT
Any failures thrown from doStart method of the consumer is causing
Camel to not startup and fail.
At that time you cannot use bridge error handler.
Camel is not yet started and routing.

There are many Camel components that does some check on startup and
throw exception if its mis configured / cannot start / cannot connect
to remote system etc.



On Wed, Nov 23, 2016 at 9:49 AM, mayur_bm <mayur.bm@gmail.com> wrote:
>
> Thanks Claus.
>
>  my goal is to handle exception in DoStart method of my custom class which
> implements *DefaultConsumer*.  here i re-used the concept from the link you
> have given and tried throwing exception using below approach which will
> raise ExchangeFailedEvent . this event can be handled and i can take
> corrective action.
>
> private void triggerCMISComponentException(boolean onError,final String
> message,final Throwable cause) throws CMISComponentException{
>
>                 if(onError){
>                         ProducerTemplate template =
> exchange.getContext().createProducerTemplate();
>                          template.send("direct:file-error", new Processor() {
>                             @Override
>                             public void process(Exchange exchange) throws Exception {
>                                 // set an exception on the message from the start so
the
> error handling is triggered
>                                 exchange.setException(cause);
>                                 exchange.getIn().setBody(message);
>                             }
>                         });
>
>
>                 }
>
>         }
>
> without this approach i want to just throw Exceptions from DoStart Method
> (while validating some configuration data) and raise
> CamelContextStartupFailureEvent.
>
> below is the simple scenario i am checking in DoStart metod and throwing
> exception if invalid configuration found.
>
>         exchange = ((DemoEndpoint) getEndpoint()).createExchange();
>
> try {
>                         Logging.log(this.getClass(), LogLevel.DEBUG, "Path under monitoring:"
+
> path);
>
>                         directory = FileUtil.getFile(path);
>                 }
>                 catch (IllegalArgumentException | IOException e) {
>
>
>                         exchange.setException(e);
>
>                         throw new IOException(messageBody);
>
>
>                 }
>
> how do i handle this exception in simple way? is there any way i can raise
> CamelContextStartupFailureEvent ?
>
> Regards,
> Mayur
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handling-Exceptions-not-handled-by-the-DeadLetterChannelBuilder-tp5790316p5790396.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Mime
View raw message