You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Marco Crivellaro (JIRA)" <ji...@apache.org> on 2009/03/30 10:57:42 UTC

[jira] Created: (AMQNET-154) Closing a consumer does not unblock receive call

Closing a consumer does not unblock receive call
------------------------------------------------

                 Key: AMQNET-154
                 URL: https://issues.apache.org/activemq/browse/AMQNET-154
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: ActiveMQ Client
    Affects Versions: 1.1
         Environment: windows xp profesional
            Reporter: Marco Crivellaro
            Assignee: Jim Gomes


calling the close method of a cosumer while this has a pending receive call blocked does not unblock returning null.

sample code (C#)

using System;
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using System.Threading;

namespace simpleConsumer
{
    class Program
    {

        private static bool _exit = false;
        private static IMessageConsumer _consumer;
       

        static void Main(string[] args)
        {            
            Apache.NMS.ActiveMQ.ConnectionFactory connectionFactory = new ConnectionFactory("tcp://172.18.141.102:61616");
            Apache.NMS.IConnection connection = connectionFactory.CreateConnection();
            connection.Start();
            Apache.NMS.ISession session = connection.CreateSession();
            Apache.NMS.ActiveMQ.Commands.ActiveMQTopic inputTopic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("test.topic");
            _consumer = session.CreateConsumer(inputTopic, "2>1");
            Thread _receiveThread = new Thread(_receiveLoop);
            _receiveThread.Start();
            while (!_exit)
            {
                String command = Console.ReadLine();
                if (command == "exit")
                {
                    _exit = true;
                }
            }
            _consumer.Close();
            _receiveThread.Join();
        }

        private static void _receiveLoop()
        {
            while (!_exit)
            {
                Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)_consumer.Receive();
                Console.WriteLine(message.Content.ToString() +  " [looping...]");
            }
        }
    }
}

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


[jira] Resolved: (AMQNET-154) Closing a consumer does not unblock receive call

Posted by "Timothy Bish (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Timothy Bish resolved AMQNET-154.
---------------------------------

    Resolution: Fixed

Fixed in Trunk, added a new unit test to confirm that the code behaves as expected now.  

> Closing a consumer does not unblock receive call
> ------------------------------------------------
>
>                 Key: AMQNET-154
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-154
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>    Affects Versions: 1.1
>         Environment: windows xp profesional
>            Reporter: Marco Crivellaro
>            Assignee: Jim Gomes
>             Fix For: 1.1
>
>
> calling the close method of a cosumer while this has a pending receive call blocked does not unblock returning null.
> sample code (C#)
> using System;
> using Apache.NMS;
> using Apache.NMS.ActiveMQ;
> using System.Threading;
> namespace simpleConsumer
> {
>     class Program
>     {
>         private static bool _exit = false;
>         private static IMessageConsumer _consumer;
>        
>         static void Main(string[] args)
>         {            
>             Apache.NMS.ActiveMQ.ConnectionFactory connectionFactory = new ConnectionFactory("tcp://172.18.141.102:61616");
>             Apache.NMS.IConnection connection = connectionFactory.CreateConnection();
>             connection.Start();
>             Apache.NMS.ISession session = connection.CreateSession();
>             Apache.NMS.ActiveMQ.Commands.ActiveMQTopic inputTopic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("test.topic");
>             _consumer = session.CreateConsumer(inputTopic, "2>1");
>             Thread _receiveThread = new Thread(_receiveLoop);
>             _receiveThread.Start();
>             while (!_exit)
>             {
>                 String command = Console.ReadLine();
>                 if (command == "exit")
>                 {
>                     _exit = true;
>                 }
>             }
>             _consumer.Close();
>             _receiveThread.Join();
>         }
>         private static void _receiveLoop()
>         {
>             while (!_exit)
>             {
>                 Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)_consumer.Receive();
>                 Console.WriteLine(message.Content.ToString() +  " [looping...]");
>             }
>         }
>     }
> }

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


[jira] Updated: (AMQNET-154) Closing a consumer does not unblock receive call

Posted by "Timothy Bish (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Timothy Bish updated AMQNET-154:
--------------------------------

    Fix Version/s: 1.1

> Closing a consumer does not unblock receive call
> ------------------------------------------------
>
>                 Key: AMQNET-154
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-154
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>    Affects Versions: 1.1
>         Environment: windows xp profesional
>            Reporter: Marco Crivellaro
>            Assignee: Jim Gomes
>             Fix For: 1.1
>
>
> calling the close method of a cosumer while this has a pending receive call blocked does not unblock returning null.
> sample code (C#)
> using System;
> using Apache.NMS;
> using Apache.NMS.ActiveMQ;
> using System.Threading;
> namespace simpleConsumer
> {
>     class Program
>     {
>         private static bool _exit = false;
>         private static IMessageConsumer _consumer;
>        
>         static void Main(string[] args)
>         {            
>             Apache.NMS.ActiveMQ.ConnectionFactory connectionFactory = new ConnectionFactory("tcp://172.18.141.102:61616");
>             Apache.NMS.IConnection connection = connectionFactory.CreateConnection();
>             connection.Start();
>             Apache.NMS.ISession session = connection.CreateSession();
>             Apache.NMS.ActiveMQ.Commands.ActiveMQTopic inputTopic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("test.topic");
>             _consumer = session.CreateConsumer(inputTopic, "2>1");
>             Thread _receiveThread = new Thread(_receiveLoop);
>             _receiveThread.Start();
>             while (!_exit)
>             {
>                 String command = Console.ReadLine();
>                 if (command == "exit")
>                 {
>                     _exit = true;
>                 }
>             }
>             _consumer.Close();
>             _receiveThread.Join();
>         }
>         private static void _receiveLoop()
>         {
>             while (!_exit)
>             {
>                 Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)_consumer.Receive();
>                 Console.WriteLine(message.Content.ToString() +  " [looping...]");
>             }
>         }
>     }
> }

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


