我想使用websockets实现一种异步机制。我的想法是:
它应该可以工作,但这里有一个问题:如何确保另一个客户端不能简单地订阅一个存在但不属于它们的ID?
此外,是否有任何内置机制来实现这一目标?
发布于 2020-04-15 12:17:41
StompEventHandler,如下所示@Controller
public class StompEventHandler{
@EventListener
public void handleSubscription(SessionSubscribeEvent event) {
//Get incoming sessionDetails from event.
//get the destination.
// Validate that the destination is present in Subscription HashMap
// and also that no client maps to the topic id.
// Based on the result either send the message or send Unauth message to
client.
}
}/topic/callback/<your_id>广播消息,还需要将消息发送到目的地,比如:/user/queue/callback/<your_id>。要发送到目的地,您需要使用simpMessagingTemplate.convertAndSendToUser(username, destination, payload, Headers) 读得好StompEventHandler类中的客户端发送一条StompEventHandler消息。这将强制取消订阅客户端。读得好https://stackoverflow.com/questions/60668695
复制相似问题