Class RedisStoreWritingMessageHandler
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>,Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,Ordered,ExpressionCapable,Orderable,IntegrationPattern,NamedComponent,IntegrationManagement,TrackableComponent,MessageHandler,reactor.core.CoreSubscriber<Message<?>>
MessageHandler which writes
Message data into a Redis store identified by a key String.
It supports the collection types identified by RedisCollectionFactoryBean.CollectionType.
It supports batch updates or single item entry.
"Batch updates" means that the payload of the Message may be a Map or Collection. With
such a payload, individual items from it are added to the corresponding Redis store.
See handleMessageInternal(Message) for more details.
You can instead choose to persist such a payload as a single item if the
extractPayloadElements property is set to false (default is true).- Since:
- 2.2
- Author:
- Oleg Zhurakousky, Gary Russell, Mark Fisher, Artem Bilan, Trung Pham
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionRedisStoreWritingMessageHandler(RedisConnectionFactory connectionFactory) Constructs an instance using the providedRedisConnectionFactory.RedisStoreWritingMessageHandler(RedisTemplate<String, ?> redisTemplate) Constructs an instance using the providedRedisTemplate. -
Method Summary
Modifier and TypeMethodDescriptionSubclasses may implement this method to provide component type information.protected voidhandleMessageInternal(Message<?> message) Will extract the payload from the Message and store it in the collection identified by the key (which may be determined by an expression).protected voidonInit()Subclasses may implement this for initialization logic.voidsetCollectionType(RedisCollectionFactoryBean.CollectionType collectionType) Sets the collection type for this handler as perRedisCollectionFactoryBean.CollectionType.voidsetExtractPayloadElements(boolean extractPayloadElements) Sets the flag signifying that if the payload is a "multivalue" (i.e., Collection or Map), it should be saved using addAll/putAll semantics.voidSpecifies the key for the Redis store.voidsetKeyExpression(Expression keyExpression) Specifies a SpEL Expression to be used to determine the key for the Redis store.voidsetKeyExpressionString(String keyExpression) Specifies a SpEL Expression to be used to determine the key for the Redis store.voidsetMapKeyExpression(Expression mapKeyExpression) Sets the expression used as the key for Map and Properties entries.voidsetMapKeyExpressionString(String mapKeyExpression) Sets the expression used as the key for Map and Properties entries.voidsetZsetIncrementExpression(Expression zsetIncrementScoreExpression) Set the expression used as the INCR flag for the ZADD command in case of ZSet collection.voidsetZsetIncrementExpressionString(String zsetIncrementScoreExpression) Set the expression used as the INCR flag for the ZADD command in case of ZSet collection.Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
RedisStoreWritingMessageHandler
Constructs an instance using the providedRedisTemplate. The RedisTemplate must be fully initialized.- Parameters:
redisTemplate- The Redis template.
-
RedisStoreWritingMessageHandler
Constructs an instance using the providedRedisConnectionFactory. It will use either aStringRedisTemplateifextractPayloadElementsis true (default) or aRedisTemplatewithStringRedisSerializers for keys and hash keys andJdkSerializationRedisSerializers for values and hash values, when it is false.- Parameters:
connectionFactory- The connection factory.- See Also:
-
-
Method Details
-
setKey
Specifies the key for the Redis store. If an expression is needed, then callsetKeyExpression(Expression)instead of this method (they are mutually exclusive). If neither setter is called, the default expression will be 'headers.RedisHeaders.KEY'.- Parameters:
key- The key.- See Also:
-
setKeyExpressionString
Specifies a SpEL Expression to be used to determine the key for the Redis store. If an expression is not needed, then a literal value may be passed to thesetKey(String)method instead of this one (they are mutually exclusive). If neither setter is called, the default expression will be 'headers.RedisHeaders.KEY'.- Parameters:
keyExpression- The key expression.- Since:
- 5.0
- See Also:
-
setKeyExpression
Specifies a SpEL Expression to be used to determine the key for the Redis store. If an expression is not needed, then a literal value may be passed to thesetKey(String)method instead of this one (they are mutually exclusive). If neither setter is called, the default expression will be 'headers.RedisHeaders.KEY'.- Parameters:
keyExpression- The key expression.- See Also:
-
setCollectionType
Sets the collection type for this handler as perRedisCollectionFactoryBean.CollectionType.- Parameters:
collectionType- The collection type.
-
setExtractPayloadElements
public void setExtractPayloadElements(boolean extractPayloadElements) Sets the flag signifying that if the payload is a "multivalue" (i.e., Collection or Map), it should be saved using addAll/putAll semantics. Default is 'true'. If set to 'false' the payload will be saved as a single entry regardless of its type. If the payload is not an instance of "multivalue" (i.e., Collection or Map), the value of this attribute is meaningless as the payload will always be stored as a single entry.- Parameters:
extractPayloadElements- true if payload elements should be extracted.
-
setMapKeyExpressionString
Sets the expression used as the key for Map and Properties entries. Default is 'headers.RedisHeaders.MAP_KEY'- Parameters:
mapKeyExpression- The map key expression.- Since:
- 5.0
-
setMapKeyExpression
Sets the expression used as the key for Map and Properties entries. Default is 'headers.RedisHeaders.MAP_KEY'- Parameters:
mapKeyExpression- The map key expression.
-
setZsetIncrementExpressionString
Set the expression used as the INCR flag for the ZADD command in case of ZSet collection. Default is 'headers.RedisHeaders.ZSET_INCREMENT_SCORE'- Parameters:
zsetIncrementScoreExpression- The ZADD INCR flag expression.- Since:
- 5.0
-
setZsetIncrementExpression
Set the expression used as the INCR flag for the ZADD command in case of ZSet collection. Default is 'headers.RedisHeaders.ZSET_INCREMENT_SCORE'- Parameters:
zsetIncrementScoreExpression- The ZADD INCR flag expression.- Since:
- 5.0
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
handleMessageInternal
Will extract the payload from the Message and store it in the collection identified by the key (which may be determined by an expression). The type of collection is specified by thecollectionTypeproperty. The default CollectionType is LIST.The rules for storing the payload are:
LIST/SET If the payload is of type Collection and
extractPayloadElementsis 'true' (default), the payload will be added using the addAll() method. IfextractPayloadElementsis set to 'false', then regardless of the payload type, the payload will be added using add().ZSET In addition to the rules described for LIST/SET, ZSET allows 'score' information to be provided. The score can be provided using the
RedisHeaders.ZSET_SCOREmessage header when the payload is not a Map, or by sending a Map as the payload where each Map 'key' is a value to be saved and each corresponding Map 'value' is the score assigned to it. IfextractPayloadElementsis set to 'false' the map will be stored as a single entry. If the 'score' can not be determined, the default value (1) will be used.MAP/PROPERTIES You can also add items to a Map or Properties based store. If the payload itself is of type Map or Properties, it can be stored either as a batch or single item following the same rules as described above for other collection types. If the payload itself needs to be stored as a value of the map/property then the map key must be specified via the mapKeyExpression (default
RedisHeaders.MAP_KEYMessage header).- Specified by:
handleMessageInternalin classAbstractMessageHandler
-