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

使用C# .NET连接Wildfly ActiveMQ Artemis的http-remoting地址问题

解决C# .NET通过http-remoting连接Wildfly上ActiveMQ Artemis的问题

你当前的代码是基于AMQP TCP协议直接连接的,但http-remoting://对应的是Wildfly上基于WebSocket的AMQP传输通道,需要调整连接方式为AMQP over WebSocket,具体修改步骤如下:

  1. 修改连接URL格式:
    将原amqp://协议替换为ws://(HTTP场景)或wss://(HTTPS加密场景),并添加Wildfly中AMQP WebSocket的默认路径/amqp(如果你的Wildfly配置了自定义路径,需对应修改)。

  2. 配置WebSocket传输选项:
    使用Qpid Proton的TransportOptions启用WebSocket模式,并指定对应的端点路径与认证凭证。

  3. 调整连接初始化逻辑:
    创建Connection时传入配置好的TransportOptions,确保底层用WebSocket协议通信。

修改后的完整代码示例:

string username = "你的用户名";
string password = "你的密码";
string ipAddress = "x.x.x.x";
string port = "xxxx";
string topic = "你的目标主题";

// 构建WebSocket格式的连接URL
string wsUrl = $"ws://{ipAddress}:{port}/amqp";

try
{
    var address = new Address(wsUrl);
    // 配置WebSocket传输选项
    var transportOptions = new TransportOptions
    {
        WebSocket = true,
        WebSocketPath = "/amqp",
        UserName = username,
        Password = password
    };

    connection = new Connection(address, transportOptions);
    session = new Session(connection);

    Source source = CreateBasicSource();

    // 配置持久化消费者
    source.Address = topic;
    source.ExpiryPolicy = new Symbol("never");
    source.Durable = 2;
    source.DistributionMode = new Symbol("copy");

    ReceiverLink receiver = new ReceiverLink(session, "test-subscription", source, null);
    LogService.Warning("Connected succesfully to: " + wsUrl);
    Consumer_Listener(receiver);
}
catch (Exception e)
{
    LogService.Warning("Failed to connect! " + e.Message);
}

关键说明:

  • WebSocket路径:Wildfly中ActiveMQ Artemis的AMQP WebSocket默认端点是/amqp,如果你的Wildfly配置文件(如standalone.xml)中修改了messaging-activemq子系统的WebSocket路径,需对应调整WebSocketPath的值。
  • HTTPS场景:如果使用加密的https-remoting://,将ws://替换为wss://即可,确保Wildfly已配置对应SSL证书。
  • 凭证处理:通过TransportOptions直接设置用户名密码,避免URL拼接带来的编码问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 10:23:29