Spring Boot ActiveMQ Durable Subscribers?

时间:2018-04-16 13:12:29

标签: websocket activemq stomp spring-websocket

我正在尝试为离线用户发送消息,因此我实施持久订阅者但仍然无法正常工作,当连接然后发送消息正在工作时会丢失一些内容,断开然后发送消息重新连接未收到。有什么问题?

来自UI静态用户 userone

function connect() {
var socket = new SockJS('/websocket');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/reply/userone?consumer.retroactive=true', function (greeting) {
message = greeting;
showGreeting(greeting);

});
});
}

WebSocketConfig

public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {


config.setApplicationDestinationPrefixes("/app")
.enableStompBrokerRelay("/topic");

}


public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/websocket").setAllowedOrigins("*").addInterceptors(new HttpHandshakeInterceptor()).withSockJS();
}


 @Bean
    public BrokerService broker() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setSchedulePeriodForDestinationPurge(10000);
        broker.addConnector("stomp://localhost:61613");
        PolicyMap policyMap = new PolicyMap();
        PolicyEntry policyEntry = new PolicyEntry();

        policyEntry.setGcInactiveDestinations(true);
        policyEntry.setInactiveTimeoutBeforeGC(30000);
        policyEntry.setQueue(">");
        FixedSizedSubscriptionRecoveryPolicy policySize = new FixedSizedSubscriptionRecoveryPolicy(); 
        policySize.setMaximumSize(1000);

        policyEntry.setSubscriptionRecoveryPolicy(policySize);
        List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
        entries.add(policyEntry);

        policyMap.setPolicyEntries(entries);

        //broker.se
        broker.setDestinationPolicy(policyMap);
        return broker;
    }

if(notificationInfo.getUsersID()!=null) {
notificationInfo.getUsersID().forEach(user->messagingTemplate.convertAndSend("/topic/reply/" +user, notificationInfo.getMessage(),headers));
}

1 个答案:

答案 0 :(得分:0)

默认情况下,所有STOMP订阅都是非持久的,因为它们是STOMP规范所需的唯一订阅类型。对持久订阅的支持是特定经纪人提供的扩展。 ActiveMQ需要使用某些特定的HTTP标头。请参阅ActiveMQ STOMP documentation中的更多内容(向下滚动到“ActiveMQ Extensions to STOMP”部分)。