Java Spring framework web sockets unique@SendTo注释

Java Spring framework web sockets unique@SendTo注释,java,spring,Java,Spring,我有一个已注册用户的web应用程序,我想向具有唯一用户ID的用户推送消息。为了能够向客户端发送消息,我需要知道如何在@sendto注释中传递唯一的用户id @SendTo("/topic/uniqueuserid") public Greeting greeting(HelloMessage message) throws Exception { int uniqueuserid; Thread.sleep(1000); // simulated dela

我有一个已注册用户的web应用程序,我想向具有唯一用户ID的用户推送消息。为了能够向客户端发送消息,我需要知道如何在
@sendto
注释中传递唯一的用户id

@SendTo("/topic/uniqueuserid")
    public Greeting greeting(HelloMessage message) throws Exception {
        int uniqueuserid;
        Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + message.getName() + uniqueuserid "!");
}
这是注释

@SendTo("/topic/uniqueuserid")
    public Greeting greeting(HelloMessage message) throws Exception {
        int uniqueuserid;
        Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + message.getName() + uniqueuserid "!");
}
这就是stomp js

stompClient.subscribe('/topic/uniqueuserid', function (greeting) {
            showGreeting(JSON.parse(greeting.body).content);
        });

如何在
@SendTo(“/topic/uniqueuserid”)
中传递唯一的用户id方法参数中可以使用
@DestinationVariable
注释,如下所示:

@MessageMapping("/mychat/{uniqueUserId}")
@SendTo("/topic/{uniqueUserId}")
public Message message(@DestinationVariable("uniqueUserId") Long uniqueUserId, HelloMessage message) {
    logger.info("Unique user id: {}", uniqueUserId);
}

您可以在方法参数中使用
@DestinationVariable
注释,如下所示:

@MessageMapping("/mychat/{uniqueUserId}")
@SendTo("/topic/{uniqueUserId}")
public Message message(@DestinationVariable("uniqueUserId") Long uniqueUserId, HelloMessage message) {
    logger.info("Unique user id: {}", uniqueUserId);
}
也许吧