Top Description Inners Methods
org.springframework.messaging.simp.stomp

public Interface StompSession

Known Direct Subinterfaces
org.springframework.messaging.simp.stomp.ConnectionHandlingStompSession
Imports
java.util.function.Consumer, org.springframework.lang.Nullable

Represents a STOMP session with operations to send messages, create subscriptions and receive messages on those subscriptions.
Author
Rossen Stoyanchev
Since
4.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
StompSession.Receiptable

A handle to use to track receipts.

public static interface
StompSession.Subscription

A handle to use to unsubscribe or to track a receipt.

Method Summary

Modifier and TypeMethod and Description
public StompSession.Receiptable

Returns:

a Receiptable for tracking receipts
acknowledge
(String
the id of the message
messageId
,
boolean
whether the message was consumed or not
consumed
)

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

public StompSession.Receiptable

Returns:

a Receiptable for tracking receipts
acknowledge
(StompHeaders
the headers for the ACK or NACK message frame
headers
,
boolean
whether the message was consumed or not
consumed
)

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

public void
disconnect()

Disconnect the session by sending a DISCONNECT frame.

public void
disconnect(StompHeaders
the headers for the disconnect message frame
headers
)

Variant of disconnect() with headers.

public String
getSessionId()

Return the id for the session.

public boolean
isConnected()

Whether the session is connected.

public StompSession.Receiptable

Returns:

a Receiptable for tracking receipts
send
(String
the destination to send a message to
destination
,
Object
the message payload
payload
)

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

public StompSession.Receiptable

Returns:

a Receiptable for tracking receipts
send
(StompHeaders
the message headers
headers
,
Object
the message payload
payload
)

An overloaded version of send(String, Object) with full StompHeaders instead of just a destination.

public 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.

public StompSession.Subscription

Returns:

a handle to use to unsubscribe and/or track receipts
subscribe
(String
the destination to subscribe to
destination
,
StompFrameHandler
the handler for received messages
handler
)

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

public StompSession.Subscription

Returns:

a handle to use to unsubscribe and/or track receipts
subscribe
(StompHeaders
the headers for the subscribed message frame
headers
,
StompFrameHandler
the handler for received messages
handler
)

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

Method Detail

acknowledgeback to summary
public 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:String

the id of the message

consumed:boolean

whether the message was consumed or not

Returns:StompSession.Receiptable

a Receiptable for tracking receipts

Since
4.3
acknowledgeback to summary
public StompSession.Receiptable acknowledge(StompHeaders headers, boolean consumed)

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

Parameters
headers:StompHeaders

the headers for the ACK or NACK message frame

consumed:boolean

whether the message was consumed or not

Returns:StompSession.Receiptable

a Receiptable for tracking receipts

Since
5.0.5
disconnectback to summary
public void disconnect()

Disconnect the session by sending a DISCONNECT frame.

disconnectback to summary
public void disconnect(StompHeaders headers)

Variant of disconnect() with headers.

Parameters
headers:StompHeaders

the headers for the disconnect message frame

Since
5.2.2
getSessionIdback to summary
public String getSessionId()

Return the id for the session.

isConnectedback to summary
public boolean isConnected()

Whether the session is connected.

sendback to summary
public 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:String

the destination to send a message to

payload:Object

the message payload

Returns:StompSession.Receiptable

a Receiptable for tracking receipts

sendback to summary
public 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:StompHeaders

the message headers

payload:Object

the message payload

Returns:StompSession.Receiptable

a Receiptable for tracking receipts

setAutoReceiptback to summary
public 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.

subscribeback to summary
public 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:String

the destination to subscribe to

handler:StompFrameHandler

the handler for received messages

Returns:StompSession.Subscription

a handle to use to unsubscribe and/or track receipts

subscribeback to summary
public StompSession.Subscription subscribe(StompHeaders headers, StompFrameHandler handler)

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

Parameters
headers:StompHeaders

