sse
Opens a ClientSSESession to receive Server-Sent Events (SSE) from a server and performs block.
Parameters
The time duration to wait before attempting reconnection in case of connection loss
When enabled, events containing only comments field will be presented in the incoming flow
When enabled, events containing only comments field will be presented in the incoming flow
Example of usage:
client.sse("http://localhost:8080/sse") { // `this` is `ClientSSESession`
incoming.collect { event ->
println("Id: ${event.id}")
println("Event: ${event.event}")
println("Data: ${event.data}")
}
}
Opens a ClientSSESessionWithDeserialization to receive Server-Sent Events (SSE) from a server with ability to deserialize the data
field of the TypedServerSentEvent
and performs block.
Parameters
The deserializer function to transform the data
field of the TypedServerSentEvent
into an object
The time duration to wait before attempting reconnection in case of connection loss
When enabled, events containing only comments field will be presented in the incoming flow
When enabled, events containing only comments field will be presented in the incoming flow
Example of usage:
client.sse({
url("http://localhost:8080/sse")
}, deserialize = {
typeInfo, jsonString ->
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
Json.decodeFromString(serializer, jsonString)!!
}) { // `this` is `ClientSSESessionWithDeserialization`
incoming.collect { event: TypedServerSentEvent<String> ->
when (event.event) {
"customer" -> {
val customer: Customer? = deserialize<Customer>(event.data)
}
"product" -> {
val product: Product? = deserialize<Product>(event.data)
}
}
}
}