Viktor Baert
Viktor Baert

Reputation: 788

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. 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().

I'm currently using a close to default jms configuration for spring boot that enables the use of the @JmsListener annotation. However I cannot find a way that to get grab the handle of the active jms session this annotation uses?

Upvotes: 4

Views: 6461

Answers (1)

Gary Russell
Gary Russell

Reputation: 174729

Just add a Session parameter to the listener...

@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

Upvotes: 11

Related Questions