在 ActiveMQ Artemis 上的主题上加载平衡消费者
Loading balancing consumers on topics on ActiveMQ Artemis
我正在使用 ActiveMQ Artemis 2.10 和 JMS Client 1.1 客户端。
如果我在我的地址上使用多播路由类型并且需要持久订阅,我如何在消费者端实现负载平衡?
对于 ActiveMQ 5,它将是 virtual destinations。
目前尚不清楚在消费持久订阅主题时如何使用 ActiveMQ Artemis 7.2 和 JMS Client 1.1 客户端实现消费者端负载平衡。
在上面的例子中:
每个消费者都会在示例中设置 clientId(client123
和 client456
),但这意味着 client123
只能有一个实例从 client123.topic.foo
。
我目前的理解是 ActiveMQ Artemis 2.10 和 JMS Client 1.1 客户端意味着您不能对主题进行负载平衡,对吗?
唯一的选择似乎是 ActiveMQ Artemis 2.10 和 JMS Client 2.0,它们允许您创建共享持久订阅,对吗?
有第三种选择吗?
My current understanding is that Active MQ Artemis 7.2 and JMS Client 1.1 client implies you cannot have load balancing on topics, would that be correct?
没有
The only option seems to be Active MQ Artemis 7.2 and JMS Client 2.0 which allows you to create Shared Durable subscriptions, would that be correct?
没有
Is there a 3rd option?
是的。您可以使用持久订阅的 fully qualified queue name with a JMS consumer. As noted in the JMS-to-core mapping document,将 JMS 主题映射到核心地址,并且对该 JMS 主题的订阅映射到核心地址上的核心队列。在持久 JMS 订阅的情况下,该队列的名称遵循模式“.”。下面是一些示例代码来演示:
ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection1 = cf.createConnection();
connection1.setClientID("myClientID");
Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = new ActiveMQTopic("myTopic");
MessageConsumer consumer1 = session1.createDurableSubscriber(topic, "mySubscriptionName");
Connection connection2 = cf.createConnection();
Session session2 = connection2.createSession();
Destination destination = new ActiveMQQueue("myTopic::myClientID.mySubscriptionName");
MessageConsumer consumer2 = session2.createConsumer(destination);
// Send 2 messages
MessageProducer producer = session1.createProducer(topic);
producer.send(session1.createMessage());
producer.send(session1.createMessage());
producer.close();
// Receive the first message with the first consumer
connection1.start();
Message message1 = consumer1.receive();
consumer1.close();
// Receive the second message with the second consumer
connection2.start();
Message message2 = consumer2.receive();
consumer2.close();
换句话说...
由于 JMS 1.1 未明确允许共享持久订阅,因此您无法使用 createDurableSubscriber
对具有相同客户端标识符和订阅名称的同一主题横向扩展应用程序。但是,如果一个应用程序使用 createDurableSubscriber
并且所有其他应用程序使用其 "fully qualified queue name" 直接从底层订阅队列消费,您可以水平扩展(这是从第一次使用时使用的客户端标识符和订阅名称派生的使用 createDurableSubscriber
).
创建
我正在使用 ActiveMQ Artemis 2.10 和 JMS Client 1.1 客户端。
如果我在我的地址上使用多播路由类型并且需要持久订阅,我如何在消费者端实现负载平衡?
对于 ActiveMQ 5,它将是 virtual destinations。
目前尚不清楚在消费持久订阅主题时如何使用 ActiveMQ Artemis 7.2 和 JMS Client 1.1 客户端实现消费者端负载平衡。
在上面的例子中:
每个消费者都会在示例中设置 clientId(client123
和 client456
),但这意味着 client123
只能有一个实例从 client123.topic.foo
。
我目前的理解是 ActiveMQ Artemis 2.10 和 JMS Client 1.1 客户端意味着您不能对主题进行负载平衡,对吗?
唯一的选择似乎是 ActiveMQ Artemis 2.10 和 JMS Client 2.0,它们允许您创建共享持久订阅,对吗?
有第三种选择吗?
My current understanding is that Active MQ Artemis 7.2 and JMS Client 1.1 client implies you cannot have load balancing on topics, would that be correct?
没有
The only option seems to be Active MQ Artemis 7.2 and JMS Client 2.0 which allows you to create Shared Durable subscriptions, would that be correct?
没有
Is there a 3rd option?
是的。您可以使用持久订阅的 fully qualified queue name with a JMS consumer. As noted in the JMS-to-core mapping document,将 JMS 主题映射到核心地址,并且对该 JMS 主题的订阅映射到核心地址上的核心队列。在持久 JMS 订阅的情况下,该队列的名称遵循模式“
ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection1 = cf.createConnection();
connection1.setClientID("myClientID");
Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = new ActiveMQTopic("myTopic");
MessageConsumer consumer1 = session1.createDurableSubscriber(topic, "mySubscriptionName");
Connection connection2 = cf.createConnection();
Session session2 = connection2.createSession();
Destination destination = new ActiveMQQueue("myTopic::myClientID.mySubscriptionName");
MessageConsumer consumer2 = session2.createConsumer(destination);
// Send 2 messages
MessageProducer producer = session1.createProducer(topic);
producer.send(session1.createMessage());
producer.send(session1.createMessage());
producer.close();
// Receive the first message with the first consumer
connection1.start();
Message message1 = consumer1.receive();
consumer1.close();
// Receive the second message with the second consumer
connection2.start();
Message message2 = consumer2.receive();
consumer2.close();
换句话说...
由于 JMS 1.1 未明确允许共享持久订阅,因此您无法使用 createDurableSubscriber
对具有相同客户端标识符和订阅名称的同一主题横向扩展应用程序。但是,如果一个应用程序使用 createDurableSubscriber
并且所有其他应用程序使用其 "fully qualified queue name" 直接从底层订阅队列消费,您可以水平扩展(这是从第一次使用时使用的客户端标识符和订阅名称派生的使用 createDurableSubscriber
).