简体   繁体   English

WebSocket convertAndSendToUser无法接收消息

[英]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: 我尝试过的:

  1. add queue in config.enableSimpleBroker("/topic","/queue"); config.enableSimpleBroker("/topic","/queue");添加队列config.enableSimpleBroker("/topic","/queue");
  2. subscribe the url like 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.

相关问题 在 SockJS+Spring Websocket 中,convertAndSendToUser 中的“用户”来自哪里? - Where “user” comes from in convertAndSendToUser works in SockJS+Spring Websocket? 在 Android 中的 Java Websocket 服务器收到消息时,不会创建 Toast 消息 - Toast Message is not created when message received at Java Websocket server in Android 在集群环境中使用外部消息代理(RabbitMQ)将Spring套接字转换并发送给用户 - spring socket convertandsendtouser with external message broker(RabbitMQ) in cluster environment WebSocket STOMP 已经覆盖 class 主要方法 getname() convertAndSendToUser 不起作用 - WebSocket STOMP already override class principal method getname() convertAndSendToUser doesn't work 为什么rabbitmq扇出交换只能收到一个订阅消息? - why rabbitmq fanout exchange only one subscribe can be received message? 如何在聊天应用程序中以粗体设置新收到的消息 - How can I set a newly received message in bold in a chatapp 如何使用Android Beam确认收到的消息? - How can I confirm my message was received using Android Beam? onMessage WebSocket中的消息处理 - Message handling in onMessage WebSocket 无法显示收到的消息 - Could not display the received message 确保收到消息 - Ensure that a message is received
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM