Home » Java » java – Session scoped JmsListener-Exceptionshub

java – Session scoped JmsListener-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to make JmsListener session scoped, but when I add @SessionScope to the class it does not receive any messages. I need a separate instance of the listener for every user that logs in to my application.

@Component
@SessionScope
public class JmsListener {   

    @org.springframework.jms.annotation.JmsListener(id="sbx",destination="$sys.monitor.Q.r.>",containerFactory="oneListenerContainerFactory")
    public void monitorSbx(Message message) throws JMSException {
        System.out.println("MY MESSAGE IS : "+message.getJMSTimestamp());
    }

    @org.springframework.jms.annotation.JmsListener(id="ayr",destination="$sys.monitor.Q.r.>",containerFactory="twoListenerContainerFactory")
    public void monitorAyr(Message message) throws JMSException {
        System.out.println("MY MESSAGE IS : "+message.getJMSTimestamp());
    }
}

It works fine without @SessionScope, but once @SessionScope is added messages are not printed.

How to&Answers: