我正在尝试使用STOMP协议在Rabbit MQ(3.6.5)队列中读取和写入消息。 我正在使用Apache NMS Stomp(1.5.4)作为客户端库。
使用NMS发送消息时,我遇到以下异常:
输入字符串的格式不正确。
原因是NMS希望提交的消息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:无花果52033-636066062974737556-1:0:1:1 @@会话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 );
}
}
}
这个问题有解决方案吗?