11

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!

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
myspri
  • 283
  • 7
  • 14
  • I could get past my problem by manually doing a stompClient.send(...) after receiving the message. This is not the perfect ACK, I was wanting to use, but this works for now. It will be ideal to know how ACKS are handled by the spring stomp ws framework. – myspri Apr 11 '15 at 15:07

2 Answers2

4

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.

btk
  • 3,158
  • 2
  • 29
  • 30
4

The answer is no for simple broker.

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html

The simple broker is great for getting started but supports only a subset of STOMP commands (e.g. no acks, receipts, etc.), relies on a simple message sending loop, and is not suitable for clustering. As an alternative, applications can upgrade to using a full-featured message broker.

user1633272
  • 2,007
  • 5
  • 25
  • 48