/** * Subscribe to one or more {@link Topic}s and receive a stream of {@link ChannelMessage} The stream may contain * {@link PatternMessage} if subscribed to patterns. Messages, and channel names are serialized/deserialized using the * given {@code channelSerializer} and {@code messageSerializer}. The message stream subscribes lazily to the Redis * channels and unsubscribes if the {@link org.reactivestreams.Subscription} is * {@link org.reactivestreams.Subscription#cancel() cancelled}. * * @param topics the channels to subscribe. * @return the message stream. * @see #receive(Iterable, SerializationPair, SerializationPair) * @throws InvalidDataAccessApiUsageException if {@code topics} is empty. */ public <C, B> Flux<Message<C, B>> receive(Iterable<? extends Topic> topics, SerializationPair<C> channelSerializer, SerializationPair<B> messageSerializer) { Assert.notNull(topics, "Topics must not be null!"); verifyConnection(); ByteBuffer[] patterns = getTargets(topics, PatternTopic.class); ByteBuffer[] channels = getTargets(topics, ChannelTopic.class); if (ObjectUtils.isEmpty(patterns) && ObjectUtils.isEmpty(channels)) { throw new InvalidDataAccessApiUsageException("No channels or patterns to subscribe to."); } return doReceive(channelSerializer, messageSerializer, connection.pubSubCommands().createSubscription(), patterns, channels); }
/** * Subscribe to one or more {@link Topic}s and receive a stream of {@link ChannelMessage} The stream may contain * {@link PatternMessage} if subscribed to patterns. Messages, and channel names are serialized/deserialized using the * given {@code channelSerializer} and {@code messageSerializer}. The message stream subscribes lazily to the Redis * channels and unsubscribes if the {@link org.reactivestreams.Subscription} is * {@link org.reactivestreams.Subscription#cancel() cancelled}. * * @param topics the channels to subscribe. * @return the message stream. * @see #receive(Iterable, SerializationPair, SerializationPair) * @throws InvalidDataAccessApiUsageException if {@code topics} is empty. */ public <C, B> Flux<Message<C, B>> receive(Iterable<? extends Topic> topics, SerializationPair<C> channelSerializer, SerializationPair<B> messageSerializer) { Assert.notNull(topics, "Topics must not be null!"); verifyConnection(); ByteBuffer[] patterns = getTargets(topics, PatternTopic.class); ByteBuffer[] channels = getTargets(topics, ChannelTopic.class); if (ObjectUtils.isEmpty(patterns) && ObjectUtils.isEmpty(channels)) { throw new InvalidDataAccessApiUsageException("No channels or patterns to subscribe to."); } return doReceive(channelSerializer, messageSerializer, connection.pubSubCommands().createSubscription(), patterns, channels); }
/** * Subscribe to one or more {@link Topic}s and receive a stream of {@link ChannelMessage} The stream may contain * {@link PatternMessage} if subscribed to patterns. Messages, and channel names are serialized/deserialized using the * given {@code channelSerializer} and {@code messageSerializer}. The message stream subscribes lazily to the Redis * channels and unsubscribes if the {@link org.reactivestreams.Subscription} is * {@link org.reactivestreams.Subscription#cancel() cancelled}. * * @param topics the channels to subscribe. * @return the message stream. * @see #receive(Iterable, SerializationPair, SerializationPair) * @throws InvalidDataAccessApiUsageException if {@code topics} is empty. */ public <C, B> Flux<Message<C, B>> receive(Iterable<? extends Topic> topics, SerializationPair<C> channelSerializer, SerializationPair<B> messageSerializer) { Assert.notNull(topics, "Topics must not be null!"); verifyConnection(); ByteBuffer[] patterns = getTargets(topics, PatternTopic.class); ByteBuffer[] channels = getTargets(topics, ChannelTopic.class); if (ObjectUtils.isEmpty(patterns) && ObjectUtils.isEmpty(channels)) { throw new InvalidDataAccessApiUsageException("No channels or patterns to subscribe to."); } return doReceive(channelSerializer, messageSerializer, connection.pubSubCommands().createSubscription(), patterns, channels); }