Example usage for org.springframework.messaging.simp.stomp StompHeaders setId

List of usage examples for org.springframework.messaging.simp.stomp StompHeaders setId

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaders setId.

Prototype

public void setId(@Nullable String id) 

Source Link

Document

Set the id header.

Usage

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

@Override
public Subscription subscribe(StompHeaders stompHeaders, StompFrameHandler handler) {
    Assert.hasText(stompHeaders.getDestination(), "Destination header is required");
    Assert.notNull(handler, "StompFrameHandler must not be null");

    String subscriptionId = stompHeaders.getId();
    if (!StringUtils.hasText(subscriptionId)) {
        subscriptionId = String.valueOf(DefaultStompSession.this.subscriptionIndex.getAndIncrement());
        stompHeaders.setId(subscriptionId);
    }/*from w w  w . j av  a  2 s  . c o m*/
    checkOrAddReceipt(stompHeaders);
    Subscription subscription = new DefaultSubscription(stompHeaders, handler);

    StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.SUBSCRIBE);
    accessor.addNativeHeaders(stompHeaders);
    Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD);
    execute(message);

    return subscription;
}

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

@Override
public Receiptable acknowledge(String messageId, boolean consumed) {
    StompHeaders stompHeaders = new StompHeaders();
    if ("1.1".equals(this.version)) {
        stompHeaders.setMessageId(messageId);
    } else {/*from  w w  w  .  j  av a  2s.c o  m*/
        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;
}