You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Denis Abramov (JIRA)" <ji...@apache.org> on 2006/08/07 17:46:23 UTC

[jira] Created: (AMQ-865) C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe

C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe
------------------------------------------------------------------------------------

                 Key: AMQ-865
                 URL: https://issues.apache.org/activemq/browse/AMQ-865
             Project: ActiveMQ
          Issue Type: Bug
          Components: NMS (C# client)
         Environment: Windows XP, VS 2005, ActiveMQ 4.0.1
            Reporter: Denis Abramov


 Easiest way to reproduce the bug would be to start the consumer using the following code and then AFTER the consumer starts, start some producer (either java or C#) and you will notice that the consumer will not get any messages (through trial and error I found that calling Receive() on the consumer at least once will make you lose a message but the listener will kick back in): 

using System; 
using ActiveMQ; 
using ActiveMQ.Commands; 
using NMS; 

namespace JMSClient 
{ 
    /// <summary> 
    /// Summary description for Class1. 
    /// </summary> 
    class Class1 
    { 
        /// <summary> 
        /// The main entry point for the application. 
        /// </summary> 
        [STAThread] 
        static void Main(string[] args) 
        { 
            IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616?jms.useAsyncSend=true")); 
            using (IConnection connection = factory.CreateConnection()) 
            { 
                Console.WriteLine("Created a connection!"); 

                ISession session = connection.CreateSession(); 
                IDestination destination = session.GetQueue("EXCEL.TESTQUEUE"); 
                Console.WriteLine("Using destination: " + destination); 

                // lets create a consumer and producer 
                IMessageConsumer consumer = session.CreateConsumer(destination); 
                consumer.Listener += new MessageListener(consumer_Listener); 

                while (true); 
            } 
        } 

        static void consumer_Listener(IMessage message) 
        { 
            if (message == null) 
            { 
                Console.WriteLine("No message received!"); 
            } 
            else 
            { 
                Console.WriteLine("Received message with text: " + ((ActiveMQTextMessage)message).Text); 
            } 
         } 
    } 
} 


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (AMQ-865) C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe

Posted by "Denis Abramov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQ-865?page=comments#action_36696 ] 
            
Denis Abramov commented on AMQ-865:
-----------------------------------

Title should be: "C# Client's Listener doesn't receive messages if you don't explicitly call Receive()"

> C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe
> ------------------------------------------------------------------------------------
>
>                 Key: AMQ-865
>                 URL: https://issues.apache.org/activemq/browse/AMQ-865
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: NMS (C# client)
>         Environment: Windows XP, VS 2005, ActiveMQ 4.0.1
>            Reporter: Denis Abramov
>
>  Easiest way to reproduce the bug would be to start the consumer using the following code and then AFTER the consumer starts, start some producer (either java or C#) and you will notice that the consumer will not get any messages (through trial and error I found that calling Receive() on the consumer at least once will make you lose a message but the listener will kick back in): 
> using System; 
> using ActiveMQ; 
> using ActiveMQ.Commands; 
> using NMS; 
> namespace JMSClient 
> { 
>     /// <summary> 
>     /// Summary description for Class1. 
>     /// </summary> 
>     class Class1 
>     { 
>         /// <summary> 
>         /// The main entry point for the application. 
>         /// </summary> 
>         [STAThread] 
>         static void Main(string[] args) 
>         { 
>             IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616?jms.useAsyncSend=true")); 
>             using (IConnection connection = factory.CreateConnection()) 
>             { 
>                 Console.WriteLine("Created a connection!"); 
>                 ISession session = connection.CreateSession(); 
>                 IDestination destination = session.GetQueue("EXCEL.TESTQUEUE"); 
>                 Console.WriteLine("Using destination: " + destination); 
>                 // lets create a consumer and producer 
>                 IMessageConsumer consumer = session.CreateConsumer(destination); 
>                 consumer.Listener += new MessageListener(consumer_Listener); 
>                 while (true); 
>             } 
>         } 
>         static void consumer_Listener(IMessage message) 
>         { 
>             if (message == null) 
>             { 
>                 Console.WriteLine("No message received!"); 
>             } 
>             else 
>             { 
>                 Console.WriteLine("Received message with text: " + ((ActiveMQTextMessage)message).Text); 
>             } 
>          } 
>     } 
> } 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (AMQ-865) C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe

Posted by "james strachan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-865?page=all ]

james strachan resolved AMQ-865.
--------------------------------

    Fix Version/s: 4.1
       Resolution: Fixed

Patch applied in SVN trunk if you want to try along with the test cases for this issue and the related AMQ-883

> C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe
> ------------------------------------------------------------------------------------
>
>                 Key: AMQ-865
>                 URL: https://issues.apache.org/activemq/browse/AMQ-865
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: NMS (C# client)
>         Environment: Windows XP, VS 2005, ActiveMQ 4.0.1
>            Reporter: Denis Abramov
>             Fix For: 4.1
>
>
>  Easiest way to reproduce the bug would be to start the consumer using the following code and then AFTER the consumer starts, start some producer (either java or C#) and you will notice that the consumer will not get any messages (through trial and error I found that calling Receive() on the consumer at least once will make you lose a message but the listener will kick back in): 
> using System; 
> using ActiveMQ; 
> using ActiveMQ.Commands; 
> using NMS; 
> namespace JMSClient 
> { 
>     /// <summary> 
>     /// Summary description for Class1. 
>     /// </summary> 
>     class Class1 
>     { 
>         /// <summary> 
>         /// The main entry point for the application. 
>         /// </summary> 
>         [STAThread] 
>         static void Main(string[] args) 
>         { 
>             IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616?jms.useAsyncSend=true")); 
>             using (IConnection connection = factory.CreateConnection()) 
>             { 
>                 Console.WriteLine("Created a connection!"); 
>                 ISession session = connection.CreateSession(); 
>                 IDestination destination = session.GetQueue("EXCEL.TESTQUEUE"); 
>                 Console.WriteLine("Using destination: " + destination); 
>                 // lets create a consumer and producer 
>                 IMessageConsumer consumer = session.CreateConsumer(destination); 
>                 consumer.Listener += new MessageListener(consumer_Listener); 
>                 while (true); 
>             } 
>         } 
>         static void consumer_Listener(IMessage message) 
>         { 
>             if (message == null) 
>             { 
>                 Console.WriteLine("No message received!"); 
>             } 
>             else 
>             { 
>                 Console.WriteLine("Received message with text: " + ((ActiveMQTextMessage)message).Text); 
>             } 
>          } 
>     } 
> } 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (AMQ-865) C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe

Posted by "james strachan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQ-865?page=comments#action_36801 ] 
            
james strachan commented on AMQ-865:
------------------------------------

Here's another test case which seems to show a similar issue...
http://www.nabble.com/Durable-topic-subscription-needs-pump-primed.-tf2117517.html#a5852831

using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;
using NUnit.Extensions;
using ActiveMQ;
using NMS;
using ActiveMQ.Commands;
using System.Threading;

namespace ActiveMQDurableTest
{
   [TestFixture]
       public class DurableTest
       {
       private static string TOPIC = "TestTopic";

       private static String URI = "tcp://localhost:61616";

       private static String CLIENT_ID = "DurableClientId";

       private static String CONSUMER_ID = "ConsumerId";

       private static ConnectionFactory FACTORY = new ConnectionFactory(new
Uri(URI));

       private int count = 0;

       public void RegisterDurableConsumer()
       {
           using (IConnection connection = FACTORY.CreateConnection())
           {
               connection.ClientId = CLIENT_ID;
               connection.Start();

               using (ISession session =
connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
               {
                   ITopic topic = session.GetTopic(TOPIC);
                   IMessageConsumer consumer =
session.CreateDurableConsumer(topic, CONSUMER_ID, "2 > 1", false);
                   consumer.Dispose();
               }

               connection.Stop();
           }
       }

       public void SendPersistentMessage()
       {
           using (IConnection connection = FACTORY.CreateConnection())
           {
               connection.Start();
               using (ISession session =
connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
               {
                   ITopic topic = session.GetTopic(TOPIC);
                   ActiveMQTextMessage message = new
ActiveMQTextMessage("Hello");
                   message.NMSPersistent = true;
                   message.Persistent = true;

                   IMessageProducer producer = session.CreateProducer();
                   producer.Send(topic, message);
                   producer.Dispose();
               }
               connection.Stop();
           }
       }

       [Test]
       public void TestMe()
       {
           count = 0;

           RegisterDurableConsumer();
           SendPersistentMessage();

           using (IConnection connection = FACTORY.CreateConnection())
           {
               connection.ClientId = CLIENT_ID;
               connection.Start();

               using (ISession session =
connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
               {
                   ITopic topic = session.GetTopic(TOPIC);
                   IMessageConsumer consumer =
session.CreateDurableConsumer(topic, CONSUMER_ID, "2 > 1", false);
                   consumer.Listener += new
MessageListener(consumer_Listener);

                   /// Don't know how else to give the system enough time.
                   ///
                   Thread.Sleep(5000);

                   Assert.AreEqual(0, count);

                   Console.WriteLine("Count = " + count);

                   SendPersistentMessage();

                   Thread.Sleep(5000);

                   Assert.AreEqual(2, count);

                   Console.WriteLine("Count = " + count);

                   consumer.Dispose();
               }

               connection.Stop();
           }
       }

       /// <summary>
       ///
       /// </summary>
       /// <param name="message"></param>
       private void consumer_Listener(IMessage message)
       {
           ++count;
- Hide quoted text -
       }
       }
}

> C# Client's Listener doesn't receive messages if you don't explicitly call Subscribe
> ------------------------------------------------------------------------------------
>
>                 Key: AMQ-865
>                 URL: https://issues.apache.org/activemq/browse/AMQ-865
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: NMS (C# client)
>         Environment: Windows XP, VS 2005, ActiveMQ 4.0.1
>            Reporter: Denis Abramov
>
>  Easiest way to reproduce the bug would be to start the consumer using the following code and then AFTER the consumer starts, start some producer (either java or C#) and you will notice that the consumer will not get any messages (through trial and error I found that calling Receive() on the consumer at least once will make you lose a message but the listener will kick back in): 
> using System; 
> using ActiveMQ; 
> using ActiveMQ.Commands; 
> using NMS; 
> namespace JMSClient 
> { 
>     /// <summary> 
>     /// Summary description for Class1. 
>     /// </summary> 
>     class Class1 
>     { 
>         /// <summary> 
>         /// The main entry point for the application. 
>         /// </summary> 
>         [STAThread] 
>         static void Main(string[] args) 
>         { 
>             IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616?jms.useAsyncSend=true")); 
>             using (IConnection connection = factory.CreateConnection()) 
>             { 
>                 Console.WriteLine("Created a connection!"); 
>                 ISession session = connection.CreateSession(); 
>                 IDestination destination = session.GetQueue("EXCEL.TESTQUEUE"); 
>                 Console.WriteLine("Using destination: " + destination); 
>                 // lets create a consumer and producer 
>                 IMessageConsumer consumer = session.CreateConsumer(destination); 
>                 consumer.Listener += new MessageListener(consumer_Listener); 
>                 while (true); 
>             } 
>         } 
>         static void consumer_Listener(IMessage message) 
>         { 
>             if (message == null) 
>             { 
>                 Console.WriteLine("No message received!"); 
>             } 
>             else 
>             { 
>                 Console.WriteLine("Received message with text: " + ((ActiveMQTextMessage)message).Text); 
>             } 
>          } 
>     } 
> } 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira