【问题标题】:Is there any documentation regarding getting message from ActiveMQ via STOMP protocol using C#是否有任何关于使用 C# 通过 STOMP 协议从 ActiveMQ 获取消息的文档
【发布时间】:2013-01-04 19:51:44
【问题描述】:

我正在尝试使用 c# 使用 stomp 协议从 activeMQ 队列接收/发送消息。因为我对activemq和stomp不太了解。所以我正在寻找一些合适的文档或示例代码,我可以通过它逐步学习。

  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);
        }
    }
}

} 我试过这个。 stomp连接的正确方法吗?

【问题讨论】:

  • 示例代码看起来不错,你真的应该试着问一个更有针对性的问题。你的代码不起作用吗?
  • 是的,当我在 uri 中添加 tcp 时它正在工作。当我传递“stomp://localhost:61613”时,才会弹出错误消息。即使我已经更改了 activemq.xml 文件。
  • 错误是“无效的 URI:无法解析主机名”
  • 那是因为 stomp:// 不是一个有效的传输协议。使用 tcp:// 进行 TCP 连接,使用 ssl:// 进行 SSL 连接。
  • 但是我想使用 stomp 协议然后我仍然必须使用 tcp。

标签: c# activemq stomp


【解决方案1】:

有各种语言的 STOMP 客户端库,对于 .NET,有 Apache.NMS.Stomp 库,它围绕 STOMP 语义放置了一个 JMS 类型外观。如果您想获得更多技术知识并了解 STOMP 协议的真正含义,那么 STOMP 规范非常清晰易懂。当然,ActiveMQ 自己的站点在其STOMP support 上有一些您应该阅读的文档。一些网络搜索也将很快为您提供一些关于使用 NMS.Stomp 库与 ActiveMQ 交互的好消息blog posts

【讨论】:

    猜你喜欢
    • 2021-06-17
    • 2019-01-23
    • 2020-10-27
    • 2011-04-05
    • 2011-02-10
    • 2010-09-28
    • 2012-11-04
    • 2019-02-08
    • 2021-11-22
    相关资源
    最近更新 更多