从JMS代码ActiveMQ发布到多个队列的相同消息

时间:2015-06-02 18:42:11

标签: java jms activemq

您好我正在尝试根据某些数据条件将相同的消息发布到多个队列。

@Override
public void onMessage(Message msg) {
    // TODO Auto-generated method stub

    if (msginstanceof TextMessage) {

       if(<data check1>){
        Destination destination = session.createQueue("inbound.1");
        MessageProducer producer = session.createProducer(destination);
        log.info("Preparing to send to queue1");
        producer.send(msg);
        log.info("Message sent to queue1");

      }
      if(<data check 2>){
         Destination destination = session.createQueue("Queue2");
         MessageProducer producer = session.createProducer(destination);
         log.info("Preparing to send to Queue2");
         producer.send(msg);
         log.info("Message sent to Queue2");
      } 

但我不知道当我将消息发送到第一个队列时,是否会留下一条消息发送到第二个队列?消息在onMessage方法中捕获,该方法是javax.jms.MessageListener类的一部分。

我也在测试它,但想知道是否有一些我错过的明显事物。

TIA!

1 个答案:

答案 0 :(得分:2)

是的,它运作得很好。 这两条消息将获得不同的消息ID,否则应该非常相似。