You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by fcolle <fc...@tiscali.it> on 2011/04/14 12:02:27 UTC

c# topic publisher and listener sessions dropped

Hello!
 I'm using c# client to connect to a qpid c++ broker for publishing and
receiving messages on a topic (amq.topic).
Unfortunately, both publisher and listener sessions/connections are dropped
after 3-5 minutes. No exceptions or events are generated by the c# client,
so I wonder how to handle this situation: I want the listener to be
connected forever to its topic. I've tried to change the connection timeout,
but with no success.
 
I created a simple publisher and a listener for reproducing the problem. The
first c# console application publishes the lines read from the console,
while the second application reads from the topic.

After a few minutes the two parts are not connected anymore and using the
'list queue' command in the qpid-tool utility I see that the queue has been
destroyed.

Any help is appreciated,
bye Fcolle


/*********************************************************************************/
//-----------------------------------------------
// PUBLISHER CODE
//-----------------------------------------------

using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Threading;
using org.apache.qpid.client;
using org.apache.qpid.transport;

namespace Publisher
{

   /// 
   /// This program is one of two programs designed to be used
   /// together. These programs use the topic exchange.
   ///    
   /// Publisher:
   ///
   /// Publishes to a broker, specifying a routing key.
   ///
   /// Listener (this program):
   ///
   /// Reads from a queue on the broker using a message listener.
   ///
   /// 
   class Listener
   {
       public static int _count = 1;

       private static void Main(string[] args)
       {
           string host = PublisherSettings.Default.Host;
           int port = PublisherSettings.Default.Port;
           string virtualhost = PublisherSettings.Default.VirtualHost;
           string username = PublisherSettings.Default.Username;
           string password = PublisherSettings.Default.Password;

           Client connection = new Client();
           try
           {
               connection.Connect(host, port, virtualhost, username,
password);
               IClientSession session = connection.CreateSession(50000);

               publishMessages(session, "myqueue.1");

               noMoreMessages(session);

               
               connection.Close();
           }
           catch (Exception e)
           {
               Console.WriteLine("Error: \n" + e.StackTrace);
           }
       }

       private static void publishMessages(IClientSession session, string
routing_key)
       {
           
           string read = "";
           do
           {
               IMessage message = new Message();
               read = Console.ReadLine();
               message.ClearData();
               message.AppendData(Encoding.UTF8.GetBytes(read));
               session.MessageTransfer("amq.topic", routing_key, message);            
           } while (read != "End");
       }

       private static void noMoreMessages(IClientSession session)
       {
           IMessage message = new Message();
           // And send a syncrhonous final message to indicate termination.
           message.ClearData();
           message.AppendData(Encoding.UTF8.GetBytes("End"));
           session.MessageTransfer("amq.topic", "control", message);
           session.Sync();
       }
   }
}



/*********************************************************************************/
//-----------------------------------------------
// LISTENER CODE
//-----------------------------------------------
using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Threading;
using org.apache.qpid.client;
using org.apache.qpid.transport;

namespace Subscriber
{

   /// 
   /// This program is one of two programs designed to be used
   /// together. These programs use the topic exchange.
   ///    
   /// Publisher:
   ///
   /// Publishes to a broker, specifying a routing key.
   ///
   /// Listener (this program):
   ///
   /// Reads from a queue on the broker using a message listener.
   ///
   /// 
   class Listener
   {
       public static int _count = 1;

       private static void Main(string[] args)
       {
           string host = Settings1.Default.Host;
           int port = Settings1.Default.Port;
           string virtualhost = Settings1.Default.VirtualHost;
           string username = Settings1.Default.Username;
           string password = Settings1.Default.Password;

           Client connection = new Client();
           try
           {
               connection.Connect(host, port, virtualhost, username,
password);
               IClientSession session = connection.CreateSession(50000);

               //--------- Main body of program
--------------------------------------------

               lock (session)
               {
                   Console.WriteLine("Listening for messages ...");
                   // Create a listener                    
                   prepareQueue("myqueue", "myqueue.#", session);
                   while (_count > 0)
                   {
                       Monitor.Wait(session);
                   }
               }

              
//---------------------------------------------------------------------------

               connection.Close();
           }
           catch (Exception e)
           {
               Console.WriteLine("Error: \n" + e.StackTrace);
           }
       }

