You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Apache.NMS.ActiveMQ连接JMS Topic时遇‘Error creating transport’错误

问题原因分析
  • 协议与客户端库不匹配:你使用的Apache.NMS.ActiveMQ库仅适配Apache ActiveMQ Broker,不支持WildFly(底层基于ActiveMQ Artemis/HornetQ)的remoting://协议。本地测试用Apache ActiveMQ时,tcp://协议能正常工作,但WildFly的JMS服务依赖Artemis原生协议,和ActiveMQ协议不兼容,这是触发"Error creating transport"的核心原因。
  • URI配置矛盾:代码日志打印的是activemq:tcp://,但实际创建的连接URI是remoting://,两者规则不统一,也会导致传输层无法识别连接逻辑。
解决步骤
  1. 替换适配的客户端库
    移除Apache.NMS.ActiveMQ NuGet包,安装Apache.NMS.Artemis包——这个库专门用于连接ActiveMQ Artemis(WildFly默认的JMS实现)。

  2. 修正连接协议与URI
    WildFly默认JMS端口:

    • TCP协议:5445(默认)
    • AMQP协议:5672(可选)
      将连接URI改为tcp://或amqp://开头,弃用remoting://。
  3. 调整代码实现
    替换ConnectionFactory类型,适配Artemis客户端,修正后的代码示例:

try
{
    // 改用tcp协议,对应WildFly默认JMS端口5445
    Uri uri = new Uri($"tcp://{textBoxIPAddress.Text}:{textBoxPort.Text}");
    // 使用Apache.NMS.Artemis的ConnectionFactory
    ConnectionFactory connectionFactory = new Apache.NMS.Artemis.ConnectionFactory(uri);
    LogService.Warning($"CONNECTING TO:  {uri}");

    if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
    {
        textBoxMessages.Text = "INSERT USERNAME AND PASSWORD";
        return;
    }

    this.connection = await connectionFactory.CreateConnectionAsync(username, password);
    await this.connection.StartAsync();
    LogService.Warning("START CONNECTION!");

    this.session = await connection.CreateSessionAsync(AcknowledgementMode.AutoAcknowledge);
    IDestination destination = await this.session.GetTopicAsync(topic);
    LogService.Warning("GET TOPIC AND SUBSCRIBE TO IT!");

    this.consumer = await this.session.CreateConsumerAsync(destination);
    this.consumer.Listener += Consumer_Listener;
}
catch (Exception e)
{
    LogService.Warning($"FAILED TO CONNECT TO THE TOPIC! {e.Message}\n{e.StackTrace}");
}
额外排查点
  • 确认WildFly已启用JMS服务,且目标Topic已在standalone-full.xml或domain-full.xml中正确配置。
  • 检查防火墙是否允许客户端访问WildFly的JMS端口(5445/5672)。
  • 验证使用的用户名密码拥有访问对应Topic的权限。

内容的提问来源于stack exchange,提问作者IceFire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 08:42:09