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 class
Value object for a Redis channel message.static interface
ReactiveSubscription.Message
represents a Redis channel message within Redis pub/sub.static class
Value 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 channelpatterns
and 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 thechannels
and 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 thechannels
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
Subscribes to the channelpatterns
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
Cancels the current subscription for allchannels
.- Returns:
- empty
Mono
that 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
Mono
that completes once the channel subscriptions are unregistered.
-
pUnsubscribe
Cancels the subscription for all channels matched bygetPatterns()
patterns}.- Returns:
- empty
Mono
that 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
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
Flux<ReactiveSubscription.Message<ByteBuffer,ByteBuffer>> receive()Retrieve the message stream emittingmessages
. The resulting message stream contains only messages for subscribed and registeredchannels
andpatterns
.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 thisSubscription
isis terminated
.- Returns:
Flux
emitting theReactiveSubscription.Message
stream.
-
cancel
Unsubscribe from allchannels
andpatterns
and request termination of all activemessage streams
. Active streams will terminate with aCancellationException
.- Returns:
- a
Mono
that completes once termination is finished.
-