JMS 2 MDB 监听多个队列

JMS 2 MDB listen to multiple queue

我在 Liberty 18.0.0.2 上使用 JavaEE 8。
我像这样设置 jms 激活配置 (server.xml):

  <messagingEngine>
    <queue id="application" />
  </messagingEngine>
  <jmsActivationSpec id="app/appMDB">
    <properties.wasJms destinationRef="java:app/onlineQueue" />
  </jmsActivationSpec>   

这是我的简单 MDB 消息侦听器:

@MessageDriven(
        name = "appMDB",
        mappedName = "java:app/onlineQueue",
        activationConfig = {
                @ActivationConfigProperty(propertyName = "destinationType",
                        propertyValue = "javax.jms.Queue"),
                @ActivationConfigProperty(propertyName = "destination",
                        propertyValue = "java:app/onlineQueue")
        }
)
public class ApplicationMessageListener implements MessageListener {
...
}

我还定义了两个这样的队列:

@Stateless
@JMSDestinationDefinitions(
        value = {
                @JMSDestinationDefinition(
                        name = "java:app/onlineQueue",
                        interfaceName = "javax.jms.Queue",
                        destinationName = "application"),
                @JMSDestinationDefinition(
                        name = "java:app/offlineQueue",
                        interfaceName = "javax.jms.Queue",
                        destinationName = "application")
        }
)
public class MessageService {

    @Inject
    private Logger logger;

    @Resource(lookup = "java:app/onlineQueue")
    private Queue onlineQueue;

    @Resource(lookup = "java:app/offlineQueue")
    private Queue offlineQueue;

    @Inject
    private JMSContext context;

    @EJB
    private MessageUtils messageUtils;

    public void sendToOnlineQueue(SimpleMessage simpleMessage) {
        TextMessage message = messageUtils.createTextMessage(simpleMessage);
        logger.info("Send online Message : " + simpleMessage);
        JMSProducer producer = context.createProducer();
        producer.send(onlineQueue, message);
    }

    public void sendToOfflineQueue(SimpleMessage simpleMessage) {
        TextMessage message = messageUtils.createTextMessage(simpleMessage);
        logger.info("Send offline Message : " + simpleMessage);
        JMSProducer producer = context.createProducer();
        producer.send(offlineQueue, message);
    }
}   

我的问题是 MDB 监听多个队列。
我想让 mdb 只听 onlineQueue .
如何解决这个问题?

你有两个不同的@JMSDestinationDefinition。一个有java:app/onlineQueuename,一个有java:app/offlineQueue的名字。但是,他们两个都有 destinationName 的应用程序,这对我来说似乎是错误的。无论您在 JNDI 中查找 java:app/onlineQueue 还是 java:app/offlineQueue,您都将获得对名为 application 的目标的引用。这几乎就是为什么发送到 java:app/offlineQueue 的消息会被 MDB 接收的原因。