subscribe
Subscribes and returns a Flow of MESSAGE frames that unsubscribes automatically when the collector is done or cancelled. The returned flow can be collected only once.
The subscription happens immediately by sending a SUBSCRIBE frame with the provided headers. If no subscription ID is provided in the headers, a generated ID is used in the SUBSCRIBE frame.
If no receipt
header is provided and auto-receipt is enabled, a new unique receipt
header is generated and added to the SUBSCRIBE frame.
If a receipt
header is present (automatically added or manually provided), this method suspends until the corresponding RECEIPT frame is received from the server. If no RECEIPT frame is received in the configured time limit, a LostReceiptException is thrown.
If auto-receipt is disabled and no receipt
header is provided, this method doesn't wait for a RECEIPT frame and never throws LostReceiptException. Instead, it returns immediately after sending the SUBSCRIBE frame. This means that, in this case, there is no real guarantee that the subscription actually happened when this method returns.
The unsubscription happens by sending an UNSUBSCRIBE frame when the flow collector's coroutine is cancelled, or when a terminal operator such as Flow.first completes the flow from the consumer's side.
See the general StompSession documentation for more details about subscription flows, suspension and receipts.