I am using Spring 4 websockets on Tomcat 8 and I have the following configuration:
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/notify">
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic" />
</websocket:message-broker>
My Spring controller has the following method:
@MessageMapping("/notify/{client}")
public void pushMessage(@DestinationVariable long client, String message) {
System.out.println("Send " + message + " to " + client);
template.convertAndSend("/topic/push/" + client, message);
}
So what I'm trying to do here is that if client 1 wants to send a message to client 2, it uses /app/notify/2. Then the Spring controller will move the message to the topic /topic/push/2.
In my client, I wrote the following code:
var id = 1;
var sock = new SockJS('/project/notify');
var client = Stomp.over(sock);
client.connect({}, function() {
client.subscribe('/topic/push/' + id, function(message) {
console.log(message);
});
});
The connection works fine /project- this is just the context root of my application.
I also have the following code in my client for sending a message:
client.send('/app/notify/' + id, {}, "test");
Both variables ( clientand id) are available, I do not get any errors from this part of the code, and I can see on my console that the message is indeed sent:
>>> SEND
destination:/app/notify/1
content-length:4
test
System.out.println() , , - , ( , , ).