Reputation: 87
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.
Upvotes: 0
Views: 1607
Reputation: 18356
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.
Upvotes: 2