javaspring-websocketstomp

Spring WebSocket ConvertAndSendToUser not working but convertAndSend working


I am new to Spring boot websocket and messaging semantics. Currently i am able to send private messages using the below code.

String queueName = "/user/" + username  + "/queue/wishes";
simpMessagingTemplate.convertAndSend(queueName, message);

When trying to use convertAndSendToUser I am not getting any error but the message is not getting sent. I knew that with sendToUser there should be a slight change in how the destination name should be formed but I am not getting it right.

String queueName = "/user/queue/wishes";
simpMessagingTemplate.convertAndSendToUser(username, queueName, message);

Below is my subscription code.

stompClient.subscribe('/user/queue/wishes', function(message) {
    alert(message);
}) 

Solution

  • Finally figured out the problem. I did a silly mistake. I was filling the User DestinationPrefix as part of WebSocket config. but didn't set it up for the injected bean SimpMessaging template.