1

Software:

  • Apache Artemis 2.10.1
  • TomEE plus 8.0

I have created a topic with 2 consumers. Each consumer has 1 MDB each. 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. 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). I was trying all different ways to get my task accomplished.

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>
Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Tej
  • 21
  • 4
  • updated the question. Please check. I am nit sure why i am creating the shared durable cnsumer on mytopic(subscription name). I was trying all different ways to get my task accomplished. Yes, The MDB1 Is istneing to BTopic and MDB2 is listening to CTopic. But both Btopic and the Ctopic are on the same address queue. Update the my actual question. – Tej Mar 24 '20 at 15:31
  • Thank you for phrasing my question better, Please help me out in solving this. – Tej Mar 24 '20 at 15:50

1 Answers1

0

Your configuration is incorrect in multiple places.

First, a JMS topic is implemented by an address which supports multicast, nothing more. This is noted in the ActiveMQ Artemis documentation. Therefore, your broker.xml should have this:

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

Second, your MDBs should be subscribing to ATOPIC using the same subscription name and no clientId, e.g.:

@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.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • Made those changes, still both the MDBs are being triggered – Tej Mar 24 '20 at 17:08
  • I just tested this scenario in the ActiveMQ Artemis test-suite and everything worked as expected. My guess is that there's something in the integration with TomEE that's broken perhaps. Can you provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with TomEE and ActiveMQ Artemis (e.g. in a project on GitHub)? – Justin Bertram Mar 24 '20 at 18:17
  • Code to receive the msg: ```connectionFactory = new ActiveMQConnectionFactory(input.getUrl()); connection=(ActiveMQConnection)connectionFactory.createConnection(input.getUsername(), input.getPassword()); session = connection.createQueueSession(input.isTransacted(), Session.AUTO_ACKNOWLEDGE); connection.start(); session = connection.createSession(true, Session.SESSION_TRANSACTED); destination = session.createTopic(input.getQueueTopicName()); consumer = session.createConsumer(destination); rtn = consumer.receive(); session.commit(); ``` – Tej Mar 24 '20 at 20:26
  • What is this code for? Aren't you using MDBs to receive the message? – Justin Bertram Mar 25 '20 at 00:53
  • This is the code used to start my java program. i.e mainMethod. One more question. why are there so many longValued Queues being generated in the Artemis Console for my address setting ? May i know what are all the good resources to learn Artemis. I am so stuck in thing since almost 2 weeks. – Tej Mar 25 '20 at 12:39
  • Why are you pasting the code used to start your Java program? In any case, all it's doing is receiving a JMS message from a non-durable topic subscription. – Justin Bertram Mar 25 '20 at 15:32
  • You should should start a *new* question about what you're seeing in the ActiveMQ Artemis web console. – Justin Bertram Mar 25 '20 at 15:32