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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classValue object for a Redis channel message.static interfaceReactiveSubscription.Messagerepresents a Redis channel message within Redis pub/sub.static classValue object for a Redis channel message received from a pattern subscription. -
Method Summary
Modifier and TypeMethodDescriptioncancel()Returns the (named) channels for this subscription.Returns the channel patters for this subscription.pSubscribe(ByteBuffer... patterns) Subscribes to the channelpatternsand adds these to the current subscription.Cancels the subscription for all channels matched bygetPatterns()patterns}.pUnsubscribe(ByteBuffer... patterns) Cancels the subscription for all channels matching the given patterns.receive()Retrieve the message stream emittingmessages.subscribe(ByteBuffer... channels) Subscribes to thechannelsand adds these to the current subscription.Cancels the current subscription for allchannels.unsubscribe(ByteBuffer... channels) Cancels the current subscription for all given channels.
-
Method Details
-
subscribe
Subscribes to thechannelsand adds these to the current subscription.- Parameters:
channels- channel names. Must not be empty.- Returns:
- empty
Monothat completes once the channel subscription is registered.
-
pSubscribe
Subscribes to the channelpatternsand adds these to the current subscription.- Parameters:
patterns- channel patterns. Must not be empty.- Returns:
- empty
Monothat completes once the pattern subscription is registered.
-
unsubscribe
Cancels the current subscription for allchannels.- Returns:
- empty
Monothat completes once the channel subscriptions are unregistered.
-
unsubscribe
Cancels the current subscription for all given channels.- Parameters:
channels- channel names. Must not be empty.- Returns:
- empty
Monothat completes once the channel subscriptions are unregistered.
-
pUnsubscribe
Cancels the subscription for all channels matched bygetPatterns()patterns}.- Returns:
- empty
Monothat completes once the patterns subscriptions are unregistered.
-
pUnsubscribe
Cancels the subscription for all channels matching the given patterns.- Parameters:
patterns- must not be empty.- Returns:
- empty
Monothat completes once the patterns subscriptions are unregistered.
-
getChannels
Set<ByteBuffer> getChannels()Returns the (named) channels for this subscription.- Returns:
Setof named channels.
-
getPatterns
Set<ByteBuffer> getPatterns()Returns the channel patters for this subscription.- Returns:
Setof channel patterns.
-
receive
Flux<ReactiveSubscription.Message<ByteBuffer,ByteBuffer>> receive()Retrieve the message stream emittingmessages. The resulting message stream contains only messages for subscribed and registeredchannelsandpatterns.Stream publishing uses
ConnectableFluxturning 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 thisSubscriptionisis terminated.- Returns:
Fluxemitting theReactiveSubscription.Messagestream.
-
cancel
Unsubscribe from allchannelsandpatternsand request termination of all activemessage streams. Active streams will terminate with aCancellationException.- Returns:
- a
Monothat completes once termination is finished.
-