2 Replies Latest reply on Aug 3, 2011 5:42 AM by Optimus Prime

    Transaction question

    Optimus Prime Newbie

      Hi all, I'm starting with JMS and I'm doing some samples before going mainstream.


      I'm trying to get the whole transaction + jms to work, but I think I might misunderstood the concept, please correct me :


      From what I understood, when using a session inside a JTA (XA) transaction, in case of message producing, the message will only be sent to the destination after the underlying TX is commited. And when consuming the message will only be acknowledge after the tx is commited as well. This would give the chance of other resources (EJBs, PersistenceContexts) to be part of the transaction right?


      Well I've tried this but it;s not working, my scenario:


      A REST (CDI) endpoint creates a XASession and sends a message, inside the same method it calls a SLSB that persists an entity (this step fails on purpose). I was expecting the message to never be sent, since the SLSB rolledback the TX, but it's sent just after the call to producer.send...


      What am I missing here?


      Here's my small code:



      public class MessageSenderImpl implements MessageSender {
                private Queue destination;
                private XAConnectionFactory xa;
                private TransactionalOrderService txService;
                public void sendTx(String message) {
                          XAConnection conn = null;
                          XASession session = null;
                          try {
                                    conn = xa.createXAConnection();
                                    session = conn.createXASession();
                                    MessageProducer producer = session.createProducer(destination);
                                    TextMessage txtMessage = session.createTextMessage(message);
                                    Order order = new Order();
                          } catch (Exception e) {
                                    try {
                                    } catch (JMSException e) {
      public interface TransactionalOrderService {
                public void save(Order order);
      public @Stateless class TransactionalOrderServiceBean implements TransactionalOrderService {
                private EntityManager em;
                public void save(Order order) {



      Have I got the whole TX concept wrong?


      Any help/advice is MOST appreciated


      Best Regards