install
block by setting the supported
properties of the
SSEConfig
- class:
+ class.
- retry
field in the incoming flow.
-
- In the following example, the SSE plugin is installed into the HTTP client and configured to include events
- that only contain comments and those that contain only the retry
field in the incoming flow:
-
Limitations: not supported with the OkHttp
engine.
+ To enable automatic reconnection with supported engines, set
+ maxReconnectionAttempts
to a value greater than 0
. You can also configure the
+ delay between attempts using reconnectionTime
:
+
+ If the connection to the server is lost, the client will wait for the specified
+ reconnectionTime
before attempting to reconnect. It will make up to
+ the specified number of maxReconnectionAttempts
attempts to reestablish the connection.
+
+ In the following example, the SSE plugin is installed into the HTTP client and configured to include events
+ that only contain comments and those that contain only the retry
field in the incoming flow:
+
From 393ec5f3183597b60dbc36474c862a3d079bfa1c Mon Sep 17 00:00:00 2001
From: Viktoriya Nikolova
Limitations: not supported with the OkHttp
engine.
️️Not supported on: OkHttp
To enable automatic reconnection with supported engines, set
@@ -76,28 +76,34 @@
that only contain comments and those that contain only the retry
field in the incoming flow:
A client's SSE session is represented by the
- DefaultClientSSESession
+
+ ClientSSESession
+
interface. This interface exposes the API that allows you to receive server-sent events from a server.
The HttpClient
allows you to get access to an SSE session in one of the following ways:
sse()
+
function creates the SSE session and allows you to act on it.
sseSession()
+
function allows you to open an SSE session.
The following parameters are available to both functions. To specify the URL endpoint, choose from two - options:
+To specify the URL endpoint, you can choose from two options:
urlString
parameter to specify the whole URL as a string.schema
, host
, port
, and path
parameters
@@ -146,8 +152,6 @@
An incoming server-sent events flow.
-
-
The example below creates a new SSE session with the events
endpoint,
reads events through the incoming
property and prints the received
@@ -155,11 +159,32 @@
.
For the full example, see + client-sse. +
++ The SSE plugin supports deserialization of server-sent events into type-safe Kotlin objects. This + feature is particularly useful when working with structured data from the server. +
+
+ To enable deserialization, provide a custom deserialization function using the deserialize
+ parameter on an SSE access function and use the
+
+ ClientSSESessionWithDeserialization
+
+ class to handle the deserialized events.
+
+ Here's an example using kotlinx.serialization
to deserialize JSON data:
+
For the full example, see client-sse.
Within the sse
block, you define the handler for the specified path, represented by the
- ServerSSESession
+
+ ServerSSESession
+
class. The following functions and properties are available within the block:
For the full example, see + server-sse. +
+
+ To enable serialization, provide a custom serialization function using the serialize
+ parameter on an SSE route. Inside the handler, you can use the
+
+ ServerSSESessionWithSerialization
+
+ class to send serialized events:
+
+ The serialize
function is responsible for converting data objects into JSON, which is then
+ placed in the data
field of a ServerSentEvent
.
+
For the full example, see server-sse.
From 2f1b36cf3819e6a23109c8f6f5caa381d8feaafe Mon Sep 17 00:00:00 2001 From: Viktoriya NikolovaFor the full example, see server-sse.
+ Heartbeats ensure the SSE connection stays active during periods of inactivity by periodically sending + events. As long as the session remains active, the server will send the specified event at the + configured interval. +
+
+ To enable and configure a heartbeat, use the
+
+ .heartbeat()
+
+ function within an SSE route handler:
+
+ In this example, a heartbeat event is sent every 10 milliseconds to maintain the + connection. +
+
To enable serialization, provide a custom serialization function using the serialize
@@ -138,7 +158,7 @@
class to send serialized events:
The serialize
function is responsible for converting data objects into JSON, which is then
placed in the data
field of a ServerSentEvent
.
From 7ffc3842a1963d5d5ed3208d9168e9c1cd559983 Mon Sep 17 00:00:00 2001
From: Viktoriya Nikolova
️️Not supported on: OkHttp
️️Not supported in: OkHttp
To enable automatic reconnection with supported engines, set @@ -67,7 +67,7 @@
If the connection to the server is lost, the client will wait for the specified
reconnectionTime
before attempting to reconnect. It will make up to
- the specified number of maxReconnectionAttempts
attempts to reestablish the connection.
+ the specified maxReconnectionAttempts
to reestablish the connection.
retry
field in the incoming
flow.
+ data
field of the
+ TypedServerSentEvent
into an object. For more information, see
+ .
+
- The serialize
function is responsible for converting data objects into JSON, which is then
+ The serialize
function in this example is responsible for converting data objects into JSON, which is then
placed in the data
field of a ServerSentEvent
.
For the full example, see