I tried implementing Azure Service Bus integration by using Spring Boot and JMS
But error handler is not working as expected, I'm getting a warning
WARN 10676 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer : Execution of JMS message listener failed, and no ErrorHandler has been set.
And sysout is not calling inside the error handler while the exception is thrown. I just tried the below example:
@SpringBootApplication
public class So49861714Application {
public static void main(String[] args) {
SpringApplication.run(So49861714Application.class, args);
}
@Bean
public ApplicationRunner runner(JmsTemplate template) {
return args -> template.convertAndSend("foo", "testMessage");
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
DefaultJmsListenerContainerFactoryConfigurer configurer,
ConnectionFactory connectionFactory,
ErrorHandler myErrorHandler) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
factory.setErrorHandler(myErrorHandler);
return factory;
}
@Bean
public ErrorHandler myErrorHandler() {
return t -> {
System.out.println("In error handler");
t.printStackTrace();
};
}
@JmsListener(destination = "foo")
public void listen(String in) {
System.out.println(in);
throw new RuntimeException("test");
}
}
Reference -
https://www.baeldung.com/spring-jms
Spring JMS : Set ErrorHandler for @JmsListener annotated method
https://lankydan.dev/2017/06/18/using-jms-in-spring-boot
Anyone, please advise on this?
You omitted the instruction for Spring to use your customised org.springframework.jms.config.JmsListenerContainerFactory bean . Set this on the @JmsListener annotation using the containerFactory property
For example, in your case;
@JmsListener(destination = "foo",containerFactory = "jmsListenerContainerFactory")
public void listen(String in) {
System.out.println(in);
throw new RuntimeException("test");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With