【问题标题】:Conenct to RabbitMQ using Apache NMS STOMP使用 Apache NMS STOMP 连接到 RabbitMQ
【发布时间】:2016-08-15 17:01:40
【问题描述】:

我正在尝试使用 STOMP 协议在 Rabbit MQ (3.6.5) 队列中读取和写入消息。 我使用 Apache NMS Stomp (1.5.4) 作为客户端库。

使用 NMS 发送消息时出现以下异常:
输入字符串格式不正确。

原因是 NMS 期望归档的 message-id 在特定位置包含一个数字。
这是 NMS 库中的代码:

public void SetValue( String messageKey )
{
    key = messageKey;

    // Parse off the sequenceId
    var p = messageKey.LastIndexOf( ":" );
    if ( p >= 0 )
    {
        ProducerSequenceId = Int64.Parse( messageKey.Substring( p + 1 ) );
        messageKey = messageKey.Substring( 0, p );
    }
    ProducerId = new ProducerId( messageKey );
}

Rabbit MQ Broker 发送的 message-id 字段有以下值: “T_ID:fig-52033-636066062974737556-1:0:1:1@@session-lOnNy1WnMfOTxEEVQmLHgg@@1”
NMS 尝试将 "1@@session-Bo6HXXTZFSh51Qy7X4wx9A@@1" 转换为 Int64。

这是我的客户端代码:

var connecturi = new Uri( "stomp:tcp://localhost:61613?transport.useInactivityMonitor=false&trace=true" );

Console.WriteLine( "About to connect to " + connecturi );
IConnectionFactory factory = new NMSConnectionFactory( connecturi );

using ( var connection = factory.CreateConnection( "XXXX", "XXXX" ) )
    using ( var session = connection.CreateSession() )
    {
        connection.Start();

        var destination = SessionUtil.GetDestination( session, "queue://FOO.BAR" );
        Console.WriteLine( "Using destination: " + destination );

        // Create a consumer and producer
        using ( var consumer = session.CreateConsumer( destination ) )
            using ( var producer = session.CreateProducer( destination ) )
            {
                // Start the connection so that messages will be processed.
                producer.DeliveryMode = MsgDeliveryMode.Persistent;

                // Send a message
                var request = session.CreateTextMessage( "Hello World! FROM NMS" );

                producer.Send( request );

                // Consume a message
                var message = consumer.Receive() as ITextMessage;
                if ( message == null )
                {
                    Console.WriteLine( "No message received!" );
                }
                else
                {
                    Console.WriteLine( "Received message with ID:   " + message.NMSMessageId );
                    Console.WriteLine( "Received message with text: " + message.Text );
                }
            }
    }

这个问题有解决办法吗?

  • 一种配置 NMS 以不同方式处理 id 的方法?
  • 告诉 Rabbit MQ 生成其他消息 ID 的方法?

【问题讨论】:

    标签: c# rabbitmq nms apache-nms


    【解决方案1】:

    我发现了问题。
    Apache NMS STOMP 期望 message-id 字段采用特定格式。他们尝试将 message-id 的特定部分解析为 Int64 变量。 (似乎是 Apache MQ 特定的。)
    他们在版本 1.7.1 中修复了这个问题,遗憾的是没有正式发布……看起来这个项目不是很活跃/死了。

    修正:Apache JIRA

    我用最新源代码的构建替换了 nugget 包。 这解决了我的问题。

    来源可以在这里找到:SVN repo

    【讨论】:

      猜你喜欢
      • 2016-11-14
      • 2014-02-13
      • 2018-03-09
      • 2019-05-08
      • 2011-09-30
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 2012-03-13
      相关资源
      最近更新 更多