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")
})
Content copied to clipboard
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.