org.springframework.messaging.simp.stomp

## Interface StompSession

All Known Subinterfaces:
  ConnectionHandlingStompSession

All Known Implementing Classes:
  DefaultStompSession

    public interface StompSession

Represents a STOMP session with operations to send messages, create subscriptions and receive messages on those subscriptions.

Since:
  4.2
Author:
  Rossen Stoyanchev

### Nested Class Summary

Nested Classes
`static interface` `StompSession.Receiptable` A handle to use to track receipts.
`static interface` `StompSession.Subscription` A handle to use to unsubscribe or to track a receipt.

### Method Summary

All Methods Instance Methods Abstract Methods
`StompSession.Receiptable` `acknowledge(StompHeaders headers, boolean consumed)` An overloaded version of `acknowledge(String, boolean)` with full `StompHeaders` instead of just a `messageId`.
`StompSession.Receiptable` `acknowledge(String messageId, boolean consumed)` Send an acknowledgement whether a message was consumed or not resulting in an ACK or NACK frame respectively.
`void` `disconnect()` Disconnect the session by sending a DISCONNECT frame.
`void` `disconnect(StompHeaders headers)` Variant of `disconnect()` with headers.
`String` `getSessionId()` Return the id for the session.
`boolean` `isConnected()` Whether the session is connected.
`StompSession.Receiptable` `send(StompHeaders headers, Object payload)` An overloaded version of `send(String, Object)` with full `StompHeaders` instead of just a destination.
`StompSession.Receiptable` `send(String destination, Object payload)` Send a message to the specified destination, converting the payload to a `byte[]` with the help of a `MessageConverter`.
`void` `setAutoReceipt(boolean enabled)` When enabled, a receipt header is automatically added to future `send` and `subscribe` operations on this session, which causes the server to return a RECEIPT.
`StompSession.Subscription` `subscribe(StompHeaders headers, StompFrameHandler handler)` An overloaded version of `subscribe(String, StompFrameHandler)` with full `StompHeaders` instead of just a destination.
`StompSession.Subscription` `subscribe(String destination, StompFrameHandler handler)` Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specified `StompFrameHandler`.

### Method Detail

#### getSessionId

    String getSessionId()

Return the id for the session.

#### isConnected

    boolean isConnected()

Whether the session is connected.

#### setAutoReceipt

    void setAutoReceipt(boolean enabled)

When enabled, a receipt header is automatically added to future `send` and `subscribe` operations on this session, which causes the server to return a RECEIPT. An application can then use the `Receiptable` returned from the operation to track the receipt.

A receipt header can also be added manually through the overloaded methods that accept `StompHeaders`.

#### send

    StompSession.Receiptable send(String destination,
                                  Object payload)

Send a message to the specified destination, converting the payload to a `byte[]` with the help of a `MessageConverter`.

Parameters:
  `destination` - the destination to send a message to
  `payload` - the message payload
Returns:
  a Receiptable for tracking receipts

#### send

    StompSession.Receiptable send(StompHeaders headers,
                                  Object payload)

An overloaded version of `send(String, Object)` with full `StompHeaders` instead of just a destination. The headers must contain a destination and may also have other headers such as "content-type" or custom headers for the broker to propagate to subscribers, or broker-specific, non-standard headers.

Parameters:
  `headers` - the message headers
  `payload` - the message payload
Returns:
  a Receiptable for tracking receipts

#### subscribe

    StompSession.Subscription subscribe(String destination,
                                        StompFrameHandler handler)

Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specified `StompFrameHandler`.

Parameters:
  `destination` - the destination to subscribe to
  `handler` - the handler for received messages
Returns:
  a handle to use to unsubscribe and/or track receipts

#### subscribe

    StompSession.Subscription subscribe(StompHeaders headers,
                                        StompFrameHandler handler)

An overloaded version of `subscribe(String, StompFrameHandler)` with full `StompHeaders` instead of just a destination.

Parameters:
  `headers` - the headers for the subscribe message frame
  `handler` - the handler for received messages
Returns:
  a handle to use to unsubscribe and/or track receipts

#### acknowledge

    StompSession.Receiptable acknowledge(String messageId,
                                         boolean consumed)

Send an acknowledgement whether a message was consumed or not resulting in an ACK or NACK frame respectively.

Note: to use this when subscribing you must set the `ack` header to "client" or "client-individual" in order ot use this.

Parameters:
  `messageId` - the id of the message
  `consumed` - whether the message was consumed or not
Returns:
  a Receiptable for tracking receipts
Since:
  4.3

#### acknowledge

    StompSession.Receiptable acknowledge(StompHeaders headers,
                                         boolean consumed)

An overloaded version of `acknowledge(String, boolean)` with full `StompHeaders` instead of just a `messageId`.

Parameters:
  `headers` - the headers for the ACK or NACK message frame
  `consumed` - whether the message was consumed or not
Returns:
  a Receiptable for tracking receipts
Since:
  5.0.5

#### disconnect

    void disconnect()

Disconnect the session by sending a DISCONNECT frame.

#### disconnect

    void disconnect(StompHeaders headers)

Variant of `disconnect()` with headers.

Parameters:
  `headers` - the headers for the disconnect message frame
Since:
  5.2.2