Class SubscriptionHandle
-
- All Implemented Interfaces:
public final class SubscriptionHandle<T extends Object>One subscription, and the rendezvous that tells you it exists.
messages is cold: the subscription is made when it is collected, and ends when the collector does. What a second collection does belongs to whatever handed the handle over, and the two answers differ. A core-NATS subscription is a single subscription rather than a factory for them, so collecting messages twice throws IllegalStateException - subscribe again for a second subscriber, which is also how fan-out is expressed, a handle per collector. A JetStream subscription re-runs consumer setup instead, re-attaching or replaying depending on whether the consumer is named; eu.vstoyanov.natsy.jetstream.JetStreamContext.subscribe says which.
val orders = subscribe<OrderEvent>("orders") launch { orders.messages.collect { ... } } orders.started() publish("orders", OrderEvent("no race"))
-
-
Method Summary
Modifier and Type Method Description final Flow<T>getMessages()final Unitstarted(Duration timeout)Suspends until this subscription is live on the server: until messages has been collected, registering the SUB, and until the server has acknowledged it.-
-
Method Detail
-
getMessages
final Flow<T> getMessages()
-
started
final Unit started(Duration timeout)
Suspends until this subscription is live on the server: until messages has been collected, registering the
SUB, and until the server has acknowledged it. Anything published after this returns reaches this subscriber - from any connection, not only this klient's.It answers for the collection that establishes the subscription, which for a handle that can be collected more than once is the first one.
- Parameters:
timeout- How long to wait for the server to acknowledge the subscription.
-
-
-
-