STOMP client session supports sending ack/nack
Issue: SPR-14208
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -310,6 +310,23 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||
return subscription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receiptable acknowledge(String messageId, boolean consumed) {
|
||||
StompHeaders stompHeaders = new StompHeaders();
|
||||
stompHeaders.setId(messageId);
|
||||
|
||||
String receiptId = checkOrAddReceipt(stompHeaders);
|
||||
Receiptable receiptable = new ReceiptHandler(receiptId);
|
||||
|
||||
StompCommand command = (consumed ? StompCommand.ACK : StompCommand.NACK);
|
||||
StompHeaderAccessor accessor = createHeaderAccessor(command);
|
||||
accessor.addNativeHeaders(stompHeaders);
|
||||
Message<byte[]> message = createMessage(accessor, null);
|
||||
execute(message);
|
||||
|
||||
return receiptable;
|
||||
}
|
||||
|
||||
private void unsubscribe(String id) {
|
||||
StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.UNSUBSCRIBE);
|
||||
accessor.setSubscriptionId(id);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -86,6 +86,18 @@ public interface StompSession {
|
||||
*/
|
||||
Subscription subscribe(StompHeaders headers, StompFrameHandler handler);
|
||||
|
||||
/**
|
||||
* Send an acknowledgement whether a message was consumed or not resulting
|
||||
* in an ACK or NACK frame respectively.
|
||||
* <p><strong>Note:</strong> to use this when subscribing you must set the
|
||||
* {@link StompHeaders#setAck(String) ack} header to "client" or
|
||||
* "client-individual" in order ot use this.
|
||||
* @param messageId the id of the message
|
||||
* @param consumed whether the message was consumed or not
|
||||
* @return a Receiptable for tracking events
|
||||
*/
|
||||
Receiptable acknowledge(String messageId, boolean consumed);
|
||||
|
||||
/**
|
||||
* Disconnect the session by sending a DISCONNECT frame.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user