Description
When trying to upgrade the NMS libraries in the MassTransit, i noticed i started receiving exceptions:
Apache.NMS.NMSException: Invliad State: Not Currently in a Transaction at Apache.NMS.ActiveMQ.TransactionContext.Commit() at Apache.NMS.ActiveMQ.Session.Commit() at MassTransit.Transports.Nms.NmsTransport.Receive(Func`2 receiver, TimeSpan timeout) in D:\Development.OSS\Masstransit\src\Transports\MassTransit.Transports.Nms\NmsTransport.cs:line 112 at MassTransit.Transports.StreamEndpoint.Receive(Func`2 receiver, TimeSpan timeout) in D:\Development.OSS\Masstransit\src\MassTransit\Transports\StreamEndpoint.cs:line 65 at MassTransit.Internal.ServiceBusReceiveContext.ReceiveFromEndpoint() in D:\Development.OSS\Masstransit\src\MassTransit\Internal\ServiceBusReceiveContext.cs:line 62
Looking further into this, i noticed that these only occur when trying to consume a message from the queue in transactional acknowledgement mode when NO mesasge is received in the timespan configured.
A simple test i did show this:
[Test] public void session_can_be_commited_without_receiving_message() { using (Session testsession = connection.CreateSession(AcknowledgementMode.Transactional) as Session) { Assert.IsTrue(testsession.Transacted); // Assert.IsTrue(testsession.TransactionContext.InTransaction); using (IMessageConsumer oTestConsumer = testsession.CreateConsumer(new ActiveMQ.Commands.ActiveMQQueue(destinationName))) { IMessage oreceived = oTestConsumer.Receive(new TimeSpan(0, 0, 0, 0, 100)); Assert.IsNull(oreceived); testsession.Commit(); } } Assert.Pass("When getting here. It is ok"); }