Spring JMS: set ErrorHandler for annotated @JmsListener method

I use an annotated method @JmsListenerto listen for JMS messages as shown below.

@JmsListener(destination="exampleQueue")  
public void fetch(@Payload String message){  
    process(message);  
}

When this execution of the method throws an exception, I got a warning log

Execution of JMS message listener failed, and no ErrorHandler has been set.

How to install ErrorHandlerto handle this case. I am using spring boot 1.3.3.RELEASE

+4
source share
2 answers

When using annotations such as @EnableJms, @JmsListeneretc. to work with Spring JMS, ErrorHandler can be set as follows

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory, ExampleErrorHandler errorHandler) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setErrorHandler(errorHandler);
    return factory;
}

@Service
public class ExampleErrorHandler implements ErrorHandler{   
    @Override
    public void handleError(Throwable t) {
        //handle exception here
    }
}

:

+3

, CachingConfigurer CachingConfigurerSupport, - :

@Configuration
@EnableCaching
public class CachingConfiguration extends CachingConfigurationSupport {

  @Override 
  public CacheErrorHandler errorHandler() {
    // return your cache error handler
  }

} 

. CacheErrorHandler javadoc

, , ( ). , .

0

Source: https://habr.com/ru/post/1661050/


All Articles