activemq-artemis - ActiveMQ Artemis 2.10.1 + JMS 2.0 - 共享订阅不起作用
问题描述
软件:
- 阿帕奇阿耳忒弥斯 2.10.1
- 汤姆EE加8.0
我创建了一个有 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 主题是由一个address
支持的实现的multicast
,仅此而已。这在ActiveMQ Artemis 文档中有说明。因此,你broker.xml
应该有这个:
<address name = "ATOPIC">
<multicast/>
</address>
其次,您的 MDB 应该ATOPIC
使用相同的订阅名称和 no 订阅clientId
,例如:
@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
.
推荐阅读
- python - 类列表视为全局
- npm-install - NPM 没有在 bitbucket 管道上安装 devDependencies?
- spring - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为“MyTastTasklet”的bean时出错
- openlayers - openlayers 5.1.3:快速启动示例中的“损坏”缩小按钮?
- javascript - 无法创建我自己的类似于暗黑破坏神 3 旅程跟踪器的网络应用程序
- ios - 将阴影和角添加到 UIView 除了底部
- c# - 应用程序的 n 层架构中可以有哪些额外的层?
- c# - 在字典中包含许多变量
- c - 从主函数中引用的函数分配后无法读取内存
- wpf - 页面资源中的 DataContext 绑定