Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 520
myspri Avatar asked Mar 30 '15 20:03

myspri


People also ask

What is a STOMP client?

STOMP is the Simple (or Streaming) Text Oriented Messaging Protocol. It uses a set of commands like CONNECT, SEND, or SUBSCRIBE to manage the conversation. STOMP clients, written in any language, can talk with any message broker supporting the protocol.

How do I unsubscribe from Stompclient?

It is preferable to unsubscribe from a subscription by calling unsubscribe() directly on the object returned by client.

How do you use STOMP?

You need to start a STOMP server with support for WebSocket (using for example HornetQ). Click on the Connect button to connect to the server and subscribe to the /queue/test/ queue. You can then type messages in the form at the bottom of the page to send STOMP messages to the queue.

Where is STOMP used?

The STOMP protocol is commonly used inside a web socket. STOMP can also be used without a websocket, e.g. over a Telnet connection or a message broking service. And Raw WebSockets can be used without STOMP - Eg.


1 Answers

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.

like image 126
btk Avatar answered Oct 09 '22 02:10

btk