Subscriber

Subscriber

A subscriber that allows listening to updates on a key expression and reacting to changes.

Simple example using a callback to handle the received samples:

val session = Session.open(Config.default()).getOrThrow()
val keyexpr = "a/b/c".intoKeyExpr().getOrThrow()
session.declareSubscriber(keyexpr, callback = { sample ->
println(">> [Subscriber] Received $sample")
})

Lifespan

Internally, the Session from which the Subscriber was declared keeps a reference to it, therefore keeping it alive until the session is closed. For the cases where we want to stop the subscriber earlier, it's necessary to keep a reference to it in order to undeclare it later.

Parameters

R

Receiver type of the Handler implementation.

See also

Properties

Link copied to clipboard

The KeyExpr to which the subscriber is associated.

Link copied to clipboard
val receiver: R

Optional R that is provided when specifying a Handler for the subscriber.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
Link copied to clipboard
open override fun undeclare()

Undeclare a declaration. No further operations should be performed after calling this function.