activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neo Wang <wangdong...@hotmail.com>
Subject Re: How to configure ActiveMQ to support XA transaction?
Date Mon, 31 Aug 2009 12:59:25 GMT

In fact, I have read these documents and followed the related configuration,
but the result is still failed. The following is the details:

1. The content of activemq-ds.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE connection-factories
    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<connection-factories>

   <tx-connection-factory>
      <jndi-name>trading/QueueConnectionFactory</jndi-name>
      <xa-transaction/>
      <!--<use-java-context>false</use-java-context>-->
      <track-connection-by-tx/>
      <rar-name>activemq-ra.rar</rar-name>
     
<connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
      <!--<ServerUrl>vm://localhost</ServerUrl>-->
      <ServerUrl>tcp://10.10.135.212</ServerUrl>
      <!--
      <UserName>sa</UserName>
      <Password></Password>
      -->
      <min-pool-size>1</min-pool-size>
      <max-pool-size>200</max-pool-size>
      <blocking-timeout-millis>30000</blocking-timeout-millis>
      <idle-timeout-minutes>3</idle-timeout-minutes>
   </tx-connection-factory>

   <tx-connection-factory>
      <jndi-name>trading/TopicConnectionFactory</jndi-name>
      <xa-transaction/>
      <!--<use-java-context>false</use-java-context>-->
      <track-connection-by-tx/>
      <rar-name>activemq-ra.rar</rar-name>
     
<connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
      <ServerUrl>tcp://10.10.135.212</ServerUrl>
      <!--<ServerUrl>vm://localhost</ServerUrl>-->
      <!--
      <UserName>sa</UserName>
      <Password></Password>
      -->
      <min-pool-size>1</min-pool-size>
      <max-pool-size>200</max-pool-size>
      <blocking-timeout-millis>30000</blocking-timeout-millis>
      <idle-timeout-minutes>3</idle-timeout-minutes>
   </tx-connection-factory>
  
   <mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.queue:name=outboundQueue">
      <attribute name="JNDIName">activemq/queue/outbound</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Queue</attribute>
      <attribute name="Properties">PhysicalName=queue.outbound</attribute>
   </mbean>
   
   <mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.queue:name=orderoutput">
      <attribute name="JNDIName">orderoutput</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Queue</attribute>
      <attribute
name="Properties">PhysicalName=queue.orderoutput</attribute>
   </mbean>

   <mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.topic:name=inboundTopic">
      <attribute name="JNDIName">activemq/topic/inbound</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Topic</attribute>
      <attribute name="Properties">PhysicalName=topic.inbound</attribute>
   </mbean>

</connection-factories>


2. The content of ejb.jar.xml

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
   version="2.1">
   
	<description>Trading EJB</description>
	<display-name>Application Controller Bean</display-name>
	<enterprise-beans>

		<!-- Session Beans -->
		<session>
			<description>Application Controller Bean</description>
			<display-name>Application Controller</display-name>
			<ejb-name>AppController</ejb-name>
			<home>com.trading.platform.ejb.AppControllerHome</home>
			<remote>com.trading.platform.ejb.AppController</remote>
			<ejb-class>com.trading.platform.ejb.AppControllerBean</ejb-class>
			<session-type>Stateless</session-type>
			<transaction-type>Container</transaction-type>
			<resource-ref>
            	<res-ref-name>jms/QueueConnectionFactory</res-ref-name>
            	<res-type>javax.jms.QueueConnectionFactory</res-type>
            	<res-auth>Container</res-auth>
            	<res-sharing-scope>Shareable</res-sharing-scope>
         	</resource-ref>
         	<message-destination-ref>
            
<message-destination-ref-name>jms/OrderOutputQueue</message-destination-ref-name>
            
<message-destination-type>javax.jms.Queue</message-destination-type>
            	<message-destination-usage>Produces</message-destination-usage>
            
