0 Replies Latest reply on Jul 6, 2015 9:21 AM by nidheesh kuvil

    Unable to get listener - HornetQ with .net

    nidheesh kuvil Newbie

      Hi all,

      We  are doing some POC for Connecting HornetQ with .net platform, and we are able to send messages to the Queue. But currently we are not receiving the message back from queue. Can any one help us with some sample codes ..

       

      public partial class MainWindow : Window

          {

              private static ISession session;

              protected static AutoResetEvent semaphore = new AutoResetEvent(false);

              protected static ITextMessage message = null;

              protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);

       

       

              public MainWindow()

              {

                  InitializeComponent();

              }

       

       

              private void Button_Click_1(object sender, RoutedEventArgs e)

              {

                  try

                  {

                      Uri connectUri = new Uri("stomp:tcp://localhost:5455");

                      IConnectionFactory factory = new NMSConnectionFactory(connectUri);

                      using (IConnection connection = factory.CreateConnection())

                      using (session = connection.CreateSession())

                      {

                          IDestination destination = session.GetDestination("queue://NewQueue", DestinationType.Queue);

                          IMessageConsumer consumer = session.CreateConsumer(destination);

                          connection.ExceptionListener +=connection_ExceptionListener;

                           consumer.Listener += OnMessage;

                          ITextMessage text = session.CreateTextMessage(txtMessage.Text);

                          text.NMSCorrelationID = "1";

                          text.NMSDeliveryMode = MsgDeliveryMode.Persistent;

                          text.NMSDestination = destination;

                          text.NMSPriority = MsgPriority.High;

                          connection.Start();

                          IMessageProducer producer = session.CreateProducer(destination);

                          producer.Send(text);

                          

                          semaphore.WaitOne((int)receiveTimeout.TotalMilliseconds, true);

                      }

                  }

                  catch (Exception ex)

                  {

                      MessageBox.Show(ex.Message);

                  }

              }

              private void connection_ExceptionListener(Exception exception)

              {

                  MessageBox.Show(exception.Message);

              }

              

              protected static void OnMessage(IMessage receivedMsg)

              {

                  message = receivedMsg as ITextMessage;

                  semaphore.Set();

              }

          }

       

      and

       

       

       

        <queue name="NewQueue1">

          <entry name="/queue/NewQueue1"/>

        </queue>

       

      Regards,

      Nidheesh