Search code examples
springwebsocketstompsubscribe

stomp message acknowledgement from client


I am using spring/stomp/websocket framework to notify users of messages asynchronously. I have done this successfully. However, I would be get ACK from the client so that some server side action can take place when this is done.

The flow is roughly as flows:

  1. Service notifies a specific user about a decision and updates a record in the DB with status = "notified"
  2. Client receives the message (using stompClient.subscribe(...))
  3. Client acknowledges that the message was received.
  4. The service "knows" that this message was acknowledged and updates the status to "ACK" in the DB.

    stompClient.connect({login:'guest', passcode:'guest'}, 
           function(frame) {
             setConnected(true);
             **var headers = {ack: 'client'};**
            ...
    
    
        stompClient.subscribe('/user/guest/response',function(notification) {
            //doSomething
        }), **headers**);
    }
    

In the service, the message is sent:

  this.messagingTemplate.convertAndSendToUser(user, "/response",msg, map);

Is there a way to handle the client ACK on the server side? Alternatively, I tried to do a

stompClient.send("/app/response/ack/"+messageId);

on the client, in the method that handles the subscription, but in vain.

Can someone please tell me what is standard way to handle acknowledgments? I have been struggling with this for a a couple of days and any thoughts would be very helpful.

Thanks!


Solution

  • Use the ACK frame as per spec. The server sends an ack:some_id header, the client uses that some_id in the ACK frame.