0

I am trying to receive/send message from queue of activeMQ using stomp protocol using c#. As I don't know much about activemq and stomp. So I'm searching for some proper document or sample code by which I can learn step by step.

  static void Main(string[] args)
    {
        Apache.NMS.Stomp.ConnectionFactory factory  = new Apache.NMS.Stomp.ConnectionFactory(new Uri("stomp:tcp://localhost:61613"));
        IConnection connection = factory.CreateConnection();
        ISession session = connection.CreateSession();
        IDestination destination = session.GetDestination("/queue/notification");
        IMessageConsumer consumer = session.CreateConsumer(destination);
        connection.Start();
        consumer.Listener += new MessageListener(OnMessage);
        Console.WriteLine("Consumer started, waiting for messages... (Press ENTER to stop.)");
        Console.ReadLine();
        connection.Close();
    }
    private static void OnMessage(IMessage message)
    { 
        try
        { 
            Console.WriteLine("Median-Server (.NET): Message received"); 
            ITextMessage msg = (ITextMessage)message; 
            message.Acknowledge();
            Console.WriteLine(msg.Text);
        } 
        catch (Exception ex)
        { 
            Console.WriteLine(ex.Message);
            Console.WriteLine("---");
            Console.WriteLine(ex.InnerException);
            Console.WriteLine("---"); 
            Console.WriteLine(ex.InnerException.Message);
        }
    }
}

} I have tried this. Is it a correct way to make stomp connection.

Manoj G
  • 87
  • 14
  • The sample code seems fine, you should really try and ask a question that's more targeted. Does your code not work? – Tim Bish Jan 21 '13 at 20:04
  • Yes it's working when i am adding tcp in uri. When I am passing "stomp://localhost:61613" only then error pop's out.Even though I have changed activemq.xml file. – Manoj G Jan 22 '13 at 05:35
  • error is "Invalid URI: The hostname could not be parsed" – Manoj G Jan 22 '13 at 10:19
  • That's because stomp:// is not a valid transport protocol. Use tcp:// for TCP connections and ssl:// for SSL connections. – Tim Bish Jan 22 '13 at 11:26
  • But I want to use stomp protocol then still i have to use tcp. – Manoj G Jan 22 '13 at 11:36

1 Answers1

2

There are client libraries for STOMP in various languages, for .NET there's the Apache.NMS.Stomp library which puts a JMS type facade around STOMP semantics. If you want to get more technical and learn what the STOMP protocol really is, then the STOMP spec is quite clear and easy to understand. And of course ActiveMQ's own site has some documentation on its STOMP support that you should read. Some web searching will also quickly net you some nice blog posts on using the NMS.Stomp library to interact with ActiveMQ.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42