       private static void prepareQueue(string queue, string routing_key,
IClientSession session)
       {
           // Create a unique queue name for this consumer by concatenating
           // the queue name parameter with the Session ID.     
           Console.WriteLine("Declaring queue: " + queue);
           session.QueueDeclare(queue, Option.EXCLUSIVE,
Option.AUTO_DELETE);

           // Route messages to the new queue if they match the routing key.
           // Also route any messages to with the "control" routing key to
           // this queue so we know when it's time to stop. A publisher
sends
           // a message with the content "That's all, Folks!", using the
           // "control" routing key, when it is finished.

           session.ExchangeBind(queue, "amq.topic", routing_key);
           session.ExchangeBind(queue, "amq.topic", "control");

           // subscribe the listener to the queue
           IMessageListener listener = new MessageListener(session);
           session.AttachMessageListener(listener, queue);
           session.MessageSubscribe(queue);
       }
   }

   public class MessageListener : IMessageListener
   {
       private readonly IClientSession _session;
       private readonly RangeSet _range = new RangeSet();

       public MessageListener(IClientSession session)
       {
           _session = session;
       }

       public void MessageTransfer(IMessage m)
       {
           BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
           byte[] body = new byte[m.Body.Length - m.Body.Position];
           reader.Read(body, 0, body.Length);
           ASCIIEncoding enc = new ASCIIEncoding();
           string message = enc.GetString(body);
           Console.WriteLine(DateTime.Now.ToString()+"\t-\tMessage:\t[" +
message + "]\tfrom: " + m.Destination);
           // Add this message to the list of message to be acknowledged
           _range.Add(m.Id);
           if (message.Equals("End"))
           {
               Console.WriteLine("Shutting down listener for " +
m.DeliveryProperties.GetRoutingKey());
               Listener._count--;
               // Acknowledge all the received messages
               _session.MessageAccept(_range);
               lock (_session)
               {
                   Monitor.Pulse(_session);
               }
           }
       }
   }
}








--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6272182.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by Steve Huston <sh...@riverace.com>.
> Thanks Cliff.
>  I think at this point of our project it would be really 
> quite hard to change the messaging layer. Do you think it's 
> possible to substitute the Qpid c# library with other AMQP 
> 0.10 compliant libraries, like the client for RabbitMQ?

The API is probably different but, more importantly, RabbitMQ implements
AMQP 0.9, I believe. So you'd need to change the broker as well, unless
you're using the Qpid Java broker.

-Steve

--
Steve Huston, Riverace Corporation
Total Lifecycle Support for Your Networked Applications
http://www.riverace.com


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by fcolle <fc...@tiscali.it>.
Thanks Cliff.
 I think at this point of our project it would be really quite hard to
change the messaging layer. Do you think it's possible to substitute the
Qpid c# library with other AMQP 0.10 compliant libraries, like the client
for RabbitMQ?

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6283759.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by Steve Huston <sh...@riverace.com>.
Hi Stephen,

> I've read this thread with interest as I'm currently 
> evaluating QPid (via
> MRG) for use within my organisation and one of the things 
> I've been unclear on is status of the C# client and it's 
> support under Mono. Forgive me if I've misunderstood but 
> would I be correct in concluding from this discussion that 
> there are currently no reliably working or fully supported 
> .NET bindings which can run under Mono? (As the pure .NET 
> client has not been maintained and the newer ones are 
> wrappers around the native C++ and consequently unsupported by Mono?).

I believe you understand it correctly.

That said, the main reason we're in this situation is that nobody has
volunteered any time/resources to adequately maintain a C# client that
would work under Mono. If your company would like to fill this gap that
would be great.

-Steve

--
Steve Huston, Riverace Corporation
Total Lifecycle Support for Your Networked Applications
http://www.riverace.com
 


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by StephenGale <st...@gmail.com>.
Hello,

I've read this thread with interest as I'm currently evaluating QPid (via
MRG) for use within my organisation and one of the things I've been unclear
on is status of the C# client and it's support under Mono. Forgive me if
I've misunderstood but would I be correct in concluding from this discussion
that there are currently no reliably working or fully supported .NET
bindings which can run under Mono? (As the pure .NET client has not been
maintained and the newer ones are wrappers around the native C++ and
consequently unsupported by Mono?).

Regards,

Stephen

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6290573.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by Cliff Jansen <cl...@gmail.com>.
> Has anyone tried to use the dotNet client on mono?

It was originally created using mono, so that should in fact be its
most robust runtime environment.

Unfortunately, the Qpid dotnet client that you are trying to use has
not been actively maintained for a long time