[jira] Assigned: (AMQNET-154) Closing a consumer does not unblock receive call

Posted by "Jim Gomes (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Gomes reassigned AMQNET-154:
--------------------------------

    Assignee: Timothy Bish  (was: Jim Gomes)

> Closing a consumer does not unblock receive call
> ------------------------------------------------
>
>                 Key: AMQNET-154
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-154
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>    Affects Versions: 1.1
>         Environment: windows xp profesional
>            Reporter: Marco Crivellaro
>            Assignee: Timothy Bish
>             Fix For: 1.1
>
>
> calling the close method of a cosumer while this has a pending receive call blocked does not unblock returning null.
> sample code (C#)
> using System;
> using Apache.NMS;
> using Apache.NMS.ActiveMQ;
> using System.Threading;
> namespace simpleConsumer
> {
>     class Program
>     {
>         private static bool _exit = false;
>         private static IMessageConsumer _consumer;
>        
>         static void Main(string[] args)
>         {            
>             Apache.NMS.ActiveMQ.ConnectionFactory connectionFactory = new ConnectionFactory("tcp://172.18.141.102:61616");
>             Apache.NMS.IConnection connection = connectionFactory.CreateConnection();
>             connection.Start();
>             Apache.NMS.ISession session = connection.CreateSession();
>             Apache.NMS.ActiveMQ.Commands.ActiveMQTopic inputTopic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("test.topic");
>             _consumer = session.CreateConsumer(inputTopic, "2>1");
>             Thread _receiveThread = new Thread(_receiveLoop);
>             _receiveThread.Start();
>             while (!_exit)
>             {
>                 String command = Console.ReadLine();
>                 if (command == "exit")
>                 {
>                     _exit = true;
>                 }
>             }
>             _consumer.Close();
>             _receiveThread.Join();
>         }
>         private static void _receiveLoop()
>         {
>             while (!_exit)
>             {
>                 Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)_consumer.Receive();
>                 Console.WriteLine(message.Content.ToString() +  " [looping...]");
>             }
>         }
>     }
> }

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


[jira] Commented: (AMQNET-154) Closing a consumer does not unblock receive call

Posted by "Timothy Bish (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=50903#action_50903 ] 

Timothy Bish commented on AMQNET-154:
-------------------------------------

This looks to be a simple bug in the Dispatcher used by consumers, the close method looks as follows:

{noformat}
		public void Close()
		{
			lock (semaphore)
			{
				m_bClosed = true;
				queue.Clear();
				if(m_bAsyncDelivery)
				{
					messageReceivedEventHandle.Set();
				}
			}
		}
{noformat}

I think the if statement there should be:

{noformat}
		if(!m_bAsyncDelivery)
		{
			messageReceivedEventHandle.Set();
		}
{noformat}

Since the async delivery case only needs to trigger an event when a message arrives whereas the sync delivery case needs to trigger a wakeup on close for any waiting consumers.

> Closing a consumer does not unblock receive call
> ------------------------------------------------
>
>                 Key: AMQNET-154
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-154
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>    Affects Versions: 1.1
>         Environment: windows xp profesional
>            Reporter: Marco Crivellaro
>            Assignee: Jim Gomes
>
> calling the close method of a cosumer while this has a pending receive call blocked does not unblock returning null.
> sample code (C#)
> using System;
> using Apache.NMS;
> using Apache.NMS.ActiveMQ;
> using System.Threading;
> namespace simpleConsumer
> {
>     class Program
>     {
>         private static bool _exit = false;
>         private static IMessageConsumer _consumer;
>        
>         static void Main(string[] args)
>         {            
>             Apache.NMS.ActiveMQ.ConnectionFactory connectionFactory = new ConnectionFactory("tcp://172.18.141.102:61616");
>             Apache.NMS.IConnection connection = connectionFactory.CreateConnection();
>             connection.Start();
>             Apache.NMS.ISession session = connection.CreateSession();
>             Apache.NMS.ActiveMQ.Commands.ActiveMQTopic inputTopic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("test.topic");
>             _consumer = session.CreateConsumer(inputTopic, "2>1");
>             Thread _receiveThread = new Thread(_receiveLoop);
>             _receiveThread.Start();
>             while (!_exit)
>             {
>                 String command = Console.ReadLine();
>                 if (command == "exit")
>                 {
>                     _exit = true;
>                 }
>             }
>             _consumer.Close();
>             _receiveThread.Join();
>         }
>         private static void _receiveLoop()
>         {
>             while (!_exit)
>             {
>                 Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)_consumer.Receive();
>                 Console.WriteLine(message.Content.ToString() +  " [looping...]");
>             }
>         }
>     }
> }

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