3 Replies Latest reply on Jul 13, 2017 4:04 AM by Yuva Bejjanki

    How to get JMS local transaction with JBOSS AS 7.2.0

    Chintan Modha Newbie

      Hi All,


      I'm trying to obtain JMS local transaction with JBOSS AS 7.2.0, but unfortunately I'm unable to get one. The issue over here is that when I use


      session = conn.createQueueSession(true,QueueSession.AUTO_ACKNOWLEDGE);

      the session that I'm getting is not transacted, even when I pass "true" to the createQueueSession(boolean transacted, int acknowledgeMode) method.  I'm not sure what am I doing wrong over here . Also, I'm using IBM WMQ 6 as a JMS provider for this example.


      Here's my JMS code, which I'm invoking through a servlet.


      package com.example.test;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSession;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      public class QueueConnectionTest implements MessageListener{
          private String jndiConnectionFactoryName = null;
          private String jndiQueueName = null;
          private QueueConnectionFactory factory = null;
          private QueueConnection conn = null;
          private QueueReceiver receiver = null;
          private QueueSession session = null;
          private Queue testQueue = null;
          public QueueConnectionTest(String jndiConnectionFactoryName, String jndiQueueName){
              this.jndiConnectionFactoryName = jndiConnectionFactoryName;
              this.jndiQueueName = jndiQueueName;       
          public void initilize(){
              if(this.jndiConnectionFactoryName!=null && this.jndiQueueName!=null){
                      Context context = new InitialContext();
                      factory = (QueueConnectionFactory) context.lookup(this.jndiConnectionFactoryName);
                          testQueue = (Queue) context.lookup(this.jndiQueueName);
                          if(factory!=null && testQueue!=null){
                              conn =  factory.createQueueConnection();
                              session = conn.createQueueSession(true,QueueSession.AUTO_ACKNOWLEDGE);
                              receiver = session.createReceiver(testQueue);
                              System.out.println(":::: Receiver STARTED for accepting messages ::::");                   
                  }catch(NamingException nx){
                  }catch(JMSException ex){
          public void onMessage(Message msg) {
              // TODO Auto-generated method stub
              if(msg!=null && msg instanceof TextMessage){
                  TextMessage txtMsg = (TextMessage)msg;
                  try {
                      System.out.println("Got Message : "+txtMsg.getText());
                      System.out.println("Is session transacted...."+session.getTransacted());               
                  } catch (JMSException e) {


      Here's my servlet code which initializes and starts the inbound message receiver.


      package com.scholastic.test;
      import java.io.IOException;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      * Servlet implementation class ConnectionServlet
      public class ConnectionServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;
           * @see HttpServlet#HttpServlet()
          public ConnectionServlet() {
              // TODO Auto-generated constructor stub
           * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              // TODO Auto-generated method stub
           * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              // TODO Auto-generated method stub
              QueueConnectionTest qConn = new QueueConnectionTest("jboss/jms/BPJMSQueueConnectionFactory","jboss/jms/BPJMSInboundQueue");


      I'm also attaching the WMQ resource adapter configuration, which I have used for standalone-full.xml


      <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
                  <config-property name="traceEnabled">true</config-property>
                  <config-property name="traceLevel">3</config-property>
                      <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedQueueConnectionFactoryImpl" jndi-name="java:jboss/jms/BPJMSQueueConnectionFactory" enabled="true" use-java-context="true" pool-name="BPJMSQueueConnectionFactoryPool">
                          <config-property name="port">1417</config-property>
                          <config-property name="hostName">xx.xx.xx.xxx</config-property>
                          <config-property name="channel">MQ.CLIENT</config-property>
                          <config-property name="transportType">CLIENT</config-property>
                          <config-property name="queueManager">MYQGMR</config-property>
                      <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/jms/BPJMSInboundQueue" enabled="true" use-java-context="true" pool-name="BPJMSInboundQueuePool">
                          <config-property name="baseQueueName">INBOUND.QUEUE.TESTING</config-property>
                          <config-property name="baseQueueManagerName">MYQGMR</config-property>
                          <config-property name="targetClient">JMS</config-property>


      so whenever I run my test, I always get the below message in the logs


      13:45:56,735 INFO  [stdout] (http-localhost/ Got Message : Hello


      13:45:56,735 INFO  [stdout] (http-localhost/ Is session transacted....false


      Can someone please help me out in how to obtain transacted session ? I appreciate any insights on this is particular issue.




        • 1. Re: How to get JMS local transaction with JBOSS AS 7.2.0
          xiang yingbing Master

          You send message in servlet has NO transaction around!

          Your sevlet can call am EJB session which can be used to send your JMS.


          I hope bellow code snippet is useful to you:


          (a) get userTransabtion in EJB session:





          public class GprsServerSocketService implements IGprsServerSocketService{

          private UserTransaction userTransaction;


          (b) use it


              try {
             //检查这个NE 是否存在:
             if(! neList.contains(terminatorAddressHexString)){
             //不要调用com.ybxiang.nms.ejb.session.secure.ISecuredRemoteSession.addNe(Ne, Long),它有权限控制!
             //User u = em.find(User.class, 1L);
             NeGroup group = em.find(NeGroup.class, 1L);
             Ne ne = new Ne();
             ne.setLatestHeartBeat(new Date());//心跳!
             Ne freshNe = em.merge(ne);
             em.createQuery("UPDATE "+ Ne.class.getName()+ " obj SET obj."+Ne.FIELD_NAME_HEART_BEAT+"=:_hearBeat WHERE obj."+Ne.FIELD_NAME_ADDRESS_HEX+"=:_addressHex")
             .setParameter("_hearBeat",new Date())
              } catch (Exception e) {
             log.error("updateHearBeat Exception:",e);
              } finally {
                  try {
                      if (userTransaction.getStatus() == Status.STATUS_ACTIVE)
                  } catch (Throwable e) {
          1 of 1 people found this helpful
          • 2. Re: How to get JMS local transaction with JBOSS AS 7.2.0
            Chintan Modha Newbie

            Thank you Xiang for the prompt reply and for your suggestions. I'm looking here to obtain local JMS transaction, without using UserTransaction.To my knowledge UserTransaction and local JMS transaction are two different things. Also, I'm looking to not have an EJB as EJB's tend to be heavy as compared to lightweight POJO which uses JMS.




            • 3. Re: How to get JMS local transaction with JBOSS AS 7.2.0
              Yuva Bejjanki Newbie

              Hello, we have same issue, please let us know if u found any solution for this.