How to get route Exception in a processor with camel+rabbitmq

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get route Exception in a processor with camel+rabbitmq

Alessandro Hoss
Hello guys,

I've a route with onException, which sends the message to rabbitMQ, and
another route listening rabbit to call a processor and get the exception
thrown. I'm able to reach this processor, but i'm not able to get the
exception thrown.

I've tried with the <handled> property set to false, and with
transferException=true query param on the endpoint uri's, but without luck.

On the "processorToGetExceptionData" i have tried both
"exchange.getException()" and
"exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class)", again
without luck.

Above are the (simplified) routes definitions:

<route id="route1">
    <from uri="rabbitmq:myExchange?queue=start&amp;routingKey=start"/>
    <onException>
            <exception>java.lang.Exception</exception>
            <redeliveryPolicy maximumRedeliveries="2"
redeliveryDelay="5000" retryAttemptedLogLevel="WARN"/>
            <handled>
                <constant>true</constant>
            </handled>
            <setHeader headerName="rabbitmq.ROUTING_KEY">
                <constant>errorMessage</constant>
            </setHeader>
            <to uri="rabbitmq:myExchange?skipQueueDeclare=true"/>
    </onException>
    <process ref="processorThatThrowsSomeException"/>
     <to uri="anyEndpoint" />
</route>

<route id="route2">
    <from
uri="rabbitmq:myExchange?queue=errorMessage&amp;routingKey=errorMessage"/>
    <process ref="processorToGetExceptionData"/>
    <to uri="anotherEndpoint"/>
</route>

Any ideas on what could be wrong ?

Thanks in advance,
Alessandro Hoss
Reply | Threaded
Open this post in threaded view
|

Re: How to get route Exception in a processor with camel+rabbitmq

wyuan4
why your from queue name is same as to queue name?

On Wed, Nov 13, 2019 at 9:10 AM Alessandro Hoss <[hidden email]> wrote:

> Hello guys,
>
> I've a route with onException, which sends the message to rabbitMQ, and
> another route listening rabbit to call a processor and get the exception
> thrown. I'm able to reach this processor, but i'm not able to get the
> exception thrown.
>
> I've tried with the <handled> property set to false, and with
> transferException=true query param on the endpoint uri's, but without luck.
>
> On the "processorToGetExceptionData" i have tried both
> "exchange.getException()" and
> "exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class)", again
> without luck.
>
> Above are the (simplified) routes definitions:
>
> <route id="route1">
>     <from uri="rabbitmq:myExchange?queue=start&amp;routingKey=start"/>
>     <onException>
>             <exception>java.lang.Exception</exception>
>             <redeliveryPolicy maximumRedeliveries="2"
> redeliveryDelay="5000" retryAttemptedLogLevel="WARN"/>
>             <handled>
>                 <constant>true</constant>
>             </handled>
>             <setHeader headerName="rabbitmq.ROUTING_KEY">
>                 <constant>errorMessage</constant>
>             </setHeader>
>             <to uri="rabbitmq:myExchange?skipQueueDeclare=true"/>
>     </onException>
>     <process ref="processorThatThrowsSomeException"/>
>      <to uri="anyEndpoint" />
> </route>
>
> <route id="route2">
>     <from
> uri="rabbitmq:myExchange?queue=errorMessage&amp;routingKey=errorMessage"/>
>     <process ref="processorToGetExceptionData"/>
>     <to uri="anotherEndpoint"/>
> </route>
>
> Any ideas on what could be wrong ?
>
> Thanks in advance,
> Alessandro Hoss
>


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Weiquan Yuan
Located in Ottawa, Canada
Reply | Threaded
Open this post in threaded view
|

Re: How to get route Exception in a processor with camel+rabbitmq

Alessandro Hoss
Hi ..

"myExchange" is not the queue name... When working with rabbitmq, you
always send the message to a "RabbitMQ Exchange", which redirects it to
some queue based on the routingKey (which is defined on the creation of the
queue)... quite complex, but RabbitMQ component has different concepts than
JMS and AMQP components.

In this case, the <from> in route1 is consuming from the "start" queue, and
the <to> inside <onException> is sending to "errorMessage" queue (by the
rabbitmq.ROUTING_KEY header), which is consumed by route2.

The flow is working fine, the only problem is that I can't get the
Exception "CAUGHT" nor "HANDLED" in route1, by the processor in route2.


Em qua., 13 de nov. de 2019 às 16:55, WEIQUAN YUAN <[hidden email]>
escreveu:

> why your from queue name is same as to queue name?
>
> On Wed, Nov 13, 2019 at 9:10 AM Alessandro Hoss <[hidden email]> wrote:
>
> > Hello guys,
> >
> > I've a route with onException, which sends the message to rabbitMQ, and
> > another route listening rabbit to call a processor and get the exception
> > thrown. I'm able to reach this processor, but i'm not able to get the
> > exception thrown.
> >
> > I've tried with the <handled> property set to false, and with
> > transferException=true query param on the endpoint uri's, but without
> luck.
> >
> > On the "processorToGetExceptionData" i have tried both
> > "exchange.getException()" and
> > "exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class)", again
> > without luck.
> >
> > Above are the (simplified) routes definitions:
> >
> > <route id="route1">
> >     <from uri="rabbitmq:myExchange?queue=start&amp;routingKey=start"/>
> >     <onException>
> >             <exception>java.lang.Exception</exception>
> >             <redeliveryPolicy maximumRedeliveries="2"
> > redeliveryDelay="5000" retryAttemptedLogLevel="WARN"/>
> >             <handled>
> >                 <constant>true</constant>
> >             </handled>
> >             <setHeader headerName="rabbitmq.ROUTING_KEY">
> >                 <constant>errorMessage</constant>
> >             </setHeader>
> >             <to uri="rabbitmq:myExchange?skipQueueDeclare=true"/>
> >     </onException>
> >     <process ref="processorThatThrowsSomeException"/>
> >      <to uri="anyEndpoint" />
> > </route>
> >
> > <route id="route2">
> >     <from
> >
> uri="rabbitmq:myExchange?queue=errorMessage&amp;routingKey=errorMessage"/>
> >     <process ref="processorToGetExceptionData"/>
> >     <to uri="anotherEndpoint"/>
> > </route>
> >
> > Any ideas on what could be wrong ?
> >
> > Thanks in advance,
> > Alessandro Hoss
> >
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Weiquan Yuan
> Located in Ottawa, Canada
>


--
Alessandro Hoss
Reply | Threaded
Open this post in threaded view
|

Re: How to get route Exception in a processor with camel+rabbitmq

Alessandro Hoss
In ActiveMQ component there is a "transferExchange" URI parameter, which
makes possible to get the exception after sending it to another queue
through activemq.

Is there a way of doing this (transfer the exchange over the messaging
layer) with RabbitMQ?

Em qua., 13 de nov. de 2019 às 17:45, Alessandro Hoss <[hidden email]>
escreveu:

> Hi ..
>
> "myExchange" is not the queue name... When working with rabbitmq, you
> always send the message to a "RabbitMQ Exchange", which redirects it to
> some queue based on the routingKey (which is defined on the creation of the
> queue)... quite complex, but RabbitMQ component has different concepts than
> JMS and AMQP components.
>
> In this case, the <from> in route1 is consuming from the "start" queue,
> and the <to> inside <onException> is sending to "errorMessage" queue (by
> the rabbitmq.ROUTING_KEY header), which is consumed by route2.
>
> The flow is working fine, the only problem is that I can't get the
> Exception "CAUGHT" nor "HANDLED" in route1, by the processor in route2.
>
>
> Em qua., 13 de nov. de 2019 às 16:55, WEIQUAN YUAN <[hidden email]>
> escreveu:
>
>> why your from queue name is same as to queue name?
>>
>> On Wed, Nov 13, 2019 at 9:10 AM Alessandro Hoss <[hidden email]>
>> wrote:
>>
>> > Hello guys,
>> >
>> > I've a route with onException, which sends the message to rabbitMQ, and
>> > another route listening rabbit to call a processor and get the exception
>> > thrown. I'm able to reach this processor, but i'm not able to get the
>> > exception thrown.
>> >
>> > I've tried with the <handled> property set to false, and with
>> > transferException=true query param on the endpoint uri's, but without
>> luck.
>> >
>> > On the "processorToGetExceptionData" i have tried both
>> > "exchange.getException()" and
>> > "exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class)",
>> again
>> > without luck.
>> >
>> > Above are the (simplified) routes definitions:
>> >
>> > <route id="route1">
>> >     <from uri="rabbitmq:myExchange?queue=start&amp;routingKey=start"/>
>> >     <onException>
>> >             <exception>java.lang.Exception</exception>
>> >             <redeliveryPolicy maximumRedeliveries="2"
>> > redeliveryDelay="5000" retryAttemptedLogLevel="WARN"/>
>> >             <handled>
>> >                 <constant>true</constant>
>> >             </handled>
>> >             <setHeader headerName="rabbitmq.ROUTING_KEY">
>> >                 <constant>errorMessage</constant>
>> >             </setHeader>
>> >             <to uri="rabbitmq:myExchange?skipQueueDeclare=true"/>
>> >     </onException>
>> >     <process ref="processorThatThrowsSomeException"/>
>> >      <to uri="anyEndpoint" />
>> > </route>
>> >
>> > <route id="route2">
>> >     <from
>> >
>> uri="rabbitmq:myExchange?queue=errorMessage&amp;routingKey=errorMessage"/>
>> >     <process ref="processorToGetExceptionData"/>
>> >     <to uri="anotherEndpoint"/>
>> > </route>
>> >
>> > Any ideas on what could be wrong ?
>> >
>> > Thanks in advance,
>> > Alessandro Hoss
>> >
>>
>>
>> --
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Weiquan Yuan
>> Located in Ottawa, Canada
>>
>
>
> --
> Alessandro Hoss
>


--
Alessandro Hoss