ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Transaction handling

Post new topic  Reply to topic
 Transaction handling « View previous topic :: View next topic » 
Author Message
drajani
PostPosted: Fri Jul 07, 2017 2:42 am    Post subject: Transaction handling Reply with quote

Newbie

Joined: 21 Dec 2016
Posts: 9

Hi, For C#.NET based application using MQ Appliance, I have below flow to be addressed.

- Read a message (Msg1) from an MQ on QueueManager MyQMgr
- Parse the content and do some logic
- Create and publish message (Msg2) with topic (Topic1) to MyQMgr for downstream systems.
- Do some more logic.
- Create and publish message (Msg3) with topic (Topic2) to MyQMgr for other downstream systems.
- Finally, commit the message Msg1.

Transaction behavior Requirement:
The end to end processing to be atomic. For eg, if Msg3 publish fails, Msg2 publish should fail and Msg1 should be rolled back.

Questions:
1. Is handling above scenario possible using IBM.XMS libraries with async model i.e., in OnMessage() event ?

2. If not, is this possible using IBM.WMQ libraries.

Regards
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Jul 07, 2017 3:45 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Yes, it's possible. Use an MQ Transaction.

Yes, it's better to use something other than the C++ API, as that is stabilized and won't be updated ever again. Which means it could stop working with newer C++ runtimes and other exciting things.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
drajani
PostPosted: Mon Jul 10, 2017 1:24 am    Post subject: Reply with quote

Newbie

Joined: 21 Dec 2016
Posts: 9

Thank you. With below code the messages still come back to the queue after closing the app. Can you help with what is wrong here.

Code:
        private IConnection mqConnection = null;
        private ISession session = null;

   private void GetConnection()
        {
            XMSFactoryFactory factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

            IConnectionFactory connectionFactory = factoryFactory.CreateConnectionFactory();

            connectionFactory.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, _connectionNameList);
            connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, _channel);
            connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, _queueManager);
            connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
            connectionFactory.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_OPTIONS, XMSC.WMQ_CLIENT_RECONNECT);
            connectionFactory.SetIntProperty(XMSC.WMQ_SHARE_CONV_ALLOWED, 1);

            mqConnection = connectionFactory.CreateConnection();
            mqConnection.ExceptionListener = new ExceptionListener(OnException);           

            // Create session for request queue
            session = mqConnection.CreateSession(true, AcknowledgeMode.AutoAcknowledge);
            IDestination queue = session.CreateQueue(ReqMQName);

            // Create the consumer and register an async message listener
            IMessageConsumer consumer = session.CreateConsumer(queue);
            consumer.MessageListener = new MessageListener(OnMessage);

            mqConnection.Start();
        }

   private void OnMessage(IMessage msg)
        {
            IBytesMessage bytesmsg;
            using (CommittableTransaction transScope = new CommittableTransaction())
            {
                try
                {
                    CommittableTransaction.Current = transScope;
                    bytesmsg = (IBytesMessage)msg;
                    //Logic here
                    transScope.Commit();
                }
                catch (TransactionException tex)
                {
                    transScope.Rollback();
                    //Error handling
                }
                catch (Exception ex)
                {
                    transScope.Rollback();
                    //Error handling
                }
                CommittableTransaction.Current = null;
            }
        }

   private void OnException(Exception ex)
        {
            //Display error
        }
Back to top
View user's profile Send private message
zpat
PostPosted: Mon Jul 10, 2017 1:35 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5849
Location: UK

Remember to close the queues/topics handles and disconnect from the queue manager in an orderly fashion.

Don't just allow the application to terminate - as MQ will assume your application has failed and it will rollback the transaction.

Or you can explicitly issue a commit and then close the handles.
_________________
Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error.
Back to top
View user's profile Send private message
drajani
PostPosted: Mon Jul 10, 2017 10:21 pm    Post subject: Reply with quote

Newbie

Joined: 21 Dec 2016
Posts: 9

Thanks zpat. I just kept the sample code flow. All key aspects you mentioned are taken care of.

Still looking for help with what else is missing in xms transaction handling.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jul 11, 2017 1:17 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

drajani wrote:
Thanks zpat. I just kept the sample code flow. All key aspects you mentioned are taken care of.

Still looking for help with what else is missing in xms transaction handling.

If you're running XMS you should be using JMS style transaction handling:
Make your XMS Session transacted by creating it with (true, AUTO_ACKNOWLEDGE), or createJMSContext(JMSContext.SessionTransacted);
Remember to commit the session at the end of each transaction:
Code:
isesssion.commit(); //JMS 1.X
// or
jmscontext.commit(); //JMS 2.0

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
drajani
PostPosted: Tue Jul 11, 2017 3:32 am    Post subject: Reply with quote

Newbie

Joined: 21 Dec 2016
Posts: 9

My session is already created with true and auto acknowledge.

Code:
session = mqConnection.CreateSession(true, AcknowledgeMode.AutoAcknowledge);


After some research found below link that says "The XA transactions are not supported in asynchronous consumers."
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.msc.doc/xms_managed_mq.htm

I am thinking this may be the root cause. Would be happy to know if otherwise.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Transaction handling
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.