简体   繁体   English

如何在@JmsListener使用的Spring Boot中访问活动的JMS连接/会话

[英]How to acces to the active JMS Connection/Session in Spring Boot that @JmsListener uses

I'm trying to recover messages that are sent back to the ActiveMQ queue due to the destination being unreachable. 我正在尝试恢复由于目标不可达而发送回ActiveMQ队列的消息。 I'm avoiding the re-delivery policy as it doesn't fit my requirements. 我回避了重新配送政策,因为它不符合我的要求。 I need to recover these messages at exact time in my application with session.recover(). 我需要使用session.recover()在应用程序中的准确时间恢复这些消息。

I'm currently using a close to default jms configuration for spring boot that enables the use of the @JmsListener annotation. 我目前正在使用接近默认的jms配置进行弹簧引导,从而可以使用@JmsListener批注。 However I cannot find a way that to get grab the handle of the active jms session this annotation uses? 但是,我找不到一种方法来获取此批注使用的活动jms会话的句柄?

Just add a Session parameter to the listener... 只需将Session参数添加到侦听器...

@SpringBootApplication
public class So55038881Application {

    public static void main(String[] args) {
        SpringApplication.run(So55038881Application.class, args);
    }

    @JmsListener(destination = "so55038881")
    public void listen(String in, Session session) {
        System.out.println(in + ":" + session);
    }

    @Bean
    public ApplicationRunner runner(JmsTemplate template) {
        return args -> template.convertAndSend("so55038881", "foo");
    }

}

and

foo:Cached JMS Session: ActiveMQSession {id=ID:host.local-52659-1551967879238-4:1:1,started=true} java.lang.Object@5bad3a2d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM