Interface Subscription

All Superinterfaces:
AutoCloseable

public interface Subscription extends AutoCloseable
A live consumer registration. Closing it stops delivery.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Stops delivery without waiting for anything in flight.
    void
    Stops delivery and releases broker resources.
    boolean
     
     
    default void
    setPrefetch(int prefetch)
    Changes how many unsettled deliveries this subscription may hold.
  • Method Details

    • queue

      String queue()
      Returns:
      the queue being consumed
    • isActive

      boolean isActive()
      Returns:
      whether the subscription is still receiving deliveries
    • setPrefetch

      default void setPrefetch(int prefetch)
      Changes how many unsettled deliveries this subscription may hold.

      Takes effect for deliveries after the call; messages already in flight are unaffected, because they have been sent. That is the protocol's behaviour, not a shortcut — there is no way to un-send them.

      The default refuses. A transport that silently ignored a prefetch change would leave an operator watching a number that says one thing while the consumer does another, which is worse than an error.

      Parameters:
      prefetch - the new limit, at least 1
      Throws:
      TransportException - if this transport cannot change prefetch on a live subscription
    • cancel

      default void cancel()
      Stops delivery without waiting for anything in flight.

      Separate from close() because the two answer different questions. Closing releases resources and lets in-flight deliveries settle, which means it may block for as long as a handler runs. Cancelling only tells the broker to stop sending — it returns at once, and whatever is already in a handler carries on.

      That distinction is what makes a bounded drain possible: stop delivery immediately, wait for in-flight work on the caller's own timeout, and close afterwards. Without it a drain given three hundred milliseconds would block for as long as the close did, and the timeout would be a decoration.

      The default closes, which is correct but not bounded.

    • close

      void close()
      Stops delivery and releases broker resources.

      Implementations should let in-flight deliveries finish settling rather than abandoning them, so a clean shutdown does not manufacture redeliveries.

      Specified by:
      close in interface AutoCloseable