spring 如何在单个方法上用于多个 @JmsListener

How spring works for multiple @JmsListener on a single method

我想说明一下,如果我将多个@jmsListener 放在一个方法上,那么它是如何工作的? 它是否会像多个单独的 JMS 侦听器一样并行工作? 或者它将像一个 JMS 侦听器一样按顺序工作?

喜欢:

    @JmsListener(destination = "queue.name1", containerFactory = "jmsListenerContainerFactory")
    @JmsListener(destination = "queue.name2", containerFactory = "jmsListenerContainerFactory")
    @JmsListener(destination = "queue.name3", containerFactory = "jmsListenerContainerFactory")
    @JmsListener(destination = "queue.name4", containerFactory = "jmsListenerContainerFactory")
    public void receiveQueue(Message message, Session session) throws JMSException {
        //TODO for message queue consuming logic
    }

我的问题是 spring 会生成 4 个单独的 JMS 侦听器并并行工作,还是 spring 只生成 1 个 JMS 侦听器并按顺序为 4 个不同的消息队列工作?

每个JmsListener注解都会构建一个JMS监听器容器,所以会有4个JMS监听器并行工作。来自 JmsListener 注释的 JavaDoc:

Annotation that marks a method to be the target of a JMS message listener on the specified destination(). The containerFactory() identifies the JmsListenerContainerFactory to use to build the JMS listener container.