.NET Core控制台应用NMS连接ActiveMQ报tcp传输匹配失败异常
问题:调用CreateConnection()时抛出"NewInstance failed to find a match for id = tcp"异常
错误详情
调用CreateConnection()创建连接时抛出如下异常:
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
代码实现
控制台应用核心代码(Program.cs):
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"); } } } } } }
ActiveMQ Artemis传输连接器配置
activemq.xml中transportConnectors配置段:
<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&wireFormat.maxFrameSize=104857600"/> <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> </transportConnectors>
已尝试的排查步骤
- 更换stomp等其他协议进行连接
- 关闭防火墙及杀毒软件
- 查阅官方文档与源码定位问题
环境信息
- .NET 7.0
- Apache.NMS v2.1.0
- Apache.NMS.ActiveMQ v2.1.0
- Apache Artemis 2.31.0
解决方案
经测试,该异常仅在Apache.NMS v2.1.0版本中触发,将Apache.NMS和Apache.NMS.ActiveMQ两个NuGet包降级至v2.0.0版本后,连接异常问题即可解决。
内容的提问来源于stack exchange,提问作者MaciejT
相关产品推荐
相关产品推荐

