-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Assuming in the browser, you establish the connection and subscribe like so:
client.subscribe("/user/notify", on_message);
This results in an okay looking console log:
XHR finished loading: GET "http://localhost:9000/stomp/info". spring-websocket.js:807
Web Socket Opened... spring-websocket.js:2510
>>> CONNECT
accept-version:1.1,1.0
heart-beat:0,0
spring-websocket.js:2510
<<< CONNECTED
user-name:[email protected]
heart-beat:0,0
version:1.1
spring-websocket.js:2510
connected to server undefined spring-websocket.js:2510
Client {ws: SockJS, counter: 0, connected: true, heartbeat: Object, maxWebSocketFrameSize: 16384…}
app.js:71
>>> SUBSCRIBE
id:sub-0
destination:/user/notify
Notice, the user does have a name. In this case obtained by a CAS login that is required even to load the page.
and on the server...
2014-07-13 15:00:17,222 [http-nio-9000-exec-7] DEBUG stomp.StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=CONNECT, nativeHeaders={heart-beat=[0,0], accept-version=[1.1,1.0]}, simpMessageType=CONNECT, id=744a315a-adde-746a-7bc5-5724b10ad6ea, timestamp=1405288817222}]
2014-07-13 15:00:17,224 [clientOutboundChannel-1] DEBUG stomp.StompEncoder - Encoded STOMP CONNECTED, headers={user-name=[[email protected]], heart-beat=[0,0], version=[1.1]}
2014-07-13 15:00:17,410 [http-nio-9000-exec-6] DEBUG stomp.StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=SUBSCRIBE, nativeHeaders={id=[sub-0], destination=[/user/notify]}, simpMessageType=SUBSCRIBE, simpSubscriptionId=sub-0, simpDestination=/user/notify, id=37c66866-e6f5-41bc-0de9-eacdb11ff400, timestamp=1405288817410}]
2014-07-13 15:00:17,411 [clientInboundChannel-4] DEBUG user.UserDestinationMessageHandler - Sending message to resolved destination=/notify-user6bgaqwlu
After tracing through the code, it appears that the proper way to direct a message to a user destination should be like this:
def principal = springSecurityService.getPrincipal()
brokerMessagingTemplate.convertAndSendToUser principal.username, '/notify', message.toString()
If you include the full destination path (like `/user/notify'), you get an error. This is because the library marshals things up to conform to the spring docs and the '/user/' here is redundant with the one inserted by the library.
Expected destination pattern "/principal/{userId}/**". Stacktrace follows:
Message: Expected destination pattern "/principal/{userId}/**"
Anyway, using '/notify' as the destination, the library appears to accept things and ends up logging this:
2014-07-13 15:01:49,975 [http-nio-9000-exec-9] DEBUG stomp.StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=CONNECT, nativeHeaders={heart-beat=[0,0], accept-version=[1.1,1.0]}, simpMessageType=CONNECT, id=3daf5238-0e15-4f30-90fc-6e34b94414b0, timestamp=1405288909975}]
2014-07-13 15:01:49,977 [clientOutboundChannel-2] DEBUG stomp.StompEncoder - Encoded STOMP CONNECTED, headers={user-name=[[email protected]], heart-beat=[0,0], version=[1.1]}
2014-07-13 15:01:50,025 [http-nio-9000-exec-4] DEBUG stomp.StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=SUBSCRIBE, nativeHeaders={id=[sub-0], destination=[/user/notify]}, simpMessageType=SUBSCRIBE, simpSubscriptionId=sub-0, simpDestination=/user/notify, id=972c5199-6224-2c76-fdaf-0c61cf1c2f94, timestamp=1405288910025}]
2014-07-13 15:01:50,026 [clientInboundChannel-2] DEBUG user.UserDestinationMessageHandler - Sending message to resolved destination=/notify-uservg2eukyn
Bu the client does not receive the message.
I've also tried subscribing like so:
client.subscribe("/notify", on_message);
But this doesn't work either.
If I send the same message to a 'topic' destination, messages are delivered as expected.