STOMP:调用用@MessageMapping注释的方法不向订阅用户发送消息
遵循有关 websockets 的本教程 (https://www.baeldung.com/websockets-spring)这在我的计算机本地工作。
我的问题是,仅当 stompclient 直接与 @MessageMapping 对话时,直接使用端点(/send)调用该方法不会向所有订阅用户发送消息。
@MessageMapping("/liveoffers")
@SendTo("/topic/messages")
public OutputMessage send(final Message message) throws Exception {
final String time = new SimpleDateFormat("HH:mm").format(new Date());
return new OutputMessage(message.getFrom(), message.getText(), time);
}
@GetMapping(value = "/send")
@ResponseStatus(HttpStatus.OK)
public void invokeSend() throws Exception {
send(new Message("from", "text"));
}
无论如何,我可以用下面类似的方式调用@MessageMapping,但实际上它可以正常工作吗?
Followed this tutorial regarding websockets (https://www.baeldung.com/websockets-spring) and this works locally on my computer.
My issue is that calling the method directly with an endpoint (/send) does not send a message to all subscribed users, only when stompclient talks to the @MessageMapping directly.
@MessageMapping("/liveoffers")
@SendTo("/topic/messages")
public OutputMessage send(final Message message) throws Exception {
final String time = new SimpleDateFormat("HH:mm").format(new Date());
return new OutputMessage(message.getFrom(), message.getText(), time);
}
@GetMapping(value = "/send")
@ResponseStatus(HttpStatus.OK)
public void invokeSend() throws Exception {
send(new Message("from", "text"));
}
Is there anyway I can call the @MessageMapping in a similar way below but actually have it functioning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 SimpMessagingTemplate 来发送消息而不是调用映射方法?
Have you considered using SimpMessagingTemplate to send a message instead of calling a mapped method?