我在Spring中配置了嵌入式ActiveMQ代理,支持websocket(使用STOMP)。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketMqConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableStompBrokerRelay("/topic");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/messaging")
.setAllowedOrigins("*")
.withSockJS();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public BrokerService brokerService() throws Exception {
PersistenceAdapter persistenceAdapter = getPersistenceAdapter();
BrokerService brokerService = new BrokerService();
brokerService.setPersistent(true);
brokerService.setDeleteAllMessagesOnStartup(true);
brokerService.setUseJmx(false);
brokerService.setBrokerName("broker");
brokerService.addConnector("stomp://localhost:61613");
return borkerService;
}
在我的JavaScript客户端中,我订阅了主题:
var successHandler = function() {
stompClient.subscribe('/topic/test', function(not) {
pushNotification(not);
}, {'id': clientId, 'activemq.subscriptionName': clientId});
};
var socket = new SockJS('/messaging');
var stompClient = Stomp.over(socket);
stompClient.connect({'client-id': clientId}, successHandler, failureHandler);
我正在使用后端服务来提供这个主题:
@Autowired
private SimpMessagingTemplate messagingTemplate;
messagingTemplate.convertAndSend("/topic/test", event);
以下是我的问题:
答案 0 :(得分:0)
发送到主题的消息不会保留,除非客户端先前已创建durable Topic subscription并且消息是在持久标志集的情况下发送的。要创建持久订阅,请添加ActiveMQ STOMP文档中指定的标头。
一旦开始使用持久主题订阅,则可以在KahaDB商店中累积yes消息,此时您可以配置store usage limits来控制大小。