0 Replies Latest reply on Aug 25, 2010 11:26 AM by maor Lo

    dot net client

    maor Lo Newbie

      Hi

      I use Hornetq push server that sending Stomp data.

      I write a C# client I use

      Apache.NMS.Stomp  ( version 1.3 .net 3.5)

       

       

      the client server some time work and sometimes not working.

      also the clients work for some Seconds/minutes and after that stop working for some Seconds/ minutes and then return to work and again and again stop and return to work.

       

       

       

       

      these is the code I use:

       

      public class TopicSubscriber

          {

            

              private readonly ISession session;

              private readonly ITopic topic;

              private readonly string destination;

              private bool disposed=false;

       

       

              public TopicSubscriber(ISession _session, string _destination)

              {

                  try

                  {

                      this.session = _session;

                      this.destination = _destination;

                     // topic = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(destination);  //tcp      

                      topic = new Apache.NMS.Stomp.Commands.Topic(destination);//stomp

                     

                  }

                  catch (Exception eee)

                  {

                      throw eee;

                  }

              }

       

              public event MessageReceivedDelegate OnMessageReceived;

              public IMessageConsumer Consumer { get; set; }

              public string ConsumerId { get; set; }

              public IDestination mydest { get; set; }

       

              public void Start(string _consumerId)

              {

                  try

                  {

                      // ConsumerId= consumerId

                      Consumer = session.CreateConsumer(Destination.CreateDestination(1, destination));

                      Consumer.Listener += (messsage =>

                          {

                              var textMessage = messsage as ITextMessage;

                              if (textMessage == null) throw new InvalidCastException(GetType().Name);

                              if (OnMessageReceived != null)

                              {

                                  OnMessageReceived(textMessage.Text);

                              }

       

                          });

                  }

                  catch (Exception eee)

                  {

                      throw eee;

                  }

              }

       

              public void Dispose()

              {

                  try

                  {

                      if (disposed) return;

                      if (Consumer != null)

                      {

                          Consumer.Close();

                          Consumer.Dispose();

                      }

                      disposed = true;

                  }

                  catch (Exception eee)

                  {

                      throw eee;

                  }

              }

          }

      }

       

       

      On the main page I use these code

      private IConnection connection;

              private IConnectionFactory connectionFactory;

       

              private TopicSubscriber subscriber1;

         

              private ISession session;

       

       

        public void StartTestQuotes1()

              {

                  try

                  {

                      CLIENT_ID = "clientId" + System.DateTime.Now.Ticks;

                      CONSUMER_ID = "CONSUMER_ID" + System.DateTime.Now.Ticks;           

                      connectionFactory = new ConnectionFactory(BROKER, CLIENT_ID);

       

                      connection = connectionFactory.CreateConnection();              

                      connection.Start();

                      connection.ExceptionListener += new ExceptionListener(OnExceptionListener);

                      session = connection.CreateSession();

       

        subscriber1 = new TopicSubscriber(session, TOPIC_NAME2);

                      subscriber1.Start("A"  + System.DateTime.Now.Ticks.ToString());

                      subscriber1.OnMessageReceived += new MessageReceivedDelegate(subscriber_OnMessageReceived);

       

      }

       

      Someone have any  idea why this working sometime and sometime it is not working.

      Can someone  give me simple C# or dot net client.

       

      Best regards