[jboss-user] [JBoss Messaging] - Re: Remote JMS server and XA transaction

Thunder Lei do-not-reply at jboss.com
Thu Aug 25 22:50:25 EDT 2011


Thunder Lei [http://community.jboss.org/people/Thunder.Farmer] created the discussion

"Re: Remote JMS server and XA transaction"

To view the discussion, visit: http://community.jboss.org/message/623078#623078

--------------------------------------------------------------
oooh, I have to say sorry for confusing.
We can do that.
To so that, simply you just need to,

In jms-ds.xml

1. define a External jndi Context, which is NOT necessary, just to simply your code, with this external jndi context, you don't need to have local jndi context and remote jndi context if you need to look up ojbects accross servers.

 <mbean code="org.jboss.naming.ExternalContext" name="jboss.jndi:service=ExternalContext,jndiName=remote">
     <attribute name="JndiName">remote</attribute>
     <attribute name="Properties">
        java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
        java.naming.factory.url.pkgs=org.jnp.interfaces
                jnp.partitionName=jms_remote
     <!-- java.naming.provider.url=jnp://serverB:1099 -->
     </attribute>
  </mbean>


2. using external jndi, define a remote JMS Provider pointing the remote server, in abouve case, server B.

   <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
      name="jboss.mq:service=JMSProviderLoader,name=RemoteJMSProvider,server=remotehost">
    <attribute name="ProviderName">RemoteJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
    <attribute name="FactoryRef">remote/ClusteredXAConnectionFactory</attribute>
    <attribute name="QueueFactoryRef">remote/ClusteredXAConnectionFactory</attribute>
    <attribute name="TopicFactoryRef">remote/ClusteredXAConnectionFactory</attribute>
    <depends>jboss.jndi:service=ExternalContext,jndiName=remote</depends>
  </mbean>


3. define a connection factory using the JMS Privider, and apply the jms JCA adapter to the connection factory.

| <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>
    <adapter-display-name>JMS Adapter</adapter-display-name>
    <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/RemoteJMSProvider</config-property>
    <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property> 
 </tx-connection-factory>


4. In the EJB code like,

Context ctx = getInitialContext();
                              ConnectionFactory cf = (ConnectionFactory)ctx.lookup("java:/RemoteJmsXA");
                              Destination remoteQueue = (Destination)ctx.lookup("remote/javax.jms.RemoteQueue");
                              connection = cf.createConnection();
                              sessionProducer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                              producer = sessionProducer.createProducer(remoteQueue);
                              ObjectMessage om = sessionProducer.createObjectMessage("StringObjectMessage");
                              producer.send(om);
                              System.out.println("============Message Sent========================");
     // some db update
   Thread.currentThread().sleep(1000 * 15); // verify xa tx



OK, enjoy your remote JMS xa tx......
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/623078#623078]

Start a new discussion in JBoss Messaging at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110825/cca4b061/attachment-0001.html 


More information about the jboss-user mailing list