You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "richie.riviere@gmail.com" <ri...@gmail.com> on 2013/12/05 12:33:35 UTC

error handling design pattern advice

Hi All,

I've got a question about error handling. Here is my scenario...

I have a route which calls a bean..

from(...JPA...)
.errorHandler(deadLetterChannel("log:dead")
.maximumRedeliveries(5)
.retryAttemptedLogLevel(LoggingLevel.ERROR))
.to("bean:serviceBean?method=login")
.to("bean:serviceBean?method=createSimpleProduct")


Where my service bean looks like this...

	public void login(Exchange exchange) {
		SharedModel model = new SharedModel();
		exchange.getOut().setHeaders(exchange.getIn().getHeaders());
		exchange.getOut().setBody(model);
	}

	public void createSimpleProduct(Exchange exchange) {
		ImportPayloadEntity importPayloadEntity =
(ImportPayloadEntity)exchange.getIn().getHeader(CamelConstants.HEADER_KEY_IMPORT_PAYLOAD);
		Collection<ItemEntity> itemEntities = importPayloadEntity.getItems();
                for (ItemEntity item : itemEntities) {        	
    		     
                      SharedModel model = ((SharedModel)
(exchange.getIn().getBody()));
                      ....
                      call soap call for each item in loop and use
attributes from SharedModel in calls
                }
}


So what happens currently is that when there is an error in create simple
product, because the model is being used as the message, the route will fail
(after unsuccessful retries) when it comes across the first bad item.

I have been wondering how could I change this so that it sidelines only the
bad item and keep going through the rest?

I had some tries at changing my route to use a Splitter to split my route
into individual item messages (which might work nicely) but then I realized
that I would lose my sharedModel as the message body which i need that to
make the service calls. 

What is the best design pattern for this situation?

much appreciated
 



--
View this message in context: http://camel.465427.n5.nabble.com/error-handling-design-pattern-advice-tp5744364.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error handling design pattern advice

Posted by "richie.riviere@gmail.com" <ri...@gmail.com>.
Thanks all for your replies. I have taken Kraythe's advice. Rather than just
putting a try catch in createSimpleProduct, in my route I did some splitting
so that the createSimpleProduct gets called for each item.

I guess I could have just put a try catch in but this way seems to be more
of a camel way.





--
View this message in context: http://camel.465427.n5.nabble.com/error-handling-design-pattern-advice-tp5744364p5744591.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error handling design pattern advice

Posted by "kraythe ." <kr...@gmail.com>.
Put a splitter in the route to split up the list and forward the split
exchanges to route b. In route b handle the items and if one fails you put
it in the DLQ, and ignore it. Another route can aggregate to do reporting
if it wants.

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*


On Tue, Dec 10, 2013 at 9:39 AM, Stephan Burkard <sb...@gmail.com> wrote:

> Well, if I don't misunderstand the situation, you could just use try/catch
> inside "createSimpleProduct" method to skip the bad items.
>
> Regards
> Stephan
>
>
> On Thu, Dec 5, 2013 at 12:33 PM, richie.riviere@gmail.com <
> richie.riviere@gmail.com> wrote:
>
> > Hi All,
> >
> > I've got a question about error handling. Here is my scenario...
> >
> > I have a route which calls a bean..
> >
> > from(...JPA...)
> > .errorHandler(deadLetterChannel("log:dead")
> > .maximumRedeliveries(5)
> > .retryAttemptedLogLevel(LoggingLevel.ERROR))
> > .to("bean:serviceBean?method=login")
> > .to("bean:serviceBean?method=createSimpleProduct")
> >
> >
> > Where my service bean looks like this...
> >
> >         public void login(Exchange exchange) {
> >                 SharedModel model = new SharedModel();
> >
> > exchange.getOut().setHeaders(exchange.getIn().getHeaders());
> >                 exchange.getOut().setBody(model);
> >         }
> >
> >         public void createSimpleProduct(Exchange exchange) {
> >                 ImportPayloadEntity importPayloadEntity =
> >
> >
> (ImportPayloadEntity)exchange.getIn().getHeader(CamelConstants.HEADER_KEY_IMPORT_PAYLOAD);
> >                 Collection<ItemEntity> itemEntities =
> > importPayloadEntity.getItems();
> >                 for (ItemEntity item : itemEntities) {
> >
> >                       SharedModel model = ((SharedModel)
> > (exchange.getIn().getBody()));
> >                       ....
> >                       call soap call for each item in loop and use
> > attributes from SharedModel in calls
> >                 }
> > }
> >
> >
> > So what happens currently is that when there is an error in create simple
> > product, because the model is being used as the message, the route will
> > fail
> > (after unsuccessful retries) when it comes across the first bad item.
> >
> > I have been wondering how could I change this so that it sidelines only
> the
> > bad item and keep going through the rest?
> >
> > I had some tries at changing my route to use a Splitter to split my route
> > into individual item messages (which might work nicely) but then I
> realized
> > that I would lose my sharedModel as the message body which i need that to
> > make the service calls.
> >
> > What is the best design pattern for this situation?
> >
> > much appreciated
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/error-handling-design-pattern-advice-tp5744364.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>

Re: error handling design pattern advice

Posted by Stephan Burkard <sb...@gmail.com>.
Well, if I don't misunderstand the situation, you could just use try/catch
inside "createSimpleProduct" method to skip the bad items.

Regards
Stephan


On Thu, Dec 5, 2013 at 12:33 PM, richie.riviere@gmail.com <
richie.riviere@gmail.com> wrote:

> Hi All,
>
> I've got a question about error handling. Here is my scenario...
>
> I have a route which calls a bean..
>
> from(...JPA...)
> .errorHandler(deadLetterChannel("log:dead")
> .maximumRedeliveries(5)
> .retryAttemptedLogLevel(LoggingLevel.ERROR))
> .to("bean:serviceBean?method=login")
> .to("bean:serviceBean?method=createSimpleProduct")
>
>
> Where my service bean looks like this...
>
>         public void login(Exchange exchange) {
>                 SharedModel model = new SharedModel();
>
> exchange.getOut().setHeaders(exchange.getIn().getHeaders());
>                 exchange.getOut().setBody(model);
>         }
>
>         public void createSimpleProduct(Exchange exchange) {
>                 ImportPayloadEntity importPayloadEntity =
>
> (ImportPayloadEntity)exchange.getIn().getHeader(CamelConstants.HEADER_KEY_IMPORT_PAYLOAD);
>                 Collection<ItemEntity> itemEntities =
> importPayloadEntity.getItems();
>                 for (ItemEntity item : itemEntities) {
>
>                       SharedModel model = ((SharedModel)
> (exchange.getIn().getBody()));
>                       ....
>                       call soap call for each item in loop and use
> attributes from SharedModel in calls
>                 }
> }
>
>
> So what happens currently is that when there is an error in create simple
> product, because the model is being used as the message, the route will
> fail
> (after unsuccessful retries) when it comes across the first bad item.
>
> I have been wondering how could I change this so that it sidelines only the
> bad item and keep going through the rest?
>
> I had some tries at changing my route to use a Splitter to split my route
> into individual item messages (which might work nicely) but then I realized
> that I would lose my sharedModel as the message body which i need that to
> make the service calls.
>
> What is the best design pattern for this situation?
>
> much appreciated
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/error-handling-design-pattern-advice-tp5744364.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>