how to capture subscribe event in my webSocket server with Spring 4

折月煮酒 提交于 2019-12-05 01:45:17

You can return anything directly to a client when it subscribes to a destination using a @SubscribeMapping handler method. The returned object won't go to the broker but will be sent directly to the client:

@SubscribeMapping("/chat")
public Collection<ChatMessage> chatInit() {
    ...
    return messages;
}

On the client side:

socket.subscribe("/app/chat", function(message) {
    ...
});

Check out the chat example on GitHub, which shows this exact scenario.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!