I have a simple producer / consumer setup doing an RPC style call over RabbitMQ using Spring Integration...
I would like to know what the best paten for handling exceptions thrown by the consumer is? In an ideal world I would have wanted the exception to be thrown directly out of the int:gateway on the producer so that it can be handled by the client.
This is my producer config:
Code:
<rabbit:connection-factory id="connectionFactory"/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue name="Q.aggregator.Proceed"/>
<rabbit:direct-exchange name="E.aggregator.direct.Proceed">
<rabbit:bindings>
<rabbit:binding queue="Q.aggregator.Proceed" key="aggregator.Proceed"/>
</rabbit:bindings>
</rabbit:direct-exchange>
<rabbit:direct-exchange name="E.thomas.direct.Proceed"/>
<int:channel id="aggregator.Proceed"/>
<int:gateway id="uwEngine" service-interface="some.Interface" default-request-channel="aggregator.Proceed" />
<int-amqp:outbound-gateway request-channel="aggregator.Proceed" amqp-template="amqpTemplate" exchange-name="E.aggregator.direct.Proceed" routing-key="aggregator.Proceed"/>
This is the consumer:
Code:
<int:channel id="aggregator.Proceed"/>
<int-amqp:inbound-gateway request-channel="aggregator.Proceed" queue-names="Q.aggregator.Proceed" connection-factory="connectionFactory" concurrent-consumers="1"/>
<bean id="beany" class="some.Interface"/>
<int:service-activator input-channel="aggregator.Proceed" ref="beany" method="proceed"/>
I currently get the following error:
Code:
INFO: Execution of Rabbit message listener failed, and no ErrorHandler has been set: class org.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception
Nov 20, 2012 2:16:00 PM org.springframework.integration.gateway.MessagingGatewaySupport doSendAndReceive
WARNING: failure occurred in gateway sendAndReceive
From reading other threads and documentation I can see a couple of options, but none would seem to get the exception back to the client...
- Define the error-channel property on the int-amqp:inbound-gateway on the consumer and then define an int-amqp:outbound-gateway to send the error back to the client. I am not sure how I would send this back to the temporary queue that was created and the client is blocking on.
- Define an ErrorHandler, not sure what I should be doing inside it, or where this is documented?
- Catch all exceptions at the consumer level and wrap these in my response payload.
- Timeout the response on the client, useless because I won't know why...
Thanks in advance!