Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

java - Spring Boot JMS Error Handler not working

I Tried Implementing azure service bus Integration by using Spring boot and JMS

But error handler 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 inside error handler not calling while exception thrown. I just tried 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

Any one please advise on this ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...