subscribeOptional

suspend fun <T : Any> StompSessionWithClassConversions.subscribeOptional(destination: String, clazz: KClass<T>): Flow<T?>
inline suspend fun <T : Any> StompSessionWithClassConversions.subscribeOptional(destination: String): Flow<T?>

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 or null, but the exact conversion is implementation-dependent. Message frames without a body MAY be skipped or result in an exception depending on the implementation, they don't have to be translated into null values. Conversely, message frames with a non-empty body may result in null values in the flow depending on the implementation.

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

Sources

Link copied to clipboard
Link copied to clipboard