1

I am implementing a WebSockets application using Spring WebSockets.

As a STOMP broker, I want to use Wildfly's Artemis (Active MQ).

I did the following configuration in standalone-full.xml:

  • Adding the following acceptor:

    <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>
    
  • add a new application user guest/guest to application-users.properties using add-user.bat

  • add the following StompConfiguration (abbreviated):

    @Configuration
    @EnableWebSocketMessageBroker
    public class StompConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
        @Override
        public void registerStompEndpoints(StompEndpointRegistry registry) {
            registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
        }
    
        @Override
        public void configureMessageBroker(MessageBrokerRegistry config) {
            config.setApplicationDestinationPrefixes("/app");
                config.enableStompBrokerRelay("/topic", "/queue").setRelayHost("localhost").setRelayPort(61613)
                .setClientLogin("guest").setClientPasscode("guest");
            }
        }
    

This seems to work well at startup:

16:57:13,890 INFO [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 64) AMQ221020: Started Acceptor at localhost:61613 for protocols [STOMP] 16:57:13,892 INFO [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 64) AMQ221007: Server is now live

However, wenn I send the first message using Spring's SimpMessagingTemplate:

template.convertAndSend(topic, payload);

I get the error

ERROR [org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler] (reactor-tcp-io-1) Received ERROR {message=[AMQ339001: Destination does not exist: /topic/abc/12345/xyz]} session=system

Using Stomp, it should not be necessary to create a topic beforehand. How can I tell Artemis to create it automatically?

stefan.m
  • 1,912
  • 4
  • 20
  • 36
  • it is advisable to add the "host" parameter to the stomp-acceptor. Otherwise it cannot be accessed from another host, as the default for "host" is localhost: (replace with your server's IP address) – stefan.m Feb 24 '17 at 12:23

1 Answers1

3

In my case, 2 problems caused this error message:

1) The first problem was that the name of the topic did not start with "jms.topic", but Artemis seems to expect that (for whatever reason...).

By changing the code to

template.convertAndSend("jms.topic." + topic, payload);

I could resolve the problem.

Note that it was also necessary to change the StompBrokerRelay configuration:

 config.enableStompBrokerRelay("jms.topic")

2) The application now worked, but when I had several clients and one unsubscribed from the topic, the error reappeared again. This error and its solution (an upgrade to Artemis 1.3) is described here: How update WildFly 10.1.0Final Apache Artemis 1.1.0 to Apache Artemis 1.3

Community
  • 1
  • 1
stefan.m
  • 1,912
  • 4
  • 20
  • 36