Interface Subscription


public interface Subscription
Represents an active subscription to a messaging channel.

Subscriptions are returned by the various subscribe methods in MessagingService and can be used to check status or cancel the subscription.

Lifecycle

  • Subscriptions are active immediately after creation
  • Calling unsubscribe() permanently deactivates the subscription
  • Subscriptions may become inactive if the messaging service disconnects

Example

// Create a subscription
Subscription sub = messaging.subscribe(Channels.CHAT, handler);

// Check if active
if (sub.isActive()) {
    logger.info("Listening on channel: {}", sub.getChannel());
}

// Cancel when done
sub.unsubscribe();
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the channel this subscription is for.
    boolean
    Check if this subscription is still active.
    void
    Cancel this subscription.
  • Method Details

    • getChannel

      @Nonnull MessageChannel getChannel()
      Get the channel this subscription is for.
      Returns:
      the subscribed channel
    • isActive

      boolean isActive()
      Check if this subscription is still active.

      A subscription becomes inactive when:

      • unsubscribe() is called
      • The messaging service disconnects
      • The subscription is removed by the service
      Returns:
      true if active and receiving messages
    • unsubscribe

      void unsubscribe()
      Cancel this subscription.

      After calling this method, no more messages will be delivered to the associated handler. This operation is idempotent - calling it multiple times has no additional effect.