How to use FQQN with MDB

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Application Platform (EAP)
    • 7.3
  • Red Hat AMQ (AMQ)
    • 7.7

Issue

  • How to use fully qualified queue names (FQQN) with MDB

Resolution

Having a topic with durable named subscriptions on the external AMQ7 broker:

<address name="example.foo">
  <multicast>
    <queue name="q1"></queue>
    <queue name="q2"></queue>
  </multicast>
</address>

And a remote JNDI context defined on EAP application server:

<subsystem xmlns="urn:jboss:domain:naming:2.0">
  <bindings>
    <external-context name="java:global/remote" module="org.apache.activemq.artemis" class="javax.naming.InitialContext">
      <environment>
        <property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
        <property name="java.naming.provider.url" value="tcp://localhost:61616"/>
        <property name="connectionFactory.ConnectionFactory" value="tcp://localhost:61616"/>
        <property name="topic.example.foo" value="example.foo"/>
        <property name="queue.example.foo::q1" value="example.foo::q1"/>
        <property name="queue.example.foo::q2" value="example.foo::q2"/>
      </environment>
    </external-context>
    <lookup name="java:/jms/topic/example.foo" lookup="java:global/remote/example.foo"/>
    <lookup name="java:/jms/queue/example.foo::q1" lookup="java:global/remote/example.foo::q1"/>
    <lookup name="java:/jms/queue/example.foo::q2" lookup="java:global/remote/example.foo::q2"/>
  </bindings>
  <remote-naming/>
</subsystem>

It is possible to subscribe your MDB using the fully qualified queue name (FQQN):

@MessageDriven(name = "TestQueueMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/example.foo::q1"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "15"),
    @ActivationConfigProperty(propertyName = "hA", propertyValue = "true"),
    @ActivationConfigProperty(propertyName = "rebalanceConnections", propertyValue = "true"),
    @ActivationConfigProperty(propertyName = "user", propertyValue = "admin"),
    @ActivationConfigProperty(propertyName = "password", propertyValue = "admin")
})

Note that queue names (q1, q2) must be different from the topic name (example.foo).

Root Cause

After subscribing to AMQ 7 topic, a new queue named with a UUID is automatically created for every subscriber. More advanced use cases might require that the client specify a queue directly. In this situation the client can use the fully qualified queue name (FQQN), by specifying both the address name and the queue name (i.e. topicName::queueName).

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.