It is ported from the Java client, providing an API that is not
recommended for use by Java programmers in most cases.  They would use
JMS instead.  Presumably to make the dotnet client into a going
concern, one would want to implement a Qpid Messaging API layer above
the existing code.  In addition, it would be necessary to review and
port bug fixes to the Java code (0.8 and 0.10) for the past 12 - 24
months, provide a mechanism to prevent staleness after that, and port
the AMQP 1.0 Java implementation when available.  There has been no
active maintenance of this client for some time so the likelihood of
these improvements happening appears remote.

Consequently, this client is no longer offered starting in Qpid 0.10.


By contrast, the WCF client and the .NET Binding for the C++ Messaging
client both consist of a relatively thin managed layer working with
the C++ native implementation (i.e. in "mixed-mode").  Because the
managed layer is thin, it requires less overall development effort for
a given functionality.  The C++ native component does most of the AMQP
and Messaging API heavy lifting.   Bug fixes to the C++ code base
automatically propagate to the mixed-mode client.  Staleness in the
supporting C++ base code is not an issue since it is always current
and not a snapshot in time.

The downside to this approach is that the managed to native interface
is not supported in all .NET runtimes.  Mono does not have this
capability.  Neither does Windows Phone 7 at the moment (but it may in
the future).

If you are able to contribute to Qpid and have ideas for providing a
more platform independent .NET implementation, we would welcome your
thoughts on the Qpid Developer List.

Cliff


On Fri, Apr 15, 2011 at 12:32 AM, fcolle <fc...@tiscali.it> wrote:
> Thanks Cliff,
>  thanks for your suggestion. I need to use the client library on the mono
> platform under Linux. For this reason I don't think the second library fits
> my needs. I have to investigate on the support for WCF on mono, but for what
> I know only a subset of the API is working.
>
> Has anyone tried to use the dotNet client on mono?
>
>
> Anyways, It seems that the problem is solved by disabling the heartbeat
> function.
>
> --
> View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6275484.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by fcolle <fc...@tiscali.it>.
Thanks Cliff, 
 thanks for your suggestion. I need to use the client library on the mono
platform under Linux. For this reason I don't think the second library fits
my needs. I have to investigate on the support for WCF on mono, but for what
I know only a subset of the API is working. 

Has anyone tried to use the dotNet client on mono?


Anyways, It seems that the problem is solved by disabling the heartbeat
function. 

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6275484.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by Cliff Jansen <cl...@gmail.com>.
Try these two:

   http://qpid.apache.org/books/0.8/Programming-In-Apache-Qpid/html/ch05.html

   http://qpid.apache.org/books/0.8/Programming-In-Apache-Qpid/html/ch04.html

The former currently enjoys the most active support within Qpid and
gains synergy from the Qpid messaging API work in some of the other
clients.  It is the one Steve was pointing you towards.

Use the latter if you have a preference for using the WCF framework or
require distributed transactions managed by MSDTC.

Cliff


On Thu, Apr 14, 2011 at 9:38 AM, fcolle <fc...@tiscali.it> wrote:
> Today I've tried to download the svn trunk but I had problems, so I found a
> tar of the 0.10 beta version and made a fast check. It seems that the
> problem is still there, but I don't know if that package had the version you
> are refering to. Anyways, I made some modifications in the c# client source
> and disabled the heartbeat. Now it seems to work, but I wonder if this
> solution could arose problems...
> Anyways tomorrow I will go on with the tests.  Do you suggest me to use the
> latest svn sources?
> Thanks for your really PRECIOUS help!
> Bye, F
>
> --
> View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6273490.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by fcolle <fc...@tiscali.it>.
Today I've tried to download the svn trunk but I had problems, so I found a
tar of the 0.10 beta version and made a fast check. It seems that the
problem is still there, but I don't know if that package had the version you
are refering to. Anyways, I made some modifications in the c# client source
and disabled the heartbeat. Now it seems to work, but I wonder if this
solution could arose problems...
Anyways tomorrow I will go on with the tests.  Do you suggest me to use the
latest svn sources?
Thanks for your really PRECIOUS help!
Bye, F

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6273490.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by Steve Huston <sh...@riverace.com>.
> -----Original Message-----
> From: fcolle [mailto:fcolle@tiscali.it] 
> Sent: Thursday, April 14, 2011 11:15 AM
> To: users@qpid.apache.org
> Subject: Re: c# topic publisher and listener sessions dropped
> 
> 
> Many thanks!
> Anyways, this is REALLY a HUGE bug! I am planning to use Qpid 
> in a production environment, but this problem seems really a 
> pain to me...

Yes, the older .NET API has a number of problems and is being replaced.
The newer .NET binding is far better and will be maintained into the
future. If you have any problems getting that one up and running please
report back here.

