5

Can I use TransactionScope when access IBM MQ with XMS? I have this test code:

               var context =
               new InitialContext(
                   new Hashtable
                   {
                        { "XMSC_IC_URL", "XXX" },
                        { "XMSC_IC_SECURITY_AUTHENTICATION", "none" },
                   });

                var connectionFactory = (IConnectionFactory) context.Lookup("XXX");
                    connectionFactory.SetStringProperty("XMSC_WMQ_CONNECTION_MODE", "5");
                    connectionFactory.SetStringProperty("XMSC_WMQ_SSL_CIPHER_SPEC", "TRIPLE_DES_SHA_US");
                    connectionFactory.SetStringProperty("XMSC_WMQ_SSL_KEY_REPOSITORY", "XXX");

                try
                {
                    using (var scope = new TransactionScope())
                    {
                        using (var connection = connectionFactory.CreateConnection())
                        {
                            connection.Start();
                            using (var session = connection.CreateSession(true, AcknowledgeMode.SessionTransacted))
                            {
                                using (var queue = session.CreateQueue(queueName))
                                {
                                    using (var consumer = session.CreateConsumer(queue))
                                    {
                                        var message = consumer.Receive();
                                    }
                                }
                            }
                        }

                        throw new Exception();
                        scope.Complete();
                    }
                }
                catch (Exception)
                {
                }

It will commit recieving (acknowledge) of the message despite of exception. Why? If I comment all lines with scope and line with throwing of an exception then the message will remain in the queue. Why using of transaction scope acknowledge the message in the case of failture?

JoshMc
  • 10,239
  • 2
  • 19
  • 38

0 Answers0