1

I am trying to produce messages to and consume messages from ActiveMQ Artemis queues for the first time. I am able to connect and produce messages via Apache.NMS.ActiveMQ as well as Apache.NMS.AMQP when I use the code in a C# console application. However, when I put that same code in a C# Windows forms application the CreateSession method call runs forever.

IConnectionFactory factory = new ConnectionFactory(brokerUri);
using (IConnection connection = factory.CreateConnection(username, password))
{
    using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
    {
        IDestination destination = session.GetQueue(queueName);
        IMessageProducer producer = session.CreateProducer(destination);
        IMessage textMessage = session.CreateTextMessage(text);
        producer.Send(textMessage);
    }
}

My broker is using SSL, and I use the Apache.NMS.ActiveMQ library with the brokerUri="ssl://mybroker:443" and I use Apache.NMS.AMQP with the brokerUri="amqps://mybroker:443". Again, each of these work fine when run in a Console app, but not a Windows Forms app.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
vandyltd
  • 11
  • 2
  • Which version of ActiveMQ are you using? – Justin Bertram Dec 05 '22 at 18:42
  • Do both the Apache.NMS.ActiveMQ and Apache.NMS.AMQP clients fail in the same way when running in a Windows Forms app? – Justin Bertram Dec 05 '22 at 18:44
  • How do you know that `CreateSession` is running forever? Are you using a debugger? If so, can you descend into `CreateSession` to see exactly what's taking so long? – Justin Bertram Dec 05 '22 at 19:02
  • Versions...AMQ version 7.8.7.CR1-redhat-00001, Artemis: 2.16.0.redhat-00046; if that is what you are asking. and yes, they both "fail" at the same CreateSession method. I brought the code in through nuget. when i F11 at the CreateSession method it just runs; doesn't enter the code. – vandyltd Dec 05 '22 at 20:26
  • This sounds like an environmental problem. Have you tried setting up a packet capture to see if anything is transmitted from the client to the broker? If nothing is transmitted then this is 100% a client-side problem. If something is being transmitted to the broker and the client is waiting for a response then that would indicate a problem with the broker or maybe a network issue of some kind. – Justin Bertram Dec 05 '22 at 20:49
  • I am having the same problem with 2.0 libs of Amq. The same code works fine with 1.8.0 lib version. So there is a problem with 2.0 version and win forms app – Adrya Dec 07 '22 at 14:49
  • Thanks for that find, Adrya. I was able to get Apache.NMS.ActiveMQ v1.8 to work in a GUI but not Apache.NMS.AMQP v1.8. In the end i dont plan on using a GUI so i should be able to use the 2.0 versions, but i like to unit test my libraries with GUIs. If anyone has any additional insight please chime in, however. – vandyltd Dec 08 '22 at 17:52
  • I would encourage you guys to report any issues on the [ActiveMQ users mailing list](https://activemq.apache.org/contact) otherwise the problem may never actually get fixed. – Justin Bertram Dec 09 '22 at 16:23
  • Thank you Justin, a bug was created for this: https://issues.apache.org/jira/browse/AMQNET-818 to be followed up :) – Adrya Dec 16 '22 at 07:51
  • Thanks for submitting that bug, Adrya. The workaround discussed in that email thread (wrapping the ActiveMQ code within "System.Threading.Tasks.Task.Run(() =>{...)}; works for me in the 2.0 versions. – vandyltd Dec 19 '22 at 14:54

1 Answers1

0

For the tl;dr crowd:

We've encountered this issue in AMQ6 and AMQ7. The workaround mentioned in the jira issues and the comments above is to wrap any AMQ connection code in a Task.Run, like so:

System.Threading.Tasks.Task.Run(() =>{
    connnection.Start();
});
Mike Devenney
  • 1,758
  • 1
  • 23
  • 42