Skip to content

Commit ebdc770

Browse files
committed
Use appropriate message id header for STOMP 1.1 vs 1.2
Issue: SPR-14391
1 parent 2cdcf75 commit ebdc770

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
6767

6868
private static final Message<byte[]> HEARTBEAT;
6969

70-
7170
static {
7271
StompHeaderAccessor accessor = StompHeaderAccessor.createForHeartbeat();
7372
HEARTBEAT = MessageBuilder.createMessage(StompDecoder.HEARTBEAT_PAYLOAD, accessor.getMessageHeaders());
@@ -93,6 +92,8 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
9392

9493
private volatile TcpConnection<byte[]> connection;
9594

95+
private volatile String version;
96+
9697
private final AtomicInteger subscriptionIndex = new AtomicInteger();
9798

9899
private final Map<String, DefaultSubscription> subscriptions = new ConcurrentHashMap<String, DefaultSubscription>(4);
@@ -313,7 +314,12 @@ public Subscription subscribe(StompHeaders stompHeaders, StompFrameHandler handl
313314
@Override
314315
public Receiptable acknowledge(String messageId, boolean consumed) {
315316
StompHeaders stompHeaders = new StompHeaders();
316-
stompHeaders.setId(messageId);
317+
if ("1.1".equals(this.version)) {
318+
stompHeaders.setMessageId(messageId);
319+
}
320+
else {
321+
stompHeaders.setId(messageId);
322+
}
317323

318324
String receiptId = checkOrAddReceipt(stompHeaders);
319325
Receiptable receiptable = new ReceiptHandler(receiptId);
@@ -407,6 +413,7 @@ else if (logger.isDebugEnabled()) {
407413
}
408414
else if (StompCommand.CONNECTED.equals(command)) {
409415
initHeartbeatTasks(stompHeaders);
416+
this.version = stompHeaders.getFirst("version");
410417
this.sessionFuture.set(this);
411418
this.sessionHandler.afterConnected(this, stompHeaders);
412419
}

0 commit comments

Comments
 (0)