我正在尝试使用 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 的方法?