[英]WebSocket convertAndSendToUser can not received message
I am using websocket to send message to client,when using this method broadcast message to client. 我使用websocket向客户端发送消息,当使用此方法向客户端广播消息时。
private void pushInfoImpl(String url, String content) {
if (simpMessagingTemplate != null) {
simpMessagingTemplate.convertAndSend(url, content);
}
}
The client could received messsage successfully. 客户端可以成功收到消息。 When using this method to send specified user: 使用此方法发送指定用户时:
//send url:/queue/location
//user:admin
private void pushInfoImpl(String user, String url, String content) {
if (simpMessagingTemplate != null) {
simpMessagingTemplate.convertAndSendToUser(user, url, content);
}
}
The client can't receive the sent message. 客户端无法接收已发送的消息。 What I have tried: 我尝试过的:
config.enableSimpleBroker("/topic","/queue");
在config.enableSimpleBroker("/topic","/queue");
添加队列config.enableSimpleBroker("/topic","/queue");
stompClient.subscribe('/admin/queue/location', function (greeting) { console.log(greeting.body); });
订阅网址如stompClient.subscribe('/admin/queue/location', function (greeting) { console.log(greeting.body); });
.admin is the user. .admin是用户。 What should I do to fix this problem? 我该怎么做才能解决这个问题? To make the client received server messsage successfully. 使客户端成功收到服务器消息。 This is log: 这是日志:
15:03:28.806]-[Timer-5699]-[org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler]-{Processing MESSAGE destination=/queue/location-userdeqnkwuw session=null payload={"data":[{"status":2,"vehicleId":"cae21196-cb66-4256-88a6-7cdfb23e2c78"}],"desc"...(truncated)}
15:03:28.806]-[Timer-5701]-[org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler]-{Processing MESSAGE destination=/queue/location-userdeqnkwuw session=null payload={"data":[{"status":2,"vehicleId":"cae21196-cb66-4256-88a6-7cdfb23e2c78"}],"desc"...(truncated)}
15:03:28.806]-[Timer-5699]-[org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler]-{Processing MESSAGE destination=/queue/location-userdeqnkwuw session=null payload={"data":[{"status":2,"vehicleId":"cae21196-cb66-4256-88a6-7cdfb23e2c78"}],"desc"...(truncated)}
The reason is the url is not right,on the server,sending parameter should like this: 原因是url不对,在服务器上,发送参数应该是这样的:
user: admin
url: /location(right) vs /queue/location(wrong)
on the client,the subsribe should like this: 在客户端,subribe应该是这样的:
/user/admin/location or /user/{username}/location
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.