spring-projects / spring-amqp

Spring AMQP - support for Spring programming model with AMQP, especially but not limited to RabbitMQ
https://spring.io/projects/spring-amqp
Apache License 2.0
807 stars 619 forks source link

Add ErrorHandler to ConnectionFactory and outbound Gateways/ChannelAdapters like Spring-JMS has [AMQP-211] #1769

Closed spring-operator closed 10 years ago

spring-operator commented 12 years ago

Edwin Stang opened AMQP-211 and commented

In Spring-JMS it is possible to set a ExceptionListener for all connections:

   <bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
     <constructor-arg ref="amqConnectionFactory" />
     <property name="exceptionListener" ref="jmsExceptionListener" />
     <property name="sessionCacheSize" value="1" />
</bean>

In Spring-AMQP it is only possible to set ErrorHandlers for specific inbound components:

<si-amqp:inbound-gateway queue-names="helloWorldMitAntwortAmqpQueue"
        connection-factory="amqpConnectionFactory" request-channel="helloWorldMitAntwortIn" error-handler="amqpErrorHandler" />
<rabbit:queue name="helloWorldMitAntwortAmqpQueue" />

It would be nice to be able to set an ErrorHandler globally on the ConnectionFactory like this:

   <bean id="amqpConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
     <property name="channelCacheSize" value="10" />
     <property name="host" value="${de.invesdwin.gemeinsam.integration.amqp.AmqpClientProperties.HOST}" />
     <property name="port" value="${de.invesdwin.gemeinsam.integration.amqp.AmqpClientProperties.PORT}" />
     <property name="username" value="${de.invesdwin.gemeinsam.integration.amqp.AmqpClientProperties.USER}" />
     <property name="password" value="${de.invesdwin.gemeinsam.integration.amqp.AmqpClientProperties.PASSWORD}" />
           <property name="errorHandler" ref="amqpErrorHandler" />
</bean>

Also, currently I see no way to add an ErrorHandler on outbound Gateways or ChannelAdapters. This is a problem for me, because I cannot get Exceptions to be logged properly if they occur in an OutboundGateway. I need to be able to get Exceptions that occur in temporary response channels that wait for synchronous responses. In JMS I sometimes get timeout exceptions about the response not arriving within 5 seconds, but in AMQP nothing gets logged, thus I don't know what happens.


Affects: 1.0.0 GA

spring-operator commented 12 years ago

Mark Fisher commented

A couple comments:

  1. The JMS API actually defines javax.jms.ExceptionListener, and the javax.jms.Connection provides a setExceptionListener method. That's why that functionality exists in Spring's CachingConnectionFactory. There is no direct correlation in the AMQP/Rabbit APIs. Perhaps the closest thing is our own ConnectionListener callback interface which you can set on the Spring AMQP CachingConnectionFactory.

  2. In Spring Integration we do not support error-handlers or error-channels on outbound adapters. The general idea is that error handling is configurable at the "entry point" (similar to the use of exception mappings in web.xml for a webapp) where all downstream Exceptions will propagate... like a big catch block for the whole message flow. You can add an error-channel on a 'gateway' proxy that exists mid-stream. Otherwise, we recommend handling errors at your inbound adapters. Hopefully that makes sense.

spring-operator commented 10 years ago

Gary Russell commented

As Mark said, there is no equivalent of the JmsExceptionListener in Rabbit.

However, you can register a ConnectionListener which is informed of opens and closes. However, with the current release, close is only called on an explicit destroy of the connection factory. #1878 added support for calling the close method whenever a closed connection is detected.