tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joeleclems <joelecl...@free.fr>
Subject Activemq embedded + createSession : unable to make it work!
Date Tue, 07 Oct 2014 16:03:40 GMT
Hi,

I'm using tomee 1.7.0 and try to use activemq embedded.
I succeed in sendind a message in a queue, and can consume it. 
The problem is using jms transaction, or "Session.CLIENT_ACKNOWLEDGE" mode
when creating session : none of them seems to work!

Testcase : 
1. Send a message (persistent, without jms transaction) to a queue
2. Send a REST call (does using REST is a problem?) 
3. Activate a message receiver (a thread) within rest function

This is activemq configuration in tomee.xml : 
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
	BrokerXmlConfig  =
broker:(tcp://127.0.0.1:61616)?usekahadb=true&amp;persistent=true&amp;kahadb.directory=../jmsdata
</Resource>

<Resource id="MyJmsConnectionFactory"
type="javax.jms.QueueConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
</Resource>

<Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
</Container>

<Resource id="MyQueue" type="javax.jms.Queue"></Resource>


This is my "Rest" Class, which intercept the call to activate receiver : 
@Stateless
@LocalBean
@Path("/control_receiver/rest")
public class ServletControlReceiver {

...

@GET
@Path("/activate_receiver")
@Produces("text/html; charset=UTF-8")
public String activateReceiver() {
	MyReceiver mr = new MyReceiver();
	mr.start();
	return "receiver ok";
}

...
}


and the MyReceiver class, which read the JMS queue : 

public class MyReceiver extends Thread {

...

/**
	 * Runs the thread.
	 */
@Override
public void run() {
		QueueConnectionFactory connectionFactory = null;
		QueueConnection connection = null;
		QueueSession session = null;
		Queue orderQueue = null;
		MessageConsumer msgConsumer = null;
		Message inMessage = null;

		Context ctx = new InitialContext();
		connectionFactory = (QueueConnectionFactory)
ctx.lookup("java:openejb/Resource/MyJmsConnectionFactory");
		connection = connectionFactory.createQueueConnection();
		session = connection.createQueueSession(true,0); //don't work? => send an
"javax.jms.IllegalStateException: Not a transacted session" when calling
"commit" or "rollback" on session

		//session = connection.createQueueSession(false,
Session.CLIENT_ACKNOWLEDGE); Session.CLIENT_ACKNOWLEDGE not used?
			
		orderQueue = (Queue) ctx.lookup("java:openejb/Resource/MyQueue");

		// Create receiver and start connection
		connection.start();
		msgConsumer = session.createConsumer(orderQueue);

		while (true) {
			inMessage = msgConsumer.receive();
			if(resultOfFunction()){
				session.commit();
			} else {
				session.rollback();
				break;
			}
		}
     }
...

}

For lisibility i removed try/catch statements.


When i'm using this line to create a session
"session = connection.createQueueSession(true,0); "

and use rollback or commit operation, it result in this exception : 
javax.jms.IllegalStateException: Not a transacted session
    at org.apache.activemq.ActiveMQSession.commit(ActiveMQSession.java:569)
    at
org.apache.activemq.ra.ManagedSessionProxy.commit(ManagedSessionProxy.java:108)


What's wrong? 

Thanks in advance

Clément



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Activemq-embedded-createSession-unable-to-make-it-work-tp4672172.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Mime
View raw message