I'm not sure how this worked in Java, but the way I read the code, the
behavior you are describing is not surprising.  There is nothing in the
run() function to keep that thread alive after it has received one message.
I would expect it to terminate after receiving the message.  To keep it
alive and processing more messages, you will need some kind of looping
mechanism.

On Wed, Jan 27, 2010 at 5:01 PM, slyfox <bobby.richa...@gmail.com> wrote:

>
> Working fine in java but switched a client over to C#, producer worked,
> consumer works, just dies after 1 message:
>
> ##############################
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using System.Threading;
> using Apache.NMS;
> using Apache.NMS.ActiveMQ;
> using Apache.NMS.Util;
>
> namespace QuoteProvider
> {
>    public class JMSQuoteProvider : IJMSQuoteSource
>    {
>        protected static AutoResetEvent semaphore = new
> AutoResetEvent(false);
>        protected static ITextMessage message = null;
>        protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);
>
>        public event Action<IncomingQuote> QuoteArrived;
>
>        public JMSQuoteProvider()
>        {
>            Thread JMSQuotes = new Thread(new ThreadStart(run));
>            JMSQuotes.IsBackground = true;
>            JMSQuotes.Priority = ThreadPriority.Normal;
>            JMSQuotes.Start();
>        }
>
>        private void run()
>        {
>            Uri connecturi = new
> Uri("activemq:tcp://127.0.0.1:61616?consumer.dispatchAsync=true");
>            IConnectionFactory factory = new
> NMSConnectionFactory(connecturi);
>            using (IConnection connection = factory.CreateConnection())
>            using (ISession session = connection.CreateSession())
>            {
>                IDestination destination = session.GetTopic("PX.UPDATE");
>
>                using (IMessageConsumer consumer =
> session.CreateConsumer(destination))
>                {
>                    connection.Start();
>
>                    consumer.Listener += new MessageListener(OnMessage);
>
>                    semaphore.WaitOne();
>                    if (message != null)
>                    {
>                        crack(message.Text.ToString());
>                    }
>
>                }
>            }
>        }
>
>        private void crack(String msg)
>        {
>            // crack logic //
>
>            IncomingQuote tempQuote = new IncomingQuote(symbol, bid, ask,
> stamp);
>            QuoteArrived(tempQuote);
>        }
>
>        protected static void OnMessage(IMessage receivedMsg)
>        {
>            message = receivedMsg as ITextMessage;
>            semaphore.Set();
>        }
>
>        #region IJMSQuoteSource Members
>
>        protected virtual void OnQuoteArrived(IncomingQuote quote)
>        {
>            if (QuoteArrived != null)
>                QuoteArrived(quote);
>        }
>
>        #endregion
>
>    }
> }
>
>
> --
> View this message in context:
> http://old.nabble.com/My-NMS-topic-consumer-dies-after-1-message-tp27349478p27349478.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>

Reply via email to