Class DefaultStompSession
java.lang.Object
org.springframework.messaging.simp.stomp.DefaultStompSession
- All Implemented Interfaces:
- ConnectionHandlingStompSession,- StompSession,- StompTcpConnectionHandler<byte[]>,- TcpConnectionHandler<byte[]>
Default implementation of 
ConnectionHandlingStompSession.- Since:
- 4.2
- Author:
- Rossen Stoyanchev
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.springframework.messaging.simp.stomp.StompSessionStompSession.Receiptable, StompSession.Subscription
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionDefaultStompSession(StompSessionHandler sessionHandler, StompHeaders connectHeaders) Create a new session.
- 
Method SummaryModifier and TypeMethodDescriptionacknowledge(String messageId, boolean consumed) Send an acknowledgement whether a message was consumed or not resulting in an ACK or NACK frame respectively.acknowledge(StompHeaders headers, boolean consumed) An overloaded version ofStompSession.acknowledge(String, boolean)with fullStompHeadersinstead of just amessageId.voidafterConnected(TcpConnection<byte[]> connection) Invoked after a connection is successfully established.voidInvoked on failure to connect.voidInvoked after the connection is closed.voidDisconnect the session by sending a DISCONNECT frame.voiddisconnect(@Nullable StompHeaders headers) Variant ofStompSession.disconnect()with headers.Return the headers that will be sent in the STOMP CONNECT frame.Return the configuredMessageConverter.longReturn the configured time limit before a receipt expires.Return a future that will complete when the session is ready for use.Return the configured session handler.Return the id for the session.Return the configured TaskScheduler to use for receipt tracking.voidHandle a failure on the connection.voidhandleMessage(Message<byte[]> message) Handle a message received from the remote host.booleanWhether receipt headers should be automatically added.booleanWhether the session is connected.Send a message to the specified destination, converting the payload to abyte[]with the help of aMessageConverter.send(StompHeaders headers, Object payload) An overloaded version ofStompSession.send(String, Object)with fullStompHeadersinstead of just a destination.voidsetAutoReceipt(boolean autoReceiptEnabled) When enabled, a receipt header is automatically added to futuresendandsubscribeoperations on this session, which causes the server to return a RECEIPT.voidsetMessageConverter(MessageConverter messageConverter) Set theMessageConverterto use to convert the payload of incoming and outgoing messages to and frombyte[]based on object type, or expected object type, and the "content-type" header.voidsetReceiptTimeLimit(long receiptTimeLimit) Configure the time in milliseconds before a receipt expires.voidsetTaskScheduler(@Nullable TaskScheduler taskScheduler) Configure the TaskScheduler to use for receipt tracking.subscribe(String destination, StompFrameHandler handler) Subscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specifiedStompFrameHandler.subscribe(StompHeaders headers, StompFrameHandler handler) An overloaded version ofStompSession.subscribe(String, StompFrameHandler)with fullStompHeadersinstead of just a destination.
- 
Field Details- 
EMPTY_PAYLOADpublic static final byte[] EMPTY_PAYLOADAn empty payload.
 
- 
- 
Constructor Details- 
DefaultStompSessionCreate a new session.- Parameters:
- sessionHandler- the application handler for the session
- connectHeaders- headers for the STOMP CONNECT frame
 
 
- 
- 
Method Details- 
getSessionIdDescription copied from interface:StompSessionReturn the id for the session.- Specified by:
- getSessionIdin interface- StompSession
- Specified by:
- getSessionIdin interface- StompTcpConnectionHandler<byte[]>
 
- 
getConnectHeadersDescription copied from interface:StompTcpConnectionHandlerReturn the headers that will be sent in the STOMP CONNECT frame.- Specified by:
- getConnectHeadersin interface- StompTcpConnectionHandler<byte[]>
 
- 
getSessionHandlerReturn the configured session handler.
- 
getSessionDescription copied from interface:ConnectionHandlingStompSessionReturn a future that will complete when the session is ready for use.- Specified by:
- getSessionin interface- ConnectionHandlingStompSession
 
- 
setMessageConverterSet theMessageConverterto use to convert the payload of incoming and outgoing messages to and frombyte[]based on object type, or expected object type, and the "content-type" header.By default, SimpleMessageConverteris configured.- Parameters:
- messageConverter- the message converter to use
 
- 
getMessageConverterReturn the configuredMessageConverter.
- 
setTaskSchedulerConfigure the TaskScheduler to use for receipt tracking.
- 
getTaskSchedulerReturn the configured TaskScheduler to use for receipt tracking.
- 
setReceiptTimeLimitpublic void setReceiptTimeLimit(long receiptTimeLimit) Configure the time in milliseconds before a receipt expires.By default set to 15,000 (15 seconds). 
- 
getReceiptTimeLimitpublic long getReceiptTimeLimit()Return the configured time limit before a receipt expires.
- 
setAutoReceiptpublic void setAutoReceipt(boolean autoReceiptEnabled) Description copied from interface:StompSessionWhen enabled, a receipt header is automatically added to futuresendandsubscribeoperations on this session, which causes the server to return a RECEIPT. An application can then use theReceiptablereturned from the operation to track the receipt.A receipt header can also be added manually through the overloaded methods that accept StompHeaders.- Specified by:
- setAutoReceiptin interface- StompSession
 
- 
isAutoReceiptEnabledpublic boolean isAutoReceiptEnabled()Whether receipt headers should be automatically added.
- 
isConnectedpublic boolean isConnected()Description copied from interface:StompSessionWhether the session is connected.- Specified by:
- isConnectedin interface- StompSession
 
- 
sendDescription copied from interface:StompSessionSend a message to the specified destination, converting the payload to abyte[]with the help of aMessageConverter.- Specified by:
- sendin interface- StompSession
- Parameters:
- destination- the destination to send a message to
- payload- the message payload
- Returns:
- a Receiptable for tracking receipts
 
- 
sendDescription copied from interface:StompSessionAn overloaded version ofStompSession.send(String, Object)with fullStompHeadersinstead 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.- Specified by:
- sendin interface- StompSession
- Parameters:
- headers- the message headers
- payload- the message payload
- Returns:
- a Receiptable for tracking receipts
 
- 
subscribeDescription copied from interface:StompSessionSubscribe to the given destination by sending a SUBSCRIBE frame and handle received messages with the specifiedStompFrameHandler.- Specified by:
- subscribein interface- StompSession
- Parameters:
- destination- the destination to subscribe to
- handler- the handler for received messages
- Returns:
- a handle to use to unsubscribe and/or track receipts
 
- 
subscribeDescription copied from interface:StompSessionAn overloaded version ofStompSession.subscribe(String, StompFrameHandler)with fullStompHeadersinstead of just a destination.- Specified by:
- subscribein interface- StompSession
- Parameters:
- headers- the headers for the subscribed message frame
- handler- the handler for received messages
- Returns:
- a handle to use to unsubscribe and/or track receipts
 
- 
acknowledgeDescription copied from interface:StompSessionSend 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 ackheader to "client" or "client-individual" in order ot use this.- Specified by:
- acknowledgein interface- StompSession
- Parameters:
- messageId- the id of the message
- consumed- whether the message was consumed or not
- Returns:
- a Receiptable for tracking receipts
 
- 
acknowledgeDescription copied from interface:StompSessionAn overloaded version ofStompSession.acknowledge(String, boolean)with fullStompHeadersinstead of just amessageId.- Specified by:
- acknowledgein interface- StompSession
- 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
 
- 
disconnectpublic void disconnect()Description copied from interface:StompSessionDisconnect the session by sending a DISCONNECT frame.- Specified by:
- disconnectin interface- StompSession
 
- 
disconnectDescription copied from interface:StompSessionVariant ofStompSession.disconnect()with headers.- Specified by:
- disconnectin interface- StompSession
- Parameters:
- headers- the headers for the disconnect message frame
 
- 
afterConnectedDescription copied from interface:TcpConnectionHandlerInvoked after a connection is successfully established.- Specified by:
- afterConnectedin interface- TcpConnectionHandler<byte[]>
- Parameters:
- connection- the connection
 
- 
afterConnectFailureDescription copied from interface:TcpConnectionHandlerInvoked on failure to connect.- Specified by:
- afterConnectFailurein interface- TcpConnectionHandler<byte[]>
- Parameters:
- ex- the exception
 
- 
handleMessageDescription copied from interface:TcpConnectionHandlerHandle a message received from the remote host.- Specified by:
- handleMessagein interface- TcpConnectionHandler<byte[]>
- Parameters:
- message- the message
 
- 
handleFailureDescription copied from interface:TcpConnectionHandlerHandle a failure on the connection.- Specified by:
- handleFailurein interface- TcpConnectionHandler<byte[]>
- Parameters:
- ex- the exception
 
- 
afterConnectionClosedpublic void afterConnectionClosed()Description copied from interface:TcpConnectionHandlerInvoked after the connection is closed.- Specified by:
- afterConnectionClosedin interface- TcpConnectionHandler<byte[]>
 
 
-