How do I connect a STOMP client to Wildfly?

2019-04-09 14:30发布

问题:

I would like to expose my WildFly server to STOMP clients but I have not found any recent samples. As I understand it all communication in recent WildFly versions goes through a single socket (listening to 8080 by default). Do I need to change any configuration or is it supported out of the box? Any pointers are appreciated.

回答1:

It's true WildFly only listens on port 8080 by default (plus port 9990 for management), using HTTP protocol upgrade to switch to different protocols.

However, you can still define additional acceptors for other ports. I don't know whether or not it is possible to use STOMP with protocol upgrade over port 8080, but here's how to configure an additional Netty acceptor for port 5445:

<extension module="org.jboss.as.messaging"/>

<subsystem xmlns="urn:jboss:domain:messaging:2.0">
    <hornetq-server>
        <journal-file-size>102400</journal-file-size>
        <connectors>
            <http-connector name="http-connector" socket-binding="http">
                <param key="http-upgrade-endpoint" value="http-acceptor"/>
            </http-connector>
            <http-connector name="http-connector-throughput" socket-binding="http">
                <param key="http-upgrade-endpoint" value="http-acceptor-throughput"/>
                <param key="batch-delay" value="50"/>
            </http-connector>
            <in-vm-connector name="in-vm" server-id="0"/>
        </connectors>
        <acceptors>
            <http-acceptor name="http-acceptor" http-listener="default"/>
            <http-acceptor name="http-acceptor-throughput" http-listener="default">
                <param key="batch-delay" value="50"/>
                <param key="direct-deliver" value="false"/>
            </http-acceptor>
            <netty-acceptor name="stomp-acceptor" socket-binding="messaging-stomp">
                <param key="protocols" value="STOMP"/>
                <param key="connection-ttl" value="30000"/>
            </netty-acceptor>
            <in-vm-acceptor name="in-vm" server-id="0"/>
        </acceptors>
        <security-settings>
            <security-setting match="#">
                <permission type="send" roles="guest"/>
                <permission type="consume" roles="guest"/>
                <permission type="createNonDurableQueue" roles="guest"/>
                <permission type="deleteNonDurableQueue" roles="guest"/>
            </security-setting>
        </security-settings>
        <address-settings>
            <!--default for catch all-->
            <address-setting match="#">
                <dead-letter-address>jms.queue.DLQ</dead-letter-address>
                <expiry-address>jms.queue.ExpiryQueue</expiry-address>
                <max-size-bytes>10485760</max-size-bytes>
                <page-size-bytes>2097152</page-size-bytes>
                <message-counter-history-day-limit>10</message-counter-history-day-limit>
            </address-setting>
        </address-settings>
        <jms-connection-factories>
            <connection-factory name="InVmConnectionFactory">
                <connectors>
                    <connector-ref connector-name="in-vm"/>
                </connectors>
                <entries>
                    <entry name="java:/ConnectionFactory"/>
                </entries>
            </connection-factory>
            <connection-factory name="RemoteConnectionFactory">
                <connectors>
                    <connector-ref connector-name="http-connector"/>
                </connectors>
                <entries>
                    <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                </entries>
            </connection-factory>
            <pooled-connection-factory name="hornetq-ra">
                <transaction mode="xa"/>
                <connectors>
                    <connector-ref connector-name="in-vm"/>
                </connectors>
                <entries>
                    <entry name="java:/JmsXA"/>
                    <entry name="java:jboss/DefaultJMSConnectionFactory"/>
                </entries>
            </pooled-connection-factory>
        </jms-connection-factories>
        <jms-destinations>
            <jms-queue name="ExpiryQueue">
                <entry name="java:/jms/queue/ExpiryQueue"/>
            </jms-queue>
            <jms-queue name="DLQ">
                <entry name="java:/jms/queue/DLQ"/>
            </jms-queue>
        </jms-destinations>
    </hornetq-server>
</subsystem>

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

In addition, you'll have to create a user account with role guest via add-user.sh. This account will be used by the STOMP client.

Tested on WildFly 8.2.0.Final.



回答2:

I am on a different version of WildFly (10.0.CR1) for that version the smallest possible change looks like:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
 ...
  <acceptor name="stomp-acceptor" factory-class="org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory">
    <param name="protocols" value="STOMP"/>
    <param name="port" value="61613"/>
  </acceptor>
 ...
  </server>
</subsystem>


回答3:

The following conf did the trick in my case (WF 10.0.0.Final)

<remote-acceptor name="stomp-acceptor" socket-binding="messaging-stomp">
   <param name="protocols" value="STOMP"/>
   <param name="connection-ttl" value="30000"/>
   <param name="stomp-enable-message-id" value="true"/>
</remote-acceptor>
...
<socket-binding name="messaging-stomp" port="61613"/>


标签: wildfly stomp