You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Neo Wang <wa...@hotmail.com> on 2009/09/04 04:39:06 UTC

The RA(Resource Adaptor) provided in the ActiveMQ 5.2 doesn't work

Environment: JDK 1.5, ActiveMQ 5.2, JBoss 5.1 GA, Oracle 10g

My test case is send a message to queue and  then save the data in DB in one
transaction, all of the them are finished a EJB2.1 stateless session bean,
the transaction is "Required", I have configured the AMQ as embedded broker,
all of the configuration has been done, I found the message is still sent to
queue even an exception is thrown in DB operation. It seems that the RA of
AMQ doesn't work in this version. The following is the some sections of the
related configuration and source code:

1. In ejb-jar.xml, I have configured  all of the JNDI name

		<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>
         	<resource-ref>
            	<res-ref-name>jms/TopicConnectionFactory</res-ref-name>
            	<res-type>javax.jms.TopicConnectionFactory</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>
         	<message-destination-ref>
            
<message-destination-ref-name>jms/OrderBroadcastTopic</message-destination-ref-name>
            
<message-destination-type>javax.jms.Topic</message-destination-type>
            	<message-destination-usage>Produces</message-destination-usage>
            
<message-destination-link>OrderBroadcastTopic</message-destination-link>
         	</message

2. jboss.xml

      <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>
         <resource-ref>
            <res-ref-name>jms/TopicConnectionFactory</res-ref-name>
            <resource-name>topicfactoryref</resource-name>
         </resource-ref>
      </session>

3.  In the stateless session bean, I get all of the objects through JNDI
lookup of app server. 	

protected 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();
			if(logger.isDebugEnabled()) logger.debug("Platform:Publisher Queue
Session connnection is created1..." );
			
		} 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);
		}
	}
	
	protected 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(String message){
		try {
			QueueSession queueSession = this.createQueueSession();
			TextMessage textMessage = queueSession.createTextMessage(message);
			
			//QueueSender sender = queueSession.createSender(queue);
			//sender.send(textMessage);
			
			//queueSession.close();
			
			MessageProducer procedure = queueSession.createProducer(queue);
			procedure.send(textMessage);
			
		} catch (JMSException e) {
			if(logger.isErrorEnabled()) logger.error("JMSException:" + e);
			throw new SystemException("System Error", e);
		}	
	}
	

4. When exception happen, I handle the transaction rollback as following:

