本文介绍了Wildfly 10 上带有 ActiveMQ Artemis 的 Websockets/STOMP 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring WebSockets 实现一个 WebSockets 应用程序.

I am implementing a WebSockets application using Spring WebSockets.

作为STOMP经纪人,我想使用Wildfly的Artemis(Active MQ).

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

我在standalone-full.xml中做了如下配置:

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-user.bat 向 application-users.properties 添加新的应用程序用户 guest/guest

  • add a new application user guest/guest to application-users.properties using add-user.bat

    添加以下 StompConfiguration(缩写):

    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 信息 [org.apache.activemq.artemis.core.server](ServerService Thread Pool -- 64) AMQ221020:在本地主机:61613 协议 [STOMP] 16:57:13,892 信息[org.apache.activemq.artemis.core.server] (ServerService 线程池-- 64) AMQ221007:服务器现已上线

    但是,我使用 Spring 的 SimpMessagingTemplate 发送第一条消息:

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

    template.convertAndSend(topic, payload);
    

    我收到错误

    错误[org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler](reactor-tcp-io-1) 收到错误 {message=[AMQ339001: Destination不存在:/topic/abc/12345/xyz]}session=系统

    使用 Stomp,不需要事先创建主题.我如何告诉 Artemis 自动创建它?

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

    推荐答案

    就我而言,有 2 个问题导致了此错误消息:

    In my case, 2 problems caused this error message:

    1)第一个问题是主题名称​​不是以jms.topic"开头,但 Artemis 似乎期望(无论出于何种原因......).

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

    通过将代码更改为

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

    我可以解决问题.

    请注意,还需要更改 StompBrokerRelay 配置:

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

     config.enableStompBrokerRelay("jms.topic")
    

    2) 应用程序现在可以工作了,但是当我有多个客户端并且其中一个取消订阅该主题时,错误再次出现.此处描述了此错误及其解决方案(升级到 Artemis 1.3):如何将 WildFly 10.1.0Final Apache Artemis 1.1.0 更新到 Apache Artemis 1.3

    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

    这篇关于Wildfly 10 上带有 ActiveMQ Artemis 的 Websockets/STOMP 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    05-21 17:51