2 Replies Latest reply on Mar 2, 2017 12:52 PM by Sai Pabbathi

    How do you use @Resource to connect to remote JMS queues

    Kristjan Gudbjornsson Newbie

      Hi, I am looking for a way to inject remote queues into my code in a similar way as is done with connection factories.

       

      My environment:

      JBoss 5.1 EAP in two clusters

      - A messaging cluster that runs JBoss Messaging 1.4.7.GA

      - An application cluster, that connects to the remote JMS on the messaging cluster. JBoss Messaging has been removed in the application cluster, and a remote JMS provider added.

       

      The problem is the mapped name in the queue injection, a remote jndi lookup is needed to inject the queue.

      My resource injection looks like this:

      {code}

      @Resource(mappedName="jnp://localhost:1199/jms/jb.itu.tes.jms.test.queue.b")

      Destination jmdest;

      {code}

       

       

      We have four different environments, Development, Test, Staging and Production.  And that requires different host:port configuration for each environment, because each environment has its own messaging cluster.

      Is there a way to do the queue lookup in a similar way to the connection factory lookup?  How do you inject remote resources in your code?

       

      Here is the application cluster JMS configuration

      {code:xml}

      <mbean code="org.jboss.jms.jndi.JMSProviderLoader"

           name="jboss.messaging:service=JMSProviderLoader,name=RemoteJMSProvider">

          <attribute name="ProviderName">RemoteJMSProvider</attribute>

          <attribute name="ProviderAdapterClass">

            org.jboss.jms.jndi.JNDIProviderAdapter

          </attribute>

          <!-- The combined connection factory -->

          <attribute name="FactoryRef">XAConnectionFactory</attribute>

          <!-- The queue connection factory -->

          <attribute name="QueueFactoryRef">XAConnectionFactory</attribute>

          <!-- The topic factory -->

          <attribute name="TopicFactoryRef">XAConnectionFactory</attribute>

          <!-- Access JMS via HAJNDI -->

          <attribute name="Properties">

             java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

             java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

             jnp.disableDiscovery=false

             jnp.partitionName=DocsPartitionCluster

             jnp.discoveryGroup=239.255.100.101

             jnp.discoveryPort=1102

             jnp.discoveryTTL=16

             jnp.discoveryTimeout=5000

             jnp.maxRetries=1

          </attribute>

      </mbean>

       

      <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->

      <tx-connection-factory>

          <jndi-name>RemoteJmsXA</jndi-name>

          <xa-transaction/>

          <rar-name>jms-ra.rar</rar-name>

          <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>

          <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>

          <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/RemoteJMSProvider</config-property>

          <max-pool-size>20</max-pool-size>

          <config-property name="UserName" type="java.lang.String">guest</config-property>

          <config-property name="Password" type="java.lang.String">guest</config-property>

          <security-domain-and-application>RemoteJmsXARealm</security-domain-and-application>

      </tx-connection-factory>

      {code}