Search code examples
c#.net.net-coreconsole-applicationactivemq-classic

I get an exception while trying to establish connection to ActiveMQ via NMS in .NET Core console application


I am trying to create simple proof of concept console app that produces a XML file message to the queue and then consumes the message from that queue. The problem is that I can't create a connection via the .CreateConnection() method. When I try to do so I get this exception:

Unhandled exception. Apache.NMS.NMSConnectionException: Error creating transport.
 ---> System.Exception: NewInstance failed to find a match for id = tcp
   at Apache.NMS.ActiveMQ.Transport.TransportFactory.NewInstance(String scheme)
   at Apache.NMS.ActiveMQ.Transport.TransportFactory.CreateTransportFactory(Uri location)
   --- End of inner exception stack trace ---
   at Apache.NMS.ActiveMQ.Transport.TransportFactory.CreateTransportFactory(Uri location)
   at Apache.NMS.ActiveMQ.Transport.TransportFactory.CreateTransport(Uri location)
   at Apache.NMS.ActiveMQ.ConnectionFactory.CreateActiveMQConnection(String userName, String password)
   at Apache.NMS.ActiveMQ.ConnectionFactory.CreateActiveMQConnection()
   at Apache.NMS.ActiveMQ.ConnectionFactory.CreateConnection()
   at ArtemisSender.Program.Main(String[] args) in C:\Users\####\Program.cs:line 12

Here's my program.cs file:

using Apache.NMS;
using Apache.NMS.ActiveMQ;

namespace ArtemisSender
{
    class Program
    {
        static void Main(string[] args)
        {
            IConnectionFactory factory = new ConnectionFactory(new Uri("activemq:tcp://0.0.0.0:61616"));

            using (IConnection connection = factory.CreateConnection())
            {
                connection.Start();

                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = session.GetQueue("queueAddress:newQueue");

                    using (IMessageProducer producer = session.CreateProducer(destination))
                    {
                        ITextMessage textMessage = producer.CreateTextMessage("This is a test message.");

                        producer.Send(textMessage);

                        Console.WriteLine("Message sent");
                    }
                }
            }
        }
    }
}

Here's my transportConnectors from the activemq.xml file

        <transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

I tried to use different protocols such as stomp but that didn't really help. I've tried disabling firewall and antivirus hoping that maybe this would help but it didn't.

I've looked through the documentation and source code to understand the "failed to find match for id = tcp" message but I didn't find anything on that.

I'm using: -.NET 7.0 -Apache.NMS v.2.1.0 -Apache.NMS.ActiveMQ v.2.1.0

The Artemis version is 2.31.0

Found the solution

The error only occurs on the 2.1.0 version of the Apache.NMS. Moving to the 2.0.0 version solved issue


Solution

  • Found the solution

    The error only occurs on the 2.1.0 version of the Apache.NMS. Moving to the 2.0.0 version solved issue