I’m trying to read and write messages into/from a Rabbit MQ (3.6.5) queue using the STOMP protocol. I’m using Apache NMS Stomp (1.5.4) as client library.
When sending a message using NMS I get the following exception:
Input string was not in a correct format.
The reasons is that NMS expects the filed message-id to contain a number at a specific position.
This is the code from the NMS library:
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 );
}
The message-id field sent by the Rabbit MQ Broker has the following value:
"T_ID:fig-52033-636066062974737556-1:0:1:1@@session-lOnNy1WnMfOTxEEVQmLHgg@@1"
NMS tries to convert "1@@session-Bo6HXXTZFSh51Qy7X4wx9A@@1" to an Int64.
This is my client code:
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 );
}
}
}
Is there a solution for this problem?
I found the problem.
Apache NMS STOMP expects the message-id field to be in a specific format. They try to parse a specific part of the message-id into a Int64 variable. (Seems to be Apache MQ specific.)
They fixed this problem in version 1.7.1, which sadly is not officially released… looks like the project is not very active / dead.
Bugfix: Apache JIRA
I replaced the nugget package with a build of the latest source. This fixed my problem.
The source can be found here: SVN repo