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:
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!
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.
It is preferable to unsubscribe from a subscription by calling unsubscribe() directly on the object returned by client.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With