Search code examples
c#.netjmswildflyactivemq-artemis

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


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.


Solution

  • 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.:

    <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>