catch (Throwable e) {
			isException = true;
			e.printStackTrace();
			if(logger.isErrorEnabled()) logger.error("Platform:AppControllerBean
error:" + e);
			throw new InvokeException("System Error", e);
		} finally {
			try {
				if(isException){
					sessionContext.setRollbackOnly();
				}
			} catch (Exception ise) {
				if(logger.isErrorEnabled()) logger.error("Platform:AppControllerBean
error:" + ise);
				ise.printStackTrace();
				throw new InvokeException("Undefined Error", ise);
			}
		}


------------------------------------------------------------------------------------------

I have struggled many days and no any progress, any suggestion about it?


-- 
View this message in context: http://www.nabble.com/The-RA%28Resource-Adaptor%29-provided-in-the-ActiveMQ-5.2-doesn%27t-work-tp25287386p25287386.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: The RA(Resource Adaptor) provided in the ActiveMQ 5.2 doesn't work

Posted by Neo Wang <wa...@hotmail.com>.
Some new finding about it, as my framework, I will initialize the
QueueConnnectionFactory and start the QueueConnection in the handleEvent()
method of one stateless session bean when it is invoked at first time(the
transaction attribute is "Required" and CMT). Then for the following
request, it will reuse the created conneciton, but for each request, a new
session will be created for sending message to queue(createQueueSession()
and sendMessageToQueue()), the strange string is for the first invoke, the
XA is work, the message will not be sent to queue if db update is failed.
But for the next requests, it doesn't work. It seems for the following
request, it doesn't join the XA transaction. But I don't know why it happen.
Another, I do some modification in the jca-jboss-beans.xml of jboss
configuration, 

<bean name="CachedConnectionManager"
class="org.jboss.resource.connectionmanager.CachedConnectionManager"> 

     <!-- Expose via JMX -->  
    
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.jca:service=CachedConnectionManager",
exposedInterface=org.jboss.resource.connectionmanager.CachedConnectionManagerMBean.class)</annotation>

     <!-- Whether to track unclosed connections and close them -->
     <property name="debug">false</property>

     <!-- Whether to throw an error for unclosed connections (true) or just
log a warning (false) -->
     <property name="error">false</property>
    
     <!-- The transaction manager -->
     <property name="transactionManager"><inject bean="TransactionManager"
property="transactionManager"/></property>

  </bean>

I change the "<property name="debug">false</property>" from the "true" to
"false", otherwise, the operation can't be finished successfully. One
exception like "you must close the ActiveMQ connection" is throw.



Neo Wang wrote:
> 
> Environment: JDK 1.5, ActiveMQ 5.2, JBoss 5.1 GA, Oracle 10g
> 
> My test case is send a message to queue and  then save the data in DB in
> one transaction, all of the them are finished a EJB2.1 stateless session
> bean, the transaction is "Required", I have configured the AMQ as embedded
> broker, all of the configuration has been done, I found the message is
> still sent to queue even an exception is thrown in DB operation. It seems
> that the RA of AMQ doesn't work in this version. The following is the some
> sections of the related configuration and source code:
> 
> 1. In ejb-jar.xml, I have configured  all of the JNDI name
> 
> 		<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>
>          	<resource-ref>
>             	<res-ref-name>jms/TopicConnectionFactory</res-ref-name>
>             	<res-type>javax.jms.TopicConnectionFactory</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>
>          	<message-destination-ref>
>             
> <message-destination-ref-name>jms/OrderBroadcastTopic</message-destination-ref-name>
>             
> <message-destination-type>javax.jms.Topic</message-destination-type>
>             
> <message-destination-usage>Produces</message-destination-usage>
>             
> <message-destination-link>OrderBroadcastTopic</message-destination-link>
>          	</message
> 
> 2. jboss.xml
> 
>       <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>
>          <resource-ref>
>             <res-ref-name>jms/TopicConnectionFactory</res-ref-name>
>             <resource-name>topicfactoryref</resource-name>
>          </resource-ref>
>       </session>
> 
> 3.  In the stateless session bean, I get all of the objects through JNDI
> lookup of app server. 	
> 
> protected 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();
> 			if(logger.isDebugEnabled()) logger.debug("Platform:Publisher Queue
> Session connnection is created1..." );
> 			
> 		} 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);
> 		}
> 	}
> 	
> 	protected 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(String message){
> 		try {
> 			QueueSession queueSession = this.createQueueSession();
> 			TextMessage textMessage = queueSession.createTextMessage(message);
> 			
> 			//QueueSender sender = queueSession.createSender(queue);
> 			//sender.send(textMessage);
> 			
> 			//queueSession.close();
> 			
> 			MessageProducer procedure = queueSession.createProducer(queue);
> 			procedure.send(textMessage);
> 			
> 		} catch (JMSException e) {
> 			if(logger.isErrorEnabled()) logger.error("JMSException:" + e);
> 			throw new SystemException("System Error", e);
> 		}	
> 	}
> 	
> 
> 4. When exception happen, I handle the transaction rollback as following:
> 
> catch (Throwable e) {
> 			isException = true;
> 			e.printStackTrace();
> 			if(logger.isErrorEnabled()) logger.error("Platform:AppControllerBean
> error:" + e);
> 			throw new InvokeException("System Error", e);
> 		} finally {
> 			try {
> 				if(isException){
> 					sessionContext.setRollbackOnly();
> 				}
> 			} catch (Exception ise) {
> 				if(logger.isErrorEnabled()) logger.error("Platform:AppControllerBean
> error:" + ise);
> 				ise.printStackTrace();
> 				throw new InvokeException("Undefined Error", ise);
> 			}
> 		}
> 
> 
> ------------------------------------------------------------------------------------------
> 
> I have struggled many days and no any progress, any suggestion about it?
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/The-RA%28Resource-Adaptor%29-provided-in-the-ActiveMQ-5.2-doesn%27t-work-tp25287386p25287686.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.