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)