<message-destination-link>OrderOutputQueue</message-destination-link>
         	</message-destination-ref>
		</session>
	</enterprise-beans>

	<assembly-descriptor>
		<container-transaction>
			<method>
				<ejb-name>AppController</ejb-name>
				<method-name>handleEvent</method-name>
			</method>
			<trans-attribute>Required</trans-attribute>
		</container-transaction>
		
		<message-destination>
         
<message-destination-name>OrderOutputQueue</message-destination-name>
      	</message-destination>
		
	</assembly-descriptor>
</ejb-jar>

3. The content of jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_5_0.dtd">

<jboss>

   <enterprise-beans>
      <session>
         <ejb-name>AppController</ejb-name>
         <jndi-name>ejb/AppController</jndi-name>
         <resource-ref>
            <res-ref-name>jms/QueueConnectionFactory</res-ref-name>
            <resource-name>queuefactoryref</resource-name>
         </resource-ref>
      </session>
   </enterprise-beans>
   
   <assembly-descriptor>
      <message-destination>
        
<message-destination-name>OrderOutputQueue</message-destination-name>
         <jndi-name>activemq/queue/outbound</jndi-name>
      </message-destination>
   </assembly-descriptor>

   <resource-managers>
   	  <resource-manager>
         <res-name>queuefactoryref</res-name>
         <res-jndi-name>java:/trading/QueueConnectionFactory</res-jndi-name>
      </resource-manager>
   </resource-managers>

</jboss>

4. The source of JMS client(It is invoked in a EJB 2 stateless session
transaction context)

	public void init(){
		if(logger.isDebugEnabled()) logger.debug("Platform:Publisher JMS
connection init is begin..." );
		
		this.getInitialContext();
		
		if(logger.isDebugEnabled()) logger.debug("Platform:Publisher JMS
connection init is end..." );
	}
	
	private void getInitialContext(){
		try {
			Context context = new InitialContext();
			QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)context.lookup(this.getQueueConnectionFactoryName());
			System.out.println("ConnectionFactory:" +
queueConnectionFactory.getClass());
			queueConn = queueConnectionFactory.createQueueConnection();
			System.out.println("Connection:" + queueConn.getClass());
			queue = (Queue)context.lookup(this.getQueueName());
			queueConn.start();
			System.out.println("Finished...");
		} catch (NamingException e) {
			if(logger.isErrorEnabled()) logger.error("NamingExcetion:" + e);
			throw new SystemException("System Error", e);
		} catch (JMSException e) {
			if(logger.isErrorEnabled()) logger.error("JMSException:" + e);
			throw new SystemException("System Error", e);
		}
	}
	
	public QueueSession createQueueSession(){
		QueueSession queueSession = null;
		try {
			queueSession = queueConn.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
		} catch (JMSException e) {
			if(logger.isErrorEnabled()) logger.error("JMSException:" + e);
			throw new SystemException("System Error", e);
		}
		return queueSession;
	}
	
	public void sendMessageToQueue(IVO vo){
		try {
			QueueSession queueSession = this.createQueueSession();
			ObjectMessage objMessage = queueSession.createObjectMessage(vo);
			
			QueueSender sender = queueSession.createSender(queue);
			sender.send(objMessage);
			
			queueSession.close();
		} catch (JMSException e) {
			if(logger.isErrorEnabled()) logger.error("JMSException:" + e);
			throw new SystemException("System Error", e);
		}	
	}

5. The source of sending message out(In a EJB transaction context)

                sendMessageToQueue(order);
		if(1 == 1){
			System.out.println("Error222");
			throw new SystemException("Error222", new Exception(""));
		}


I found the message is sent to queue even an exception will be thrown out
later, I have tried many ways, but results are all failed. It seems that the
transaction of ActiveMQ is not enlisted in the JTA transaction of JBoss. Any
suggestion about it?


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- 
View this message in context: http://www.nabble.com/How-to-configure-ActiveMQ-to-support-XA-transaction--tp25220910p25223088.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message