如何使用grails中的websocket向特定用户发送消息 服务器端
我有我的WebSocketConfig如何使用grails中的websocket向特定用户发送消息 服务器端,grails,websocket,stomp,Grails,Websocket,Stomp,我有我的WebSocketConfig @Slf4j @Configuration @EnableWebSocketMessageBroker class WebSocketConfig extends DefaultWebSocketConfig { @Override void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) { stompEndpointRegistry.addEndp
@Slf4j
@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig extends DefaultWebSocketConfig {
@Override
void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/stomp").setAllowedOrigins("*").withSockJS()
}
}
它在resources.groovy中注册
beans = {
webSocketConfig(WebSocketConfig)
}
我在控制器中使用convertAndSend('/topic/hello',data.toString())
阴蒂侧
以前的代码可以工作,但如果我在服务器端使用(我有一个用户名为000000000的用户)convertAndSendToUser('000000000','/queue/hello',data.toString())
,在客户端订阅中使用'/user/queue/hello'
或'/user/000000000/queue/hello'
则无法工作
我在用这个
private connect(): void {
const ws = Stomp.over(new SockJS('http://localhost:8080/stomp'));
ws.connect({}, () => {
ws.subscribe('/topic/hello', data => {
this.single = JSON.parse(data.body);
});
});
}