0
我正尝试使用c#使用stomp协议从activeMQ队列接收/发送消息。因为我对activemq和stomp了解不多。所以我正在寻找一些适当的文档或示例代码,我可以逐步学习。是否有任何有关通过使用C#通过STOMP协议从ActiveMQ获取消息的文档
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);
}
}
}
} 我试过这个。这是一个正确的方式,使跺脚连接。
你试过谷歌? –
示例代码看起来很好,你应该试着问一个更有针对性的问题。你的代码不工作吗? –
是的,当我在uri中添加tcp时,它正在工作。当我传递“stomp:// localhost:61613”时,只有错误弹出。尽管我已经更改了activemq.xml文件。 –