wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes EJB with CMT sending JMS message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB with CMT sending JMS message" Watch "EJB with CMT sending JMS message" New topic
Author

EJB with CMT sending JMS message

Nicki Carstensen
Greenhorn

Joined: Apr 27, 2010
Posts: 3
Hi all,

I have a problem with container managed transactions in a stateless session bean sending a jms message.
It seems i can't include my JMS session in the transaction.

Here's the code:

Problem is that no message ends up on the queue when the enqueueOrder method completes, and i would expect the container to commit the transaction. Method completes ok without throwing any exceptions.

However if I change to: the message is placed on the queue when the send(message) call completes. But that means the jms session is not part of the EJB transaction.

My app-server is JBoss5.1, and there are no consumers on the queue.

I'm probably missing something blindingly obvious, but i just can't spot it. Any help appreciated.

Michal Nalewajko
Greenhorn

Joined: Mar 07, 2013
Posts: 7
Hi,

you should commit the session when it is transacional.


Nicki Carstensen
Greenhorn

Joined: Apr 27, 2010
Posts: 3
Hi Michael,

Thanks for your tip, you are correct, if i call session.commit(); the message ends up on the queue.

But that confuses me .
I thought that when using
in a JEE container, the application server would create a resource adapter that wraps the real jms connection, enabling container managed transactions.

Please enlighten me if I'm wrong.
Nicki Carstensen
Greenhorn

Joined: Apr 27, 2010
Posts: 3
Found the solution!

JBoss provides resource adapter for JMS at java:/JmsXA, not at java:/ConnectionFactory in JNDI.

Here is the changed code:

Rest is still the same:

Messages are now placed on the queue when method completes and container commits transaction.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB with CMT sending JMS message
 
Similar Threads
JMS in Stateless Bean
problemwith MessageDriven Bean
mapping jms resource from jpa entity
mapping jms resource from jpa entity
JMS sender (Stateless EJB) sends message even if transaction fails