the headers for the subscribed message frame

handler:StompFrameHandler

the handler for received messages

Returns:StompSession.Subscription

a handle to use to unsubscribe and/or track receipts

org.springframework.messaging.simp.stomp back to summary

public Interface StompSession.Receiptable

Known Direct Subinterfaces
org.springframework.messaging.simp.stomp.StompSession.Subscription
Known Direct Implementers
org.springframework.messaging.simp.stomp.DefaultStompSession.ReceiptHandler

A handle to use to track receipts.
See Also
setAutoReceipt(boolean)

Method Summary

Modifier and TypeMethod and Description
public void
addReceiptLostTask(Runnable
the task to invoke
task
)

Task to invoke when a receipt is not received in the configured time.

public void
addReceiptTask(Runnable
the task to invoke
task
)

Task to invoke when a receipt is received.

public void
addReceiptTask(Consumer<StompHeaders>
the consumer to invoke
task
)

Variant of addReceiptTask(Runnable) with a Consumer of the headers from the RECEIPT frame.

public String
getReceiptId()

Return the receipt id, or null if the STOMP frame for which the handle was returned did not have a "receipt" header.

Method Detail

addReceiptLostTaskback to summary
public void addReceiptLostTask(Runnable task)

Task to invoke when a receipt is not received in the configured time.

Parameters
task:Runnable

the task to invoke

Exceptions
IllegalArgumentException:
if the receiptId is null
See Also
org.springframework.messaging.simp.stomp.StompClientSupport#setReceiptTimeLimit(long)
addReceiptTaskback to summary
public void addReceiptTask(Runnable task)

Task to invoke when a receipt is received.

Parameters
task:Runnable

the task to invoke

Exceptions
IllegalArgumentException:
if the receiptId is null
addReceiptTaskback to summary
public void addReceiptTask(Consumer<StompHeaders> task)

Variant of addReceiptTask(Runnable) with a Consumer of the headers from the RECEIPT frame.

Parameters
task:Consumer<StompHeaders>

the consumer to invoke

Exceptions
IllegalArgumentException:
if the receiptId is null
Since
5.3.23
getReceiptIdback to summary
public String getReceiptId()

Return the receipt id, or null if the STOMP frame for which the handle was returned did not have a "receipt" header.

Annotations
@Nullable
org.springframework.messaging.simp.stomp back to summary

public Interface StompSession.Subscription

extends Receiptable
Known Direct Implementers
org.springframework.messaging.simp.stomp.DefaultStompSession.DefaultSubscription

A handle to use to unsubscribe or to track a receipt.

Method Summary

Modifier and TypeMethod and Description
public StompHeaders
getSubscriptionHeaders()

Return the headers used on the SUBSCRIBE frame.

public String
getSubscriptionId()

Return the id for the subscription.

public void
unsubscribe()

Remove the subscription by sending an UNSUBSCRIBE frame.

public void
unsubscribe(StompHeaders
the custom headers, if any
headers
)

Alternative to unsubscribe() with additional custom headers to send to the server.

Inherited from org.springframework.messaging.simp.stomp.StompSession.Receiptable:
addReceiptLostTaskaddReceiptTaskaddReceiptTaskgetReceiptId

Method Detail

getSubscriptionHeadersback to summary
public StompHeaders getSubscriptionHeaders()

Return the headers used on the SUBSCRIBE frame.

Since
5.0
getSubscriptionIdback to summary
public String getSubscriptionId()

Return the id for the subscription.

Annotations
@Nullable
unsubscribeback to summary
public void unsubscribe()

Remove the subscription by sending an UNSUBSCRIBE frame.

unsubscribeback to summary
public void unsubscribe(StompHeaders headers)

Alternative to unsubscribe() with additional custom headers to send to the server.

Note

There is no need to set the subscription id.

Parameters
headers:StompHeaders

the custom headers, if any

Since
5.0