Skip to content

Commit d078486

Browse files
committed
Make Subscription.unsubscribe() return Receiptable
1 parent fbc5ff8 commit d078486

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,24 @@ public Receiptable acknowledge(StompHeaders headers, boolean consumed) {
345345
return receiptable;
346346
}
347347

348-
private void unsubscribe(String id, @Nullable StompHeaders headers) {
349-
StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.UNSUBSCRIBE);
350-
if (headers != null) {
351-
accessor.addNativeHeaders(headers);
348+
private Receiptable unsubscribe(String id, @Nullable StompHeaders headers) {
349+
Assert.hasText(id, "Subscription id is required");
350+
351+
if (headers == null){
352+
headers = new StompHeaders();
352353
}
354+
355+
String receiptId = checkOrAddReceipt(headers);
356+
Receiptable receiptable = new ReceiptHandler(receiptId);
357+
358+
StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.UNSUBSCRIBE);
359+
accessor.addNativeHeaders(headers);
353360
accessor.setSubscriptionId(id);
361+
354362
Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD);
355363
execute(message);
364+
365+
return receiptable;
356366
}
357367

358368
@Override
@@ -674,17 +684,19 @@ public StompFrameHandler getHandler() {
674684
}
675685

676686
@Override
677-
public void unsubscribe() {
678-
unsubscribe(null);
687+
public Receiptable unsubscribe() {
688+
return unsubscribe(null);
679689
}
680690

681691
@Override
682-
public void unsubscribe(@Nullable StompHeaders headers) {
692+
public Receiptable unsubscribe(@Nullable StompHeaders headers) {
683693
String id = this.headers.getId();
694+
Receiptable receiptable = new ReceiptHandler(null);
684695
if (id != null) {
685696
DefaultStompSession.this.subscriptions.remove(id);
686-
DefaultStompSession.this.unsubscribe(id, headers);
697+
receiptable = DefaultStompSession.this.unsubscribe(id, headers);
687698
}
699+
return receiptable;
688700
}
689701

690702
@Override

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ interface Subscription extends Receiptable {
183183
/**
184184
* Remove the subscription by sending an UNSUBSCRIBE frame.
185185
*/
186-
void unsubscribe();
186+
Receiptable unsubscribe();
187187

188188
/**
189189
* Alternative to {@link #unsubscribe()} with additional custom headers
@@ -192,7 +192,7 @@ interface Subscription extends Receiptable {
192192
* @param headers the custom headers, if any
193193
* @since 5.0
194194
*/
195-
void unsubscribe(@Nullable StompHeaders headers);
195+
Receiptable unsubscribe(@Nullable StompHeaders headers);
196196
}
197197

198198
}

0 commit comments

Comments
 (0)