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
Modifier 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 TypeMethodDescriptionreactor.core.publisher.Mono<Void>
cancel()
Returns the (named) channels for this subscription.Returns the channel patters for this subscription.reactor.core.publisher.Mono<Void>
pSubscribe
(ByteBuffer... patterns) Subscribes to the channelpatterns
and adds these to the current subscription.reactor.core.publisher.Mono<Void>
Cancels the subscription for all channels matched bygetPatterns()
patterns}.reactor.core.publisher.Mono<Void>
pUnsubscribe
(ByteBuffer... patterns) Cancels the subscription for all channels matching the given patterns.reactor.core.publisher.Flux<ReactiveSubscription.Message<ByteBuffer,
ByteBuffer>> receive()
Retrieve the message stream emittingmessages
.reactor.core.publisher.Mono<Void>
subscribe
(ByteBuffer... channels) Subscribes to thechannels
and adds these to the current subscription.reactor.core.publisher.Mono<Void>
Cancels the current subscription for allchannels
.reactor.core.publisher.Mono<Void>
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
reactor.core.publisher.Mono<Void> 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
reactor.core.publisher.Mono<Void> 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
reactor.core.publisher.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
reactor.core.publisher.Mono<Void> 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.
-