I have such problem in sending notification to the specified user. This is my config file.
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
//registry.enableSimpleBroker("/topic");
}
This one is my client code
$(document).ready(function () {
connect();
}
function connect() {
var socket = new SockJS('/ws');
stompClient = Stomp.over(socket);
stompClient.connect({}, function () {
stompClient.subscribe("/user/queue/reply", function (notification) {
console.log("------------------------ subscribed !!!!!!");
notify(JSON.parse(notification.body).content);
});
});
}
This controller handles all chat related handler methods
@MessageMapping("/message")
@SendToUser("/queue/reply")
public ChatMessage processMessageFromClient(@Payload ChatMessage chatMessage) throws Exception {
return chatMessage;
}
Guys seems I am new in Spring boot websocket sphere, and please tell me whether or not it is enough for sending notification to the specified user. Instead, when I execute the aforementioned client code, it's me, the user principal, who gets notified, not the needed user. What have I done wrong here? It says, that spring boot keeps the session id under the hood, and uses it to resole who to send the notification. But seems it is not the case here...
Here is the browser log, when notification send button is clicked.
Opening Web Socket...
stomp.min.js:8 Web Socket Opened...
stomp.min.js:8 >>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000
stomp.min.js:8 <<< CONNECTED
version:1.1
heart-beat:0,0
user-name:hmkhitaryan
stomp.min.js:8 connected to server undefined
stomp.min.js:8 >>> SUBSCRIBE
id:sub-0
destination:/user/queue/reply
stomp.min.js:8 >>> SEND
destination:/app/message
content-length:71
{"sender":"hmkhitaryan","content":"friend request","type":"FR_REQUEST"}
stomp.min.js:8 <<< MESSAGE
destination:/user/queue/reply
content-type:application/json;charset=UTF-8
subscription:sub-0
message-id:xgec4kaf-15
content-length:71
{"type":"FR_REQUEST","content":"friend request","sender":"hmkhitaryan"}
The thing is, that instead of sending "hmkhitaryan1
", the next user, it sends to me, "hmkhitaryan
".