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"))
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Flow<T> messages
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Flow<T> getMessages()
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • 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.