You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mayur_bm <ma...@gmail.com> on 2016/11/22 04:10:51 UTC

Handling Exceptions not handled by the DeadLetterChannelBuilder

Hi,

i see that if component implements DefaultConsumer and its  being run in the
route & if it throws exception in application logic before an Exchange is
created and we call the processor.process(exchange). its not being handled
by the DeadLetterChannelBuilder ErrorHandlerRef which is defined in the
CamelContext. what is the approach we have to take to handle the exceptions
which are created before Exchange is created? ( mostly i see
CamelRuntimeException)

Regards,
Mayur 



--
View this message in context: http://camel.465427.n5.nabble.com/Handling-Exceptions-not-handled-by-the-DeadLetterChannelBuilder-tp5790316.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handling Exceptions not handled by the DeadLetterChannelBuilder

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See about the bridge error handler option
http://camel.apache.org/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.html



On Tue, Nov 22, 2016 at 5:10 AM, mayur_bm <ma...@gmail.com> wrote:
> Hi,
>
> i see that if component implements DefaultConsumer and its  being run in the
> route & if it throws exception in application logic before an Exchange is
> created and we call the processor.process(exchange). its not being handled
> by the DeadLetterChannelBuilder ErrorHandlerRef which is defined in the
> CamelContext. what is the approach we have to take to handle the exceptions
> which are created before Exchange is created? ( mostly i see
> CamelRuntimeException)
>
> Regards,
> Mayur
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handling-Exceptions-not-handled-by-the-DeadLetterChannelBuilder-tp5790316.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

Re: Handling Exceptions not handled by the DeadLetterChannelBuilder

Posted by Claus Ibsen <cl...@gmail.com>.
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 <ma...@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

Re: Handling Exceptions not handled by the DeadLetterChannelBuilder

Posted by mayur_bm <ma...@gmail.com>.
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.