Thanks,
-Steve


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by fcolle <fc...@tiscali.it>.
Many thanks!
Anyways, this is REALLY a HUGE bug! I am planning to use Qpid in a
production environment, but this problem seems really a pain to me...

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6273198.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: c# topic publisher and listener sessions dropped

Posted by Gordon Sim <gs...@redhat.com>.
On 04/14/2011 01:37 PM, fcolle wrote:
> I'm using the client for AMQP0-10 contained in the library from Qpid 0.8.
> I'll try to download the latest revision of the client from repository.
> Could you please link me to those similar posts?
> Thanks :)

http://apache-qpid-users.2158936.n2.nabble.com/Connection-close-automatically-after-4-minutes-td6088572.html

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by fcolle <fc...@tiscali.it>.
I'm using the client for AMQP0-10 contained in the library from Qpid 0.8. 
I'll try to download the latest revision of the client from repository.
Could you please link me to those similar posts?
Thanks :)

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publisher-and-listener-sessions-dropped-tp6272182p6272603.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


RE: c# topic publisher and listener sessions dropped

Posted by Steve Huston <sh...@riverace.com>.
There was some recent discussion very similar to this on the group. Are
you by any chance using the pre-0.10 .NET client? If so, I recommend you
stop, wait for Qpid 0.10 (which should be released shortly) and use the
new .NET bindings.

-Steve

--
Steve Huston, Riverace Corporation
Total Lifecycle Support for Your Networked Applications
http://www.riverace.com


> -----Original Message-----
> From: fcolle [mailto:fcolle@tiscali.it] 
> Sent: Thursday, April 14, 2011 6:02 AM
> To: users@qpid.apache.org
> Subject: c# topic publisher and listener sessions dropped
> 
> 
> Hello!
>  I'm using c# client to connect to a qpid c++ broker for 
> publishing and receiving messages on a topic (amq.topic). 
> Unfortunately, both publisher and listener 
> sessions/connections are dropped after 3-5 minutes. No 
> exceptions or events are generated by the c# client, so I 
> wonder how to handle this situation: I want the listener to 
> be connected forever to its topic. I've tried to change the 
> connection timeout, but with no success.
>  
> I created a simple publisher and a listener for reproducing 
> the problem. The first c# console application publishes the 
> lines read from the console, while the second application 
> reads from the topic.
> 
> After a few minutes the two parts are not connected anymore 
> and using the 'list queue' command in the qpid-tool utility I 
> see that the queue has been destroyed.
> 
> Any help is appreciated,
> bye Fcolle
> 
> 
> /*************************************************************
> ********************/
> //-----------------------------------------------
> // PUBLISHER CODE
> //-----------------------------------------------
> 
> using System;
> using System.Configuration;
> using System.IO;
> using System.Text;
> using System.Threading;
> using org.apache.qpid.client;
> using org.apache.qpid.transport;
> 
> namespace Publisher
> {
> 
>    /// 
>    /// This program is one of two programs designed to be used
>    /// together. These programs use the topic exchange.
>    ///    
>    /// Publisher:
>    ///
>    /// Publishes to a broker, specifying a routing key.
>    ///
>    /// Listener (this program):
>    ///
>    /// Reads from a queue on the broker using a message listener.
>    ///
>    /// 
>    class Listener
>    {
>        public static int _count = 1;
> 
>        private static void Main(string[] args)
>        {
>            string host = PublisherSettings.Default.Host;
>            int port = PublisherSettings.Default.Port;
>            string virtualhost = PublisherSettings.Default.VirtualHost;
>            string username = PublisherSettings.Default.Username;
>            string password = PublisherSettings.Default.Password;
> 
>            Client connection = new Client();
>            try
>            {
>                connection.Connect(host, port, virtualhost, 
> username, password);
>                IClientSession session = 
> connection.CreateSession(50000);
> 
>                publishMessages(session, "myqueue.1");
> 
>                noMoreMessages(session);
> 
>                
>                connection.Close();
>            }
>            catch (Exception e)
>            {
>                Console.WriteLine("Error: \n" + e.StackTrace);
>            }
>        }
> 
>        private static void publishMessages(IClientSession 
> session, string
> routing_key)
>        {
>            
>            string read = "";
>            do
>            {
>                IMessage message = new Message();
>                read = Console.ReadLine();
>                message.ClearData();
>                message.AppendData(Encoding.UTF8.GetBytes(read));
>                session.MessageTransfer("amq.topic", 
> routing_key, message);            
>            } while (read != "End");
>        }
> 
>        private static void noMoreMessages(IClientSession session)
>        {
>            IMessage message = new Message();
>            // And send a syncrhonous final message to 
> indicate termination.
>            message.ClearData();
>            message.AppendData(Encoding.UTF8.GetBytes("End"));
>            session.MessageTransfer("amq.topic", "control", message);
>            session.Sync();
>        }
>    }
> }
> 
> 
> 
> /*************************************************************
> ********************/
> //-----------------------------------------------
> // LISTENER CODE
> //-----------------------------------------------
> using System;
> using System.Configuration;
> using System.IO;
> using System.Text;
> using System.Threading;
> using org.apache.qpid.client;
> using org.apache.qpid.transport;
> 
> namespace Subscriber
> {
> 
>    /// 
>    /// This program is one of two programs designed to be used
>    /// together. These programs use the topic exchange.
>    ///    
>    /// Publisher:
>    ///
>    /// Publishes to a broker, specifying a routing key.
>    ///
>    /// Listener (this program):
>    ///
>    /// Reads from a queue on the broker using a message listener.
>    ///
>    /// 
>    class Listener
>    {
>        public static int _count = 1;
> 
>        private static void Main(string[] args)
>        {
>            string host = Settings1.Default.Host;
>            int port = Settings1.Default.Port;
>            string virtualhost = Settings1.Default.VirtualHost;
>            string username = Settings1.Default.Username;
>            string password = Settings1.Default.Password;
> 
>            Client connection = new Client();
>            try
>            {
>                connection.Connect(host, port, virtualhost, 
> username, password);
>                IClientSession session = 
> connection.CreateSession(50000);
> 
>                //--------- Main body of program
> --------------------------------------------
> 
>                lock (session)
>                {
>                    Console.WriteLine("Listening for messages ...");
>                    // Create a listener                    
>                    prepareQueue("myqueue", "myqueue.#", session);
>                    while (_count > 0)
>                    {
>                        Monitor.Wait(session);
>                    }
>                }
> 
>               
> //------------------------------------------------------------
> ---------------
> 
>                connection.Close();
>            }
>            catch (Exception e)
>            {
>                Console.WriteLine("Error: \n" + e.StackTrace);
>            }
>        }
> 
>        private static void prepareQueue(string queue, string 
> routing_key, IClientSession session)
>        {
>            // Create a unique queue name for this consumer by 
> concatenating
>            // the queue name parameter with the Session ID.     
>            Console.WriteLine("Declaring queue: " + queue);
>            session.QueueDeclare(queue, Option.EXCLUSIVE, 
> Option.AUTO_DELETE);
> 
>            // Route messages to the new queue if they match 
> the routing key.
>            // Also route any messages to with the "control" 
> routing key to
>            // this queue so we know when it's time to stop. A 
> publisher sends
>            // a message with the content "That's all, 
> Folks!", using the
>            // "control" routing key, when it is finished.
> 
>            session.ExchangeBind(queue, "amq.topic", routing_key);
>            session.ExchangeBind(queue, "amq.topic", "control");
> 
>            // subscribe the listener to the queue
>            IMessageListener listener = new MessageListener(session);
>            session.AttachMessageListener(listener, queue);
>            session.MessageSubscribe(queue);
>        }
>    }
> 
>    public class MessageListener : IMessageListener
>    {
>        private readonly IClientSession _session;
>        private readonly RangeSet _range = new RangeSet();
> 
>        public MessageListener(IClientSession session)
>        {
>            _session = session;
>        }
> 
>        public void MessageTransfer(IMessage m)
>        {
>            BinaryReader reader = new BinaryReader(m.Body, 
> Encoding.UTF8);
>            byte[] body = new byte[m.Body.Length - m.Body.Position];
>            reader.Read(body, 0, body.Length);
>            ASCIIEncoding enc = new ASCIIEncoding();
>            string message = enc.GetString(body);
>            
> Console.WriteLine(DateTime.Now.ToString()+"\t-\tMessage:\t[" 
> + message + "]\tfrom: " + m.Destination);
>            // Add this message to the list of message to be 
> acknowledged
>            _range.Add(m.Id);
>            if (message.Equals("End"))
>            {
>                Console.WriteLine("Shutting down listener for 
> " + m.DeliveryProperties.GetRoutingKey());
>                Listener._count--;
>                // Acknowledge all the received messages
>                _session.MessageAccept(_range);
>                lock (_session)
>                {
>                    Monitor.Pulse(_session);
>                }
>            }
>        }
>    }
> }
> 
> 
> 
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://apache-qpid-users.2158936.n2.nabble.com/c-topic-publish
> er-and-listener-sessions-dropped-tp6272182p6272182.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
> 
> 


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org