Interface ReactiveSubscription


public interface ReactiveSubscription
Subscription for Redis channels using reactive infrastructure. A ReactiveSubscription allows subscribing to channels and patterns. It provides access to the ReactiveSubscription.ChannelMessage stream that emits only messages for channels and patterns registered in this ReactiveSubscription.

A reactive Redis connection can have multiple subscriptions. If two or more subscriptions subscribe to the same target (channel/pattern) and one unsubscribes, then the other one will no longer receive messages for the target due to how Redis handled Pub/Sub subscription.

Since:
2.1
Author:
Mark Paluch, Christoph Strobl
  • Method Details

    • subscribe

      reactor.core.publisher.Mono<Void> subscribe(ByteBuffer... channels)
      Subscribes to the channels and adds these to the current subscription.
      Parameters:
      channels - channel names. Must not be empty.
      Returns:
      empty Mono that completes once the channel subscription is registered.
    • pSubscribe

      reactor.core.publisher.Mono<Void> pSubscribe(ByteBuffer... patterns)
      Subscribes to the channel patterns and adds these to the current subscription.
      Parameters:
      patterns - channel patterns. Must not be empty.
      Returns:
      empty Mono that completes once the pattern subscription is registered.
    • unsubscribe

      reactor.core.publisher.Mono<Void> unsubscribe()
      Cancels the current subscription for all channels.
      Returns:
      empty Mono that completes once the channel subscriptions are unregistered.
    • unsubscribe

      reactor.core.publisher.Mono<Void> unsubscribe(ByteBuffer... channels)
      Cancels the current subscription for all given channels.
      Parameters:
      channels - channel names. Must not be empty.
      Returns:
      empty Mono that completes once the channel subscriptions are unregistered.
    • pUnsubscribe

      reactor.core.publisher.Mono<Void> pUnsubscribe()
      Cancels the subscription for all channels matched by getPatterns() patterns}.
      Returns:
      empty Mono that completes once the patterns subscriptions are unregistered.
    • pUnsubscribe

      reactor.core.publisher.Mono<Void> pUnsubscribe(ByteBuffer... patterns)
      Cancels the subscription for all channels matching the given patterns.
      Parameters:
      patterns - must not be empty.
      Returns:
      empty Mono that completes once the patterns subscriptions are unregistered.
    • getChannels

      Set<ByteBuffer> getChannels()
      Returns the (named) channels for this subscription.
      Returns:
      Set of named channels.
    • getPatterns

      Set<ByteBuffer> getPatterns()
      Returns the channel patters for this subscription.
      Returns:
      Set of channel patterns.
    • receive

      reactor.core.publisher.Flux<ReactiveSubscription.Message<ByteBuffer,ByteBuffer>> receive()
      Retrieve the message stream emitting messages. The resulting message stream contains only messages for subscribed and registered channels and patterns.

      Stream publishing uses ConnectableFlux turning the stream into a hot sequence. Emission is paused if there is no demand. Messages received in that time are buffered. This stream terminates either if all subscribers unsubscribe or if this Subscription is is terminated.

      Returns:
      Flux emitting the ReactiveSubscription.Message stream.
    • cancel

      reactor.core.publisher.Mono<Void> cancel()
      Unsubscribe from all channels and patterns and request termination of all active message streams. Active streams will terminate with a CancellationException.
      Returns:
      a Mono that completes once termination is finished.