Spring Stomp @SubscribeMapping(“/user/…”) with User Destination doesn't work

后端 未结 1 1546
走了就别回头了
走了就别回头了 2021-02-19 07:18

I need to react on a user destination subscription.

Example:

A user subscribes to /user/messages, because he wants to receive all incoming message

相关标签:
1条回答
  • 2021-02-19 07:42

    Define the user prefix also as an application prefix, and you'll then be able to map the subscription in your controller. Configuration:

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/app", "/user");
        registry.enableSimpleBroker("/queue", "/topic");
        registry.setUserDestinationPrefix("/user");
    }
    

    Controller:

    @SubscribeMapping("/messages")
    public void test(Principal p) { 
        sendMessagesThatWereReceivedWhileUserWasOffline();
    }
    
    0 讨论(0)
提交回复
热议问题