subscribeOptional

abstract suspend fun <T : Any> subscribeOptional(headers: StompSubscribeHeaders, deserializer: DeserializationStrategy<T>): Flow<T?>(source)

Subscribes and returns a Flow of messages of type T that unsubscribes automatically when the collector is done or cancelled. The returned flow can be collected only once.

The received MESSAGE frames are converted to instances of T using the provided Kotlinx Serialization's deserializer. Message frames without a body are allowed and result in null values in the flow.

See the general StompSession documentation for more details about subscription flows and receipts.