[英]ActiveMQ Artemis 2.10.1 + JMS 2.0 - shared subscription not working
軟件:
我創建了一個有 2 個消費者的主題。 每個消費者都有 1 個 MDB。 我有一個主要的方法來進行配置和所有操作。
即使我只發送一條消息並指定這是一個共享訂閱,該消息也被兩個 MDB 使用。 不知道如何解決這個問題。 當然沒有錯誤。 但這不是我的代碼預期的功能。
@MessageDriven(name = "TOPICMDB1", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "BTOPIC"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "mytopic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "durable"),
@ActivationConfigProperty(propertyName = "shareSubscriptions", propertyValue="true"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "MyClientId_1")
})
@MessageDriven(name = "TOPICMDB2", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "CTOPIC"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "mytopic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "durable"),
@ActivationConfigProperty(propertyName = "shareSubscriptions", propertyValue="true"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "MyClientId_2")
})
connectionFactory = new ActiveMQConnectionFactory(input.getUrl());
connection = (ActiveMQConnection) connectionFactory.createConnection(input.getUsername(), input.getPassword());
session = connection.createTopicSession(input.isTransacted(), Session.AUTO_ACKNOWLEDGE);
connection.start();
session = connection.createTopicSession(true, Session.SESSION_TRANSACTED);
destination = session.createTopic("ATOPIC");
consumer = session.createSharedDurableConsumer( (Topic) destination, "mytopic");
rtn = consumer.receive();
session.commit();
我不確定為什么要在mytopic
(訂閱名稱)上創建這個共享的持久消費者。 我正在嘗試所有不同的方法來完成我的任務。
tomee.xml
:
<Resource id="ATOPIC"
class-name="org.apache.activemq.artemis.api.jms.ActiveMQJMSClient"
constructor="name"
factory-name="createTopic"
type="javax.jms.Topic">
name=ATOPIC
</Resource>
broker.xml
:
<address name = "ATOPIC">
<multicast>
<queue name = "BTOPIC"/>
<queue name = "CTOPIC"/>
</multicast>
</address>
您的配置在多個地方不正確。
首先,JMS 主題由支持multicast
的address
實現,僅此而已。 這在ActiveMQ Artemis 文檔中有說明。 因此,您的broker.xml
應該具有以下內容:
<address name = "ATOPIC">
<multicast/>
</address>
其次,您的 MDB 應該使用相同的訂閱名稱而不是clientId
訂閱ATOPIC
,例如:
@MessageDriven(name = "TOPICMDB1", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "ATOPIC"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "mytopicSubscription"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "shareSubscriptions", propertyValue="true")
})
@MessageDriven(name = "TOPICMDB2", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "ATOPIC"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "mytopicSubscription"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "shareSubscriptions", propertyValue="true")
})
第三,您不應該在ATOPIC
上手動創建共享的持久消費者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.