activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neo Wang <wangdong...@hotmail.com>
Subject The RA(Resource Adaptor) provided in the ActiveMQ 5.2 doesn't work
Date Fri, 04 Sep 2009 02:39:06 GMT

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.


Mime
View raw message