10 Replies Latest reply on May 7, 2014 1:25 PM by takeshinho

    How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1

    takeshinho Newbie

      Hi all,

      I'd like to know how can I use UserTransaction.commit() to commit or rollback

      MQ and Database transaction same time.

       

      I cannot find any example and I just wonder it is impossible.

       

      Please tell me, if somebody knows something.

       

      Thanks

        • 1. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
          Wolf-Dieter Fink Master

          Never used WS-MQ but from the Tx perspective, if you use the MQ inside of EAP I think you need to have a XA resource adapter for MQ which handle the connection/transaction.

          The XA resource use the EAP TxManager and the TxManager will use the 2phase XA protocoll to commit/rollback all resources

          1 of 1 people found this helpful
          • 2. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
            takeshinho Newbie

            Thanks for your reply.

            Is there any example about usage of JBoss EAP TxManager?

            • 3. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
              Wolf-Dieter Fink Master

              Maybe there is already an implementation of a resource adapter for WS-MQ.

              Otherwise you can have a look to IronJacamar examples

              • 4. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                takeshinho Newbie

                >Maybe there is already an implementation of a resource adapter for WS-MQ.

                I've had look at it and find out there is no way to commit WSMQ transaction

                using UserTransaction after MQGET done by MessageDrivenBean.

                It seems like MDB is only one way to get message from WSMQ.

                Now I need to create my own WSMQ message consumer deployed in JBoss.

                 

                >Otherwise you can have a look to IronJacamar examples

                Please show me some links if you can.


                Thanks

                • 5. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                  Miroslav Novak Master

                  Hi Takeshi,

                   

                  at this moment communication to Webshere MQ is supported only through Websphere MQ resouce adapter.

                  Take a look at official documentation for EAP 6.2: https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/6.2/html-single/Administration_… This will guide you through installation.

                   

                  Your deployment must use connection factory deployed by this Webshere MQ RA so you can use XA transactions.

                   

                  Cheers,

                  Mirek

                  • 6. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                    takeshinho Newbie

                    Hi Miroslav,

                     

                     

                    Thanks for your information.

                     

                     

                    I have already deployed wmq.jmsra.rar and it works fine

                    as long as I get message through MDB.

                     

                     

                    But when I tried to get message through ConnctionFactory,

                    and  it doesn't work....

                     

                     

                    I can put message into MQ queue that registered in admin-object tag,

                    But I cannot get any message.

                     

                     

                    I need to read WMQ queue message without using MDB.

                    Because WMQ MDB's transaction scope is not

                    adequate for our transaction strategy.

                     

                     

                    So, I wonder what should I do..

                    • 7. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                      Miroslav Novak Master

                      Hi Takeshi,

                       

                      reading of messages should work especially when you can send messages. Can you check log of WebshereMQ server for any warnings/errors? There could be a security permission problem. Then just for sure check whether you're calling connection.start() before receiving messages. If it does not help, can you share your configuration of EAP and also of WebsphereMQ server. Which version of WebsphereMQ server are you using? Anything what could help to investigate or reproduce the issue.

                       

                      Thanks,

                      Mirek

                      • 8. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                        takeshinho Newbie

                        OK

                        This is my MDB.

                         

                        import java.sql.Timestamp;

                        import java.util.Date;

                         

                         

                        import javax.annotation.Resource;

                        import javax.ejb.ActivationConfigProperty;

                        import javax.ejb.EJB;

                        import javax.ejb.MessageDriven;

                        import javax.ejb.MessageDrivenContext;

                        import javax.ejb.TransactionAttribute;

                        import javax.ejb.TransactionAttributeType;

                        import javax.ejb.TransactionManagement;

                        import javax.ejb.TransactionManagementType;

                        import javax.interceptor.Interceptors;

                        import javax.jms.Connection;

                        import javax.jms.ConnectionFactory;

                        import javax.jms.JMSException;

                        import javax.jms.Message;

                        import javax.jms.MessageListener;

                        import javax.jms.MessageProducer;

                        import javax.jms.Queue;

                        import javax.jms.Session;

                        import javax.jms.TextMessage;

                         

                         

                        import model.MessageHistory;

                         

                         

                        import org.jboss.ejb3.annotation.ResourceAdapter;

                        import org.jboss.logging.Logger;

                         

                         

                        import wmq.ejb.interceptor.LoggingInterceptor;

                         

                        @MessageDriven( name="MyMDB",

                                activationConfig =

                                {

                              @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),

                              @ActivationConfigProperty(propertyName  = "destinationType", propertyValue = "javax.jms.Queue"),

                              @ActivationConfigProperty(propertyName  = "connectionFactoryJndiName", propertyValue = "java:/jms/MyConnectionFactory"), // External JNDI Name

                              @ActivationConfigProperty(propertyName = "queueManager", propertyValue = "mq.mgr.01"),

                              @ActivationConfigProperty(propertyName = "channel", propertyValue = "mq.server.conn.01"),

                              @ActivationConfigProperty(propertyName = "destination", propertyValue = "mq.queue.01"),

                                })

                        @ResourceAdapter(value="wmq.jmsra.rar")

                        @TransactionAttribute(TransactionAttributeType.REQUIRED)

                        @TransactionManagement(TransactionManagementType.CONTAINER)

                        public class MyMDB implements MessageListener{

                         

                          private static final Logger log = Logger.getLogger(MyMDB.class);

                         

                          @Resource(mappedName="java:/jms/mq.queue.02")

                          private Queue queue2;

                         

                          @Resource(mappedName="java:/jms/MyConnectionFactory")

                          private ConnectionFactory cf;

                         

                          @Resource

                          MessageDrivenContext ctx;

                         

                          @EJB

                          private HistoryUpdate historyUpdate;

                         

                          private static int cnt = 0;

                         

                          @Override

                          @Interceptors({LoggingInterceptor.class})

                            public void onMessage(Message message) {

                                TextMessage textMessage = (TextMessage) message;

                                try {

                                log.info(message);

                                    log.info("\n\n\t Message Received by MDB : "+ textMessage.getText());

                                 

                                    MessageHistory history = new MessageHistory();

                                    history.setMessage(textMessage.getText());

                                    Date nowDate = new Date();

                                    history.setReceived(new Timestamp(nowDate.getTime()));

                                 

                          Connection conn = this.cf.createConnection();

                          Session session = conn.createSession(true, Session.SESSION_TRANSACTED);

                          TextMessage outMessage = session.createTextMessage();

                          outMessage.setText(textMessage.getText() + " " + new Date() + "  " + cnt);

                         

                          MessageProducer producer = session.createProducer(queue2);

                         

                          producer.send(outMessage);

                         

                                    historyUpdate.update(history);

                         

                                    conn.close();

                         

                                   log.info("MyMDB End " + history);

                                 

                                } catch (JMSException e) {

                                    e.printStackTrace();

                          } catch (SecurityException e) {

                          e.printStackTrace();

                          } catch (IllegalStateException e) {

                          e.printStackTrace();

                          }

                            }

                        }

                         

                        and This is part of my standalone-full.xml

                         

                                <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">

                                    <resource-adapters>

                                        <resource-adapter id="wmq.jmsra.rar">

                                            <archive>

                                                wmq.jmsra.rar

                                            </archive>

                                            <transaction-support>XATransaction</transaction-support>

                                            <connection-definitions>

                                                <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/jms/MyConnectionFactory" enabled="true" use-java-context="false" pool-name="MyConnectionFactory">

                                                    <config-property name="port">

                                                        1414

                                                    </config-property>

                                                    <config-property name="hostName">

                                                        localhost

                                                    </config-property>

                                                    <config-property name="channel">

                                                        mq.server.conn.01

                                                    </config-property>

                                                    <config-property name="transportType">

                                                        CLIENT

                                                    </config-property>

                                                    <config-property name="queueManager">

                                                        mq.mgr.01

                                                    </config-property>

                                                    <validation>

                                                        <background-validation>false</background-validation>

                                                    </validation>

                                                </connection-definition>

                                            </connection-definitions>

                                            <admin-objects>

                                                <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/jms/mq.queue.02" enabled="true" use-java-context="false" pool-name="MyQueuePool02">

                                                    <config-property name="baseQueueManagerName">

                                                        mq.mgr.01

                                                    </config-property>

                                                    <config-property name="baseQueueName">

                                                        mq.queue.02

                                                    </config-property>

                                                </admin-object>

                                                <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/jms/mq.queue.01" enabled="true" use-java-context="false" pool-name="MyQueuePool01">

                                                    <config-property name="baseQueueManagerName">

                                                        mq.mgr.01

                                                    </config-property>

                                                    <config-property name="baseQueueName">

                                                        mq.queue.01

                                                    </config-property>

                                                </admin-object>

                                            </admin-objects>

                                        </resource-adapter>

                                    </resource-adapters>

                                </subsystem>

                         

                        And sorry for localization, but this is how my MQ Explorer shows.

                        There is two input count by MDB and one output count by admin-object.

                        So I cannot get message from this admin-object queue .

                         

                        MQExplorer.PNG

                        • 9. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                          takeshinho Newbie

                          >reading of messages should work especially when you can send messages.


                          I'm not so sure of it.

                          Can you show me some example of source code which read message from MQ without using MDB,

                          because so far I cannot find anything.


                          Thanks

                          • 10. Re: How can I synchronize Websphere MQ transaction and datasource transaction in JBoss EAP 6.1
                            takeshinho Newbie

                            I found that I just had forgot

                            Connection.start().

                             

                            Now I can receive message from my Websphere MQ.

                             

                            Now I'm having another problem with XA-Transaction.

                            I'll put this in another question.

                             

                            Thanks.