虚拟目标活动和客户端 id 通配符

Virtual Destinations Active and client id wildcard

我一直在阅读虚拟目的地的文档:http://activemq.apache.org/virtual-destinations.html

但是我遇到了一点问题,当我发送到一个主题时,它似乎没有按照文档中描述的那样遵循客户端 ID 名称

我在活动 mq 上的设置是:

    <destinationInterceptors>
      <virtualDestinationInterceptor>
        <virtualDestinations>
          <virtualTopic name="Destination.>" prefix="Target.*." selectorAware="false" />
        </virtualDestinations>
      </virtualDestinationInterceptor>
    </destinationInterceptors>

上面的代码描述了当我发送到 Destination.Status 主题时 ClientId客户 A.

如果理解正确,它应该只发送给 Target.CustomerA.Destination.Status,但实际情况是它正在发送给 Target.CustomerA.Destination.StatusTarget.CustomerB.Destination.Status 所以基本上将消息分散到队列中并忽略客户端 ID。

我没有看到任何关于如何配置它的进一步文档,我想知道是否还有其他人遇到过这个问题?

我是不是漏掉了什么? 下面是我的制作人,如果有帮助的话。

    public static class HelloWorldProducer implements Runnable {
        public void run() {
            try {
                // Create a ConnectionFactory
                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61617");

                // Create a Connection
                Connection connection = connectionFactory.createConnection();
                connection.setClientID("CustomerA");
                connection.start();

                // Create a Session
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                // Create the destination (Topic or Queue)
                Destination destination = session.createTopic("Destination.Status");
                // Create a MessageProducer from the Session to the Topic or Queue
                MessageProducer producer = session.createProducer(destination);
                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

                // Create a messages
                String text = "Hello world! From: " + Thread.currentThread().getName() + " : " + this.hashCode();
                TextMessage message = session.createTextMessage(text);

                // Tell the producer to send the message
                System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
                producer.send(message);

                // Clean up
                session.close();
                connection.close();
            }
            catch (Exception e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
            }
        }
    }

任何输入都是有益的。

无论您是否设置了 ClientID,这种情况下的发送方对代理的路由没有实际影响,因为它只是发送到一个命名的主题,在本例中为“Destination.Status”。代理上的配置控制路由,在您的情况下,您已经配置了“Destination.>”,因此出现的任何队列消费者都会订阅与您设置的配置相匹配的队列。因此,在您的情况下,我猜您有一个消费者订阅 Queue (Target.CustomerA.Destination.Status) 和一个订阅 Queue (Target.CustomerB.Destination.Status),然后导致任何消息发送到主题向双方展开。

如果您想要相互竞争的消费者,那么您需要同时订阅 Target.CustomerA。Destination.Status 然后代理会循环将已发送的消息发送给任一活跃订阅者。