You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Michel Van Hoof (JIRA)" <ji...@apache.org> on 2010/08/23 16:34:49 UTC

[jira] Commented: (AMQNET-275) Session throws not in transaction error when no message has been received during transactional session

    [ https://issues.apache.org/activemq/browse/AMQNET-275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=61336#action_61336 ] 

Michel Van Hoof commented on AMQNET-275:
----------------------------------------

Actually, apparently, the session is transacted simply by setting the acknowledgementmode to transactional. Tha transactionContext however, only considers himself transacted when a message is actually received and the transactionid is set.

if you uncomment the line // Assert.IsTrue(testsession.TransactionContext.InTransaction);


you will see that session says it is transacted while transactionContext Says it isn't.

I did some simple testing in the session where is do an extra check on commit and rollback as such:

{code} 
public void Commit()
        {
            if(!Transacted)
            {
                throw new InvalidOperationException(
                        "You cannot perform a Commit() on a non-transacted session. Acknowlegement mode is: "
                        + this.AcknowledgementMode);
            }
            //HACK: transaction IS in transaction while transactioncontext isn't. Exception is thrown.
            if (this.transactionContext.InTransaction)
            {
                this.TransactionContext.Commit();
            }
        }
{code}

and same here:

{code}
 public void Rollback()
        {
            if(!Transacted)
            {
                throw new InvalidOperationException(
                        "You cannot perform a Commit() on a non-transacted session. Acknowlegement mode is: "
                        + this.AcknowledgementMode);
            }
            //HACK: transaction IS in transaction while transactioncontext isn't. Exception is thrown.
            if (this.transactionContext.InTransaction)
            {
                this.TransactionContext.Rollback();
            }
        }
{code}

I will attach the patc h for this. I am not really happy with this quick & dirty way ( hence the "hack" tag) but i really need a working version to update masstransit from nms 1.0.0 to 1.3.x. could this pretty please be released as an update to 1.3.0 as soon as possible ? :s

> Session throws not in transaction error when no message has been received during transactional session
> ------------------------------------------------------------------------------------------------------
>
>                 Key: AMQNET-275
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-275
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ
>    Affects Versions: 1.3.0
>         Environment: Any
>            Reporter: Michel Van Hoof
>            Assignee: Jim Gomes
>            Priority: Critical
>
> When trying to upgrade the NMS libraries in the MassTransit, i noticed i started receiving exceptions:
> {code}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
> {code}
> 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:
> {code}
> [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");
>         }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.