Bhavesh Kharwa
Bhavesh Kharwa

Reputation: 73

How do I lookup a multicast queue?

Configured following topic/queue in broker.xml:

<address name="Topic1">
   <multicast>
      <queue name="Queue1"/>
      <queue name="Queue2"/>
   </multicast>
</address>

How can I create producer for Queue1/Queue2 for send message? I am using ActiveMQ Artemis 2.6.3.

Using following way I am creating connection factory, connection and queue lookup

Hashtable<String, Object> properties = new Hashtable<>();
properties.put("connectionFactory.ConnectionFactory", (tcp://localhost:61618,tcp://localhost:61616)?ha=true&retryInterval=3000&reconnectAttempts=-1&initialConnectAttempts=10&maxRetryInterval=3000&clientFailureCheckPeriod=1000);
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
InitialContext jndiContext = new InitialContext(properties);
ConnectionFactory connFactory = (ConnectionFactory) jndiContext.lookup(connectionFactory);
Connection connection = connFactory.createConnection(userName, password);
Session session = connection.createSession(true,javax.jms.Session.AUTO_ACKNOWLEDGE);
//Using following way looking up Multicast Queue2 on Address Topic1
Destination dest = new ActiveMQTopic("Topic1::Queue2");
MessageProducer producer = session.createProducer(dest);
producer.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, msgTTL);

After did with the above code change and try to send message, message will not send to queue "Queue2"

Upvotes: 1

Views: 1414

Answers (2)

Justin Bertram
Justin Bertram

Reputation: 35123

In general you want to pick the right kind of routing-type for your needs. The choices are:

  • anycast: provides point-to-point semantics (e.g. a JMS queue); messages sent to the address are routed to just one anycast queue
  • multicast: provides publish-subscribe semantics (e.g. a JMS topic); messages sent to the address are routed to all multicast queues

You've got an address named Topic with 2 multicast queues - Queue1 & Queue2. Therefore, messages sent to Topic will go to both Queue1 & Queue2. If you want to send messages to just one queue you might consider using a different configuration (e.g. an address with an anycast queue).

However, if you find that you really need your existing configuration for whatever reason then you can send message using the fully qualified queue name (i.e. FQQN) via the syntax <address>::<queue>. I see that you're already attempting to do this, e.g.:

Destination dest = new ActiveMQTopic("Topic1::Queue2");

However, the version of ActiveMQ Artemis you're using doesn't support FQQN for producers. To use this functionality I recommend you upgrade to at least 2.7.0 or ideally to the latest release which is 2.17.0.

Upvotes: 2

luismoramedina
luismoramedina

Reputation: 14

Same solution as @justin with spring and artemis 2.7.0:

    JmsTemplate jmsTemplate = new JmsTemplate(new 
    ActiveMQConnectionFactory("tcp://localhost:61616"));
    //this is the important part
    jmsTemplate.setPubSubDomain(true);
    jmsTemplate.convertAndSend("Topic1::Queue2", "hello");

Upvotes: -1

Related Questions