我正在使用 Spring WebSockets 实现 WebSockets 应用程序。
作为STOMP broker,我想使用Wildfly的Artemis(Active MQ)。
我在standalone-full.xml中做了如下配置:
添加以下接受器:
<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 将新的应用程序用户 guest/guest 添加到 application-users.properties
添加以下 StompConfiguration(缩写):
@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"); } }
这似乎在启动时运行良好:
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
但是,我使用 Spring 的 SimpMessagingTemplate 发送第一条消息:
template.convertAndSend(topic, payload);
我得到了错误
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
使用 Stomp,应该不需要事先创建主题。我如何告诉 Artemis 自动创建它?
最佳答案
就我而言,有 2 个问题导致了此错误消息:
1) 第一个问题是主题的名称不是以“jms.topic”开头,但 Artemis 似乎希望如此(无论出于何种原因...)。
通过将代码更改为
template.convertAndSend("jms.topic." + topic, payload);
我可以解决这个问题。
请注意,还需要更改 StompBrokerRelay 配置:
config.enableStompBrokerRelay("jms.topic")
2) 该应用程序现在可以运行,但是当我有多个客户并且其中一个取消订阅该主题时,错误再次出现。此错误及其解决方案(升级到 Artemis 1.3)在此处描述:How update WildFly 10.1.0Final Apache Artemis 1.1.0 to Apache Artemis 1.3
关于java - 在 Wildfly 10 上使用 ActiveMQ Artemis 的 Websockets/STOMP 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42373649/