简体   繁体   English

ActiveMQ Artemis 2.10.1 + JMS 2.0 - 共享订阅不起作用

[英]ActiveMQ Artemis 2.10.1 + JMS 2.0 - shared subscription not working

Software:软件:

  • Apache Artemis 2.10.1阿帕奇阿尔忒弥斯 2.10.1
  • TomEE plus 8.0 TomEE plus 8.0

I have created a topic with 2 consumers.我创建了一个有 2 个消费者的主题。 Each consumer has 1 MDB each.每个消费者都有 1 个 MDB。 I have one main method where I do the configuration and all.我有一个主要的方法来进行配置和所有操作。

Even though I am sending only one message and specified that this is a shared subscription the message is consumed by both the MDBs.即使我只发送一条消息并指定这是一个共享订阅,该消息也被两个 MDB 使用。 Not sure how to resolve this.不知道如何解决这个问题。 Of course there is no error.当然没有错误。 But this is not the expected functionality from my code.但这不是我的代码预期的功能。

@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(); 

I am not sure why I am creating this shared durable consumer on mytopic (subscription name).我不确定为什么要在mytopic (订阅名称)上创建这个共享的持久消费者。 I was trying all different ways to get my task accomplished.我正在尝试所有不同的方法来完成我的任务。

tomee.xml : 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 : broker.xml

<address name = "ATOPIC">
   <multicast>
      <queue name = "BTOPIC"/>
      <queue name = "CTOPIC"/>
   </multicast>
</address>

Your configuration is incorrect in multiple places.您的配置在多个地方不正确。

First, a JMS topic is implemented by an address which supports multicast , nothing more.首先,JMS 主题由支持multicastaddress实现,仅此而已。 This is noted in the ActiveMQ Artemis documentation .这在ActiveMQ Artemis 文档中有说明 Therefore, your broker.xml should have this:因此,您的broker.xml应该具有以下内容:

<address name = "ATOPIC">
   <multicast/>
</address>

Second, your MDBs should be subscribing to ATOPIC using the same subscription name and no clientId , eg:其次,您的 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")
})      

Third, you shouldn't be manually creating a shared durable consumer on ATOPIC .第三,您不应该在ATOPIC上手动创建共享的持久消费者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM