Accessing RabbitMQ Queue via STOMP in .NET

159 views
Skip to first unread message

marco

unread,
Aug 12, 2016, 5:27:18 AM8/12/16
to rabbitmq-users
Hi,

I trying to accessing a rabbitmq queue via the stomp-protocol in .net. Currently i using Apache.NMS.Stomp api to establish a connection.
Somehow i getting a "Input string was not in a correct format." exception, while trying to send / receive a message from the queue.

Does anyone have experience with this api or used an antother solution for this kind of communication?

Thanks for your advices!

Best reagards

marco

Michael Klishin

unread,
Aug 12, 2016, 6:09:21 AM8/12/16
to rabbitm...@googlegroups.com, marco
It would help a lot if your code, full stack trace and server logs were posted.
> --
> You received this message because you are subscribed to the Google Groups "rabbitmq-users"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
> To post to this group, send an email to rabbitm...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
MK

Staff Software Engineer, Pivotal/RabbitMQ


marco

unread,
Aug 12, 2016, 7:02:25 AM8/12/16
to rabbitmq-users
Sure, here you go:

Source Code
==========

#region Usings
 
using System;
using Apache.NMS;
using Apache.NMS.Util;
using Apache.NMS.Stomp;
 
#endregion
 
namespace MessageProducerConsumer
{
    class Program
    {
        static void Main( string[] args )
        {
            // Example connection strings:
            //    activemq:tcp://activemqhost:61616
            //    stomp:tcp://activemqhost:61613
            //    ems:tcp://tibcohost:7222
            //    msmq://localhost
 
            var connecturi = new Uri("stomp:tcp://localhost:61613?transport.useInactivityMonitor=false");
 
            Console.WriteLine( "About to connect to " + connecturi );
 
            // NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder.
            IConnectionFactory factory = new NMSConnectionFactory( connecturi );
 
            using ( var connection = factory.CreateConnection() )
                using ( var session = connection.CreateSession() )
                {
                    var destination = SessionUtil.GetDestination( session, "TestQueue" );
                    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.
                            connection.Start();
                            producer.DeliveryMode = MsgDeliveryMode.Persistent;
 
                            // Send a message
                            var request = session.CreateTextMessage( "Hello World!" );
                            request.NMSCorrelationID = Guid.NewGuid()
                                                           .ToString();
 
                            request.NMSDeliveryMode = MsgDeliveryMode.Persistent;
                            request.NMSPriority = MsgPriority.Highest;
                            request.NMSReplyTo = destination;
                            request.NMSTimeToLive = TimeSpan.FromHours(1);
                            request.NMSTimestamp = DateTime.Now;
 
                            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 );
                            }
                        }
                }
            Console.ReadKey();
        }
    }
}

Stack Trace
=========

   at Apache.NMS.Stomp.Connection.SyncRequest(Command command, TimeSpan requestTimeout) in ...NMS.Stomp\src\main\csharp\Connection.cs:line 523
   at Apache.NMS.Stomp.Session.DoSend(Message message, MessageProducer producer, TimeSpan sendTimeout) in ...\NMS.Stomp\src\main\csharp\Session.cs:line 626
   at Apache.NMS.Stomp.MessageProducer.Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) in ...\NMS.Stomp\src\main\csharp\MessageProducer.cs:line 208
   at Apache.NMS.Stomp.MessageProducer.Send(IMessage message) in...\MessageProducer.cs:line 127
   at MessageProducerConsumer.Program.Main(String[] args) in ...\MessageProducer\Program.cs:line 54
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Server Log
========
=INFO REPORT==== 12-Aug-2016::12:54:42 ===
accepting STOMP connection <0.8249.1> ([::1]:59426 -> [::1]:61613)

=INFO REPORT==== 12-Aug-2016::12:54:42 ===
closing STOMP connection <0.8249.1> ([::1]:59426 -> [::1]:61613)
Reply all
Reply to author
Forward
0 new messages