Class RedisMessageSendingTemplate
- All Implemented Interfaces:
RedisMessageSendingOperations, DestinationResolvingMessageSendingOperations<ChannelTopic>, MessageSendingOperations<ChannelTopic>
RedisOperations.
This template bridges Spring Messaging's Message abstraction to Redis Pub/Sub. Destinations are resolved through a DestinationResolver backed by a TopicResolver, and channel names
are written by using a String serializer.
In contrast to RedisOperations.convertAndSend(String, Object), which uses the configured value serializer of
the underlying RedisOperations, this template delegates payload conversion to a MessageConverter. The
default converter is created through RedisMessageConverters.createMessageConverter() and selects a suitable
conversion strategy according to the payload type and, if present, the
contentType header.
Redis Pub/Sub transmits only the serialized message body. Message headers participate in conversion before publication and are not written to Redis.
- Since:
- 4.1
- Author:
- Mark Paluch
- See Also:
-
Field Summary
Fields inherited from class AbstractMessageSendingTemplate
CONVERSION_HINT_HEADER, logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionRedisMessageSendingTemplate(RedisOperations<?, ?> redisOperations) Create a newRedisMessageSendingTemplatefor the givenRedisOperations.protectedRedisMessageSendingTemplate(RedisOperations<?, ?> redisOperations, RedisSerializer<String> stringSerializer) -
Method Summary
Modifier and TypeMethodDescription<T> voidconvertAndSend(String destinationName, T payload) <T> voidconvertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers) <T> voidconvertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) <T> voidconvertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor) protected voiddoSend(ChannelTopic destination, Message<?> message) @Nullable DestinationResolver<ChannelTopic> Return the configured destination resolver.protected final ChannelTopicresolveDestination(String destinationName) voidvoidsetDestinationResolver(@Nullable DestinationResolver<ChannelTopic> destinationResolver) Configure theDestinationResolverto use to resolve String destination names into actual destinations of typeChannelTopic.Methods inherited from class AbstractMessageSendingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, send, setDefaultDestination, setMessageConverterMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageSendingOperations
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send, send
-
Constructor Details
-
RedisMessageSendingTemplate
Create a newRedisMessageSendingTemplatefor the givenRedisOperations.Uses the configured string
RedisSerializerofRedisTemplate, if available, and otherwise falls back toRedisSerializer.string()for channel serialization.- Parameters:
redisOperations- the Redis operations to use. Must not be null.
-
RedisMessageSendingTemplate
protected RedisMessageSendingTemplate(RedisOperations<?, ?> redisOperations, RedisSerializer<String> stringSerializer)
-
-
Method Details
-
setDestinationResolver
Configure theDestinationResolverto use to resolve String destination names into actual destinations of typeChannelTopic.Defaults to a
TopicDestinationResolverbacked byTopicResolver.channel(). Set this property to null only if destination-name based operations are not used.- Parameters:
destinationResolver- the destination resolver to use.
-
getDestinationResolver
Return the configured destination resolver.- Returns:
- the configured destination resolver.
-
send
- Specified by:
sendin interfaceDestinationResolvingMessageSendingOperations<ChannelTopic>- Throws:
MessagingException
-
convertAndSend
- Specified by:
convertAndSendin interfaceDestinationResolvingMessageSendingOperations<ChannelTopic>- Throws:
MessagingException
-
convertAndSend
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers) throws MessagingException- Specified by:
convertAndSendin interfaceDestinationResolvingMessageSendingOperations<ChannelTopic>- Throws:
MessagingException
-
convertAndSend
public <T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException - Specified by:
convertAndSendin interfaceDestinationResolvingMessageSendingOperations<ChannelTopic>- Throws:
MessagingException
-
convertAndSend
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingException- Specified by:
convertAndSendin interfaceDestinationResolvingMessageSendingOperations<ChannelTopic>- Throws:
MessagingException
-
doSend
- Specified by:
doSendin classAbstractMessageSendingTemplate<ChannelTopic>
-
resolveDestination
-