On Fri, Jul 9, 2010 at 2:35 PM, Javier Arias <[email protected]> wrote:
> Hello Everybody,
>
> I found that if I change in my bean:
> from:
>         System.out.println(" received message. returning error.");
>         exchange.setStatus(ExchangeStatus.ERROR);
>        channel.send(exchange);
>
> to:
>         System.out.println(" received message. returning error.");
>         throw new MessagingException(" ALWAYS RETURN ERROR. throw messaging
> exception.");
>
> camel is catching the error correctly and making redeliveries and sending to
> deadletter endpoint.
>
> I searched on the documentation and google, but didn't find the response; my
> question is: what is the difference between returning an error exchange and
> throw an exception? which is the recommended way of handling errors in bean? 
> and
> what about patterns on error handling on servicemix?
>

You need to enable handleFault on the Camel side before the Camel
error handler can catch and handle JBI FAULTs
There are a bit of info in chapter 13 of the Camel book. And maybe a
little bit on the camel wiki pages.



> Thank you very much.
>
> Regards.
> Javier.
>
>
>
>
> ________________________________
> From: Javier Arias <[email protected]>
> To: [email protected]
> Sent: Thu, July 8, 2010 12:54:22 PM
> Subject: Camel dealetter + Bean strange behaviour
>
>
> Hello All,
>
> Our general error policy for some parts of our processes is to use a camel
> deadletter queue (on file).
>
>
> What I am trying to do is (sm 3.3.1)
>
> FILE POLLER => CAMEL DEADLETTER => BEAN
>
> In case of error CAMEL would send to a file sender.
>
> So, in an SA we have a bean that make some actions and return DONE or ERROR
> depending  on the result, what I would expect is that if the bean returns 
> ERROR
> camel retries for a number of times and sends to the deadletter, but this is 
> not
> done. It is not retrying or sending to deadletter, and my msg disappears (msg
> comes from a file poller).
> From other part of the process we are sending an email, which works perfectly
> with camel deadletter, retrying and sending to deadletter when necessary.
>
> Probably I am doing wrong but I do not know what.
>
> Below is an example (also, I attached my sample SA):
>
> Thank you in advance.
> Javier
>
> ====================================================================
> BEAN :::
> ====================================================================
> package playground.bean;
>
> import javax.annotation.Resource;
> import javax.jbi.messaging.DeliveryChannel;
> import javax.jbi.messaging.ExchangeStatus;
> import javax.jbi.messaging.MessageExchange;
> import javax.jbi.messaging.MessagingException;
>
> import  org.apache.servicemix.jbi.listener.MessageExchangeListener;
>
> public class AlwaysErrorBean implements MessageExchangeListener {
>
>   �...@resource
>    private DeliveryChannel channel;
>
>   �...@override
>    public void onMessageExchange(MessageExchange exchange) throws
> MessagingException {
>        if (exchange.getStatus() != ExchangeStatus.ACTIVE) {
>            System.out.println("onMessageExchange : RECEIVED NON ACTIVE 
> EXCHANGE
> : " + exchange.getStatus().toString());
>            return;
>        }
>
>        System.out.println(" received message. returning error.");
>        exchange.setStatus(ExchangeStatus.ERROR);
>        channel.send(exchange);
>    }
> }
>
> ====================================================================
> CAMEL ROUTE :::
> ====================================================================
>
> package playground.camel;
>    import org.apache.camel.Exchange;
>    import org.apache.camel.Processor;
>    import org.apache.camel.builder.RouteBuilder;
>    import org.apache.camel.model.InterceptorType;
>    import org.apache.camel.processor.DelegateProcessor;
>
>    public class CamelRouteBuilder extends RouteBuilder {
>
>        private final static String JBI_ENDP = "jbi:endpoint:";
>         private final static String NAMESPACE = "http://playground";;
>
>            public void configure() throws Exception {
>
>                DelegateProcessor proc = new DelegateProcessor(){
>                     public void process(Exchange exchange) throws Exception {
>                        System.out.println(exchange.toString());
>                        processNext(exchange);
>                    }
>
>                    protected void processNext(Exchange exchange) throws
> Exception {
>                        if (processor != null) {
>                            processor.process(exchange);
>                        }
>                    }
>                };
> //                ALTERNATIVE 1 : SEND TO ALWAYSERROR BEAN
>                from(JBI_ENDP+NAMESPACE+"/camelDeadLetter/camelDeadLetterEp")
>
> .errorHandler(deadLetterChannel(JBI_ENDP+NAMESPACE+"/deadLetter/deadLetterEp"))
>
>
>
> .to(JBI_ENDP+NAMESPACE+"/alwaysErrorBean/alwaysErrorBeanEp").addInterceptor(proc);
>
> //                 ALTERNATIVE 2 : SEND TO MAIL COMPONENT
> //                
> from(JBI_ENDP+NAMESPACE+"/camelDeadLetter/camelDeadLetterEp")
> //
> .errorHandler(deadLetterChannel(JBI_ENDP+NAMESPACE+"/deadLetter/deadLetterEp"))
>
>
> //
> .to(JBI_ENDP+NAMESPACE+"/emailSender/emailSenderEp").addInterceptor(proc);
>
>            }
> }
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to