Search code examples
javajbosswildflystompactivemq-artemis

Wildfly / JBoss - STOMP protocol not working in embedded Artemis broker


We are running JBoss 7.4.0. We have the embedded Artemis broker running and are using it successfully from applications running in JBoss and external Java clients with no issues.

We have a new requirement to allow another group to drop messages into a queue. They are using Python which uses the STOMP protocol. I'm unable to get this working in the JBoss embedded Artemis broker. It works fine in the Artemis standalone broker.

For JBoss configuration and setup, I added a new socket binding and remote-acceptor like this:

<socket-binding name="external-messaging-stomp" port="61613"/>

...

<remote-acceptor name="stomp-acceptor" socket-binding="external-messaging-stomp">
    <param name="protocols" value="STOMP"/>
</remote-acceptor>

I was getting an error in the JBoss logs about the protocol not being found. I did a little research and it looks like JBoss doesn't include the JARs for the STOMP protocol. I added a module (modules\system\layers\base\org\apache\activemq\artemis\protocol\stomp\main). I pulled the redhat version of the stomp jar with a matching version number and build number as the rest of the JBoss provided Artemis jars. Here is the module.xml:

<module name="org.apache.activemq.artemis.protocol.stomp" xmlns="urn:jboss:module:1.9">
    <resources>
        <resource-root path="artemis-stomp-protocol-2.16.0.redhat-00022.jar"/>
    </resources>

    <dependencies>
        <!-- required to load ActiveMQ protocol SPI -->
        <module name="org.apache.activemq.artemis"/>
        <module name="io.netty"/>
    </dependencies>
</module>

I updated the existing modules\system\layers\base\org\apache\activemq\artemis\main\module.xml to include the following:

<module name="org.apache.activemq.artemis.protocol.stomp" services="import" optional="true"/>

That all seems to work as I'm now seeing these logs from JBoss:

2022-08-19 13:27:07,702 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 78) AMQ221043: Protocol module found: [artemis-stomp-protocol]. Adding protocol support for: STOMP

2022-08-19 13:27:11,040 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 78) AMQ221020: Started NIO Acceptor at 127.0.0.1:61613 for protocols [STOMP]

Here's my Python script that simply tries to establish a connection:

import logging
import time
import sys
import stomp

logging.basicConfig(level=logging.DEBUG)

hosts = [('127.0.0.1', 61613)]

print("Creating connection")
conn = stomp.Connection(host_and_ports=hosts)

print("Connecting")
conn.connect('myUserId', 'myPassword', wait=True)

This script just hangs forever connecting. The debug logs show it sends

DEBUG:stomp.py:Sending frame: [b'STOMP', b'\n', b'accept-version:1.2\n', b'host:127.0.0.1\n', b'login:myUserId\n', b'passcode:myPassword\n', b'\n', b'\x00']

Nothing logs on the JBoss side. I set TRACE logging for Artemis and am not seeing anything related to the connection or handshake. Using Wireshark I sniffed the traffic. I can see that the Python script sends the connection frame. I see a TCP ACK from port 61613, so I know JBoss / Artemis got it. JBoss / Artemis simply never sends anything back and the connection will remain open and connected forever.

As I mentioned I setup standalone Artemis using the same port# and everything works fine. I sniffed that traffic and it all looks the same initially. But for standalone Artemis after the ACK of the connect frame packet, Artemis sends back a STOMP frame indicating it's connected.

I've been banging my head against the wall for a couple days on this one. So if anyone has any ideas, I'd love to hear them.

Thanks! Todd


Solution

  • Thanks to ehsavoie I was able to get this working. He pointed out that JBoss EAP removed STOMP support, but Wildfly has it. I looked at the Wildfly version (23.0.0) which is the basis for our JBoss EAP version (7.4.0). I had made the mistake setting up the module for the STOMP protocol. In the module.xml I missed the dependency for JBoss logging. Once I added that, everything works correctly.

    So for anyone trying to get STOMP working in JBoss EAP, these would be the steps...

    1. Look at the jars in the Artemis module and get the version numbers and build numbers.
    2. Get the correct version and build of artemis-stomp-protocol.jar from the Red Hat Maven repository
    3. Create a new module for STOMP by copying the jar to a new directory (modules\system\layers\base\org\apache\activemq\artemis\protocol\stomp\main) and creating module.xml as shown below.
    4. Update artemis's main module.xml (modules\system\layers\base\org\apache\activemq\artemis\main\module.xml) to include the STOMP module as optional as shown below.
    5. Create a socket binding and remote-acceptor in your configuration.

    This is for EAP 7.4.0. If you are running a different version, use an appropriate module.xml as a template. Better yet, download the corresponding version of Wildfly and look at how it's setup. Here is the module.xml I ended up with for the STOMP module:

    <module name="org.apache.activemq.artemis.protocol.stomp" xmlns="urn:jboss:module:1.9">
        <resources>
            <resource-root path="artemis-stomp-protocol-2.16.0.redhat-00022.jar"/>
        </resources>
    
        <dependencies>
            <!-- required to load ActiveMQ protocol SPI -->
            <module name="org.apache.activemq.artemis"/>
            <module name="org.jboss.logging"/>
            <module name="io.netty"/>
        </dependencies>
    </module>
    

    Here is the line you need to add to the existing artemis module.xml:

        <dependencies>
            …
            <module name="org.apache.activemq.artemis.protocol.stomp" services="import" optional="true"/>
            …
        </dependencies>
    

    Here is the change the JBoss configuration (stanalone.xml, etc) to add a socket binging for port# 61613:

        <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
            …
            <socket-binding name="external-messaging-stomp" port="61613"/>
            …
        </socket-binding-group>
    
    

    And finally here is the remote acceptor that is configured to use STOMP and listen on port 61613:

            <subsystem xmlns="urn:jboss:domain:messaging-activemq:13.0">
                <server name="default">
                    …
                    <remote-acceptor name="stomp-acceptor" socket-binding="external-messaging-stomp">
                        <param name="protocols" value="STOMP"/>
                    </remote-acceptor>
                    …
                </server>
            </subsystem>