Skip to content
Advertisement

Websocket Client not receiving any messages

I have Python client which opens a websocket connection to a server and subscribes to particular topic using STOMP protocol, subscription goes just fine as i see on the server all is fine. However, When the server publishes a few messages the client does not receive any. Here are the codes used:

Client

JavaScript

Code server uses to publish the message:

JavaScript

When i checked out the value of the above variables i saw that destination was as expected queue/alerts. I have java client to test out as well and it works just fine. I have even tried this by subscribing to /topic/alerts and sending to it via template.convertAndSend(/topic/alerts), here too i received nothing. I am a drawing a complete blank on this and would appreciate any sort of help!

Advertisement

Answer

After many days of hair pulling I finally figured out the reason and the fix!

  1. The java client I used was WebSocketStompClient stompClient = new WebSocketStompClient(transport);.The stompClient.connect(URL, webSocketHttpHeaders, sessionHandler); method implicitly sends a stomp CONNECTnnx00n
  2. The Springboot server which has been configured for STOMP understands this as a connection request and responds with a CONNECT_ACK.
  3. When this ACK is sent it also updates it’s local UserRegistry with the new user. So the internal message broker knows that there is a user who has subscribed to so-and-so topic.
  4. In my Python code, i had merely opened a Websocket connection and after that directly sent a SUBSCRIBE message. So the broker never got a CONNECT so the user was never stored! This resulted in the messages later on being published to be merely discarded by the broker.
  5. The fix was to send a CONNECTnnx00n after opening up the connection and before the subscription. Here is the code:
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement