I am using Artemis with .NET Core and NMS in 2 different projects. One as a consumer and one as a listener and I am following the code example provided in the docs. When I follow the documentation, I can get both async and sync versions to work. However, the listener only works when the queue already previously has a message on it. If i start the listener first with no message and use the async version, after execution from another project, and sending the message from the producer, nothing is happening. So basically I cannot continous listening for the queue on the listener part. anyone knows what im doing wrong?
public void Receive(string queue)
{
IConnectionFactory factory = new NMSConnectionFactory(ServerUri);
using (IConnection connection = factory.CreateConnection(Username, Password))
using (Apache.NMS.ISession session = connection.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, queue);
using (IMessageConsumer consumer = session.CreateConsumer(destination))
{
// Start the connection so that messages will be processed.
connection.Start();
consumer.Listener += new MessageListener(message =>
{
Console.WriteLine(message);
});
//semaphore.WaitOne((int)receiveTimeout.TotalMilliseconds, true);
if (message == null)
{
Console.WriteLine("No message received!");
}
else
{
Console.WriteLine("Received message with ID: " + message.NMSMessageId);
Console.WriteLine("Received message with ID: " + message.Text);
}
/* // Consume a message
IObjectMessage message2 = consumer.Receive() as IObjectMessage;
if (message2 == null)
{
Console.WriteLine("No message received!");
}
else
{
Console.WriteLine("Received message with ID: " + message2.NMSMessageId);
Console.WriteLine("Received message with text: " + message2.Body);
}*/
}
}
}
and for the producer in another project
public void Send(object message, string queue)
{
IConnectionFactory factory = new NMSConnectionFactory(ServerUri);
using (IConnection connection = factory.CreateConnection(Username, Password))
using (ISession session = connection.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, queue);
using (IMessageProducer producer = session.CreateProducer(destination))
{
connection.Start();
producer.DeliveryMode = MsgDeliveryMode.Persistent;
ITextMessage request = session.CreateTextMessage("Hello World!");
request.NMSCorrelationID = "abc";
request.Properties["NMSXGroupID"] = "cheese";
request.Properties["myHeader"] = "Cheddar";
/* IObjectMessage request = session.CreateObjectMessage(message);*/
producer.Send(request);
}
}
}
i expected it to work.