连接到Wildfly ActiveMQ Artemis中的http-remoting地址,使用C# .NET – 我漏掉了什么?

huangapple go评论51阅读模式
英文:

Connecting to http-remoting address in Wildfly ActiveMQ Artemis using C# .NET - what am I missing?

问题

我有一个运行ActiveMQ Artemis的Wildfly实例。如何在C# .NET中设置并连接到地址"http-remoting://x.x.x.x:xxxx",并使用用户名和密码?

string url = "amqp://" + username + ":" + password + "@" + ipAddress + ":" + port;

try
{
   var address = new Address(url);
   connection = new Connection(address);

   session = new Session(connection);
   Source source = CreateBasicSource();

   // 创建一个持久性消费者Source。
   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 successfully to: " + url);
   Consumer_Listener(receiver);
}
catch (Exception e)
{
   LogService.Warning("Failed to connect! " + e.Message);
}

上述代码在连接到地址"amqp://x.x.x.x:xxxx"时工作正常,但如果我尝试更改地址为"http-remoting://x.x.x.x:xxxx",则不起作用。我不确定如何更改我的代码,以便它能够连接到我想要的地址。

英文:

I have a Wildfly instance running ActiveMQ Artemis. How can I set up and connect to an address "http-remoting://x.x.x.x:xxxx" in C# .NET with using a username and password?

string url = "amqp://" + username + ":" + password + "@" + ipAddress + ":" + port;

try
{
   var address = new Address(url);
   connection = new Connection(address);

   session = new Session(connection);
   Source source = CreateBasicSource();

   // Create a Durable Consumer Source.
   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: " + url);
   Consumer_Listener(receiver);
}
catch (Exception e)
{
   LogService.Warning("Failed to connect! " + e.Message);
}

The above code works, when connecting to an address "amqp://x.x.x.x:xxxx", but does not work if I try to change the address to "http-remoting://x.x.x.x:xxxx". I am unsure on how to change my code, so that it will connect to my desired address.

答案1

得分: 1

"http-remoting"方案由Java WildFly客户端实现,通常用于在消息上下文中查找JNDI中的JMS ConnectionFactoryDestination。当然,使用AMQP的C# .NET消息客户端对JNDI没有概念或需求,因为那确实是Java特定的东西。

你遇到的问题是WildFly默认未配置为支持AMQP。即使ActiveMQ Artemis是一个多协议代理,WildFly实际上只是使用它来支持JMS,因此它只配置了这一点。要启用对AMQP的支持,您需要添加新的remote-acceptor和新的socket-binding,例如:

<server>
    ...
    <profile>
        ...
        <subsystem xmlns="urn:jboss:domain:messaging-activemq:15.0">
            <server name="default">
                ...
                <remote-acceptor name="amqp" socket-binding="amqp">
                    <param name="protocols" value="AMQP"/>
                </remote-acceptor>
                ...
            </server>
        </subsystem>
        ...
    </profile>
    ...
    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        ...
        <socket-binding name="amqp" port="5672"/>
        ...
    </socket-binding-group>
</server>
英文:

The "http-remoting" scheme is implemented by the Java WildFly client and it's used for various things, but in the messaging context it's usually used to look up the JMS ConnectionFactory and Destination in JNDI. Of course, a C# .NET messaging client that speaks AMQP has no notion or need of JNDI since that's really a Java-specific thing.

The issue you're hitting is that WildFly, by default, isn't configured to support AMQP. Even though ActiveMQ Artemis is a multi-protocol broker WildFly really just uses it for JMS support so that's all it's configured for out-of-the-box. In order to enable support for AMQP you'd need to add a new remote-acceptor as well as a new socket-binding, e.g.:

&lt;server&gt;
    ...
    &lt;profile&gt;
        ...
        &lt;subsystem xmlns=&quot;urn:jboss:domain:messaging-activemq:15.0&quot;&gt;
            &lt;server name=&quot;default&quot;&gt;
                ...
                &lt;remote-acceptor name=&quot;amqp&quot; socket-binding=&quot;amqp&quot;&gt;
                    &lt;param name=&quot;protocols&quot; value=&quot;AMQP&quot;/&gt;
                &lt;/remote-acceptor&gt;
                ...
            &lt;/server&gt;
        &lt;/subsystem&gt;
        ...
    &lt;/profile&gt;
    ...
    &lt;socket-binding-group name=&quot;standard-sockets&quot; default-interface=&quot;public&quot; port-offset=&quot;${jboss.socket.binding.port-offset:0}&quot;&gt;
        ...
        &lt;socket-binding name=&quot;amqp&quot; port=&quot;5672&quot;/&gt;
        ...
    &lt;/socket-binding-group&gt;
&lt;/server&gt;

huangapple
  • 本文由 发表于 2023年5月29日 14:20:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355067.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定