org.springframework.integration.redis.store
Class RedisMessageStore

java.lang.Object
  extended by org.springframework.integration.store.AbstractMessageGroupStore
      extended by org.springframework.integration.redis.store.RedisMessageStore
All Implemented Interfaces:
java.lang.Iterable<MessageGroup>, MessageGroupStore, MessageStore

public class RedisMessageStore
extends AbstractMessageGroupStore
implements MessageStore

An implementation of both the MessageStore and MessageGroupStore strategies that relies upon Redis for persistence.

Since:
2.1

Field Summary
 
Fields inherited from class org.springframework.integration.store.AbstractMessageGroupStore
logger
 
Constructor Summary
RedisMessageStore(org.springframework.data.redis.connection.RedisConnectionFactory connectionFactory)
           
 
Method Summary
<T> Message<T>
addMessage(Message<T> message)
          Put the provided Message into the MessageStore.
 MessageGroup addMessageToGroup(java.lang.Object groupId, Message<?> message)
          Add a Message to the group with the provided group ID.
 Message<?> getMessage(java.util.UUID id)
          Return the Message with the given id, or null if no Message with that id exists in the MessageStore.
 long getMessageCount()
          Optional attribute giving the number of messages in the store.
 MessageGroup getMessageGroup(java.lang.Object groupId)
          Will create a new instance of SimpleMessageGroup initializing it with data collected from the Redis Message Store.
 java.util.Iterator<MessageGroup> iterator()
           
 MessageGroup markMessageFromGroup(java.lang.Object groupId, Message<?> messageToMark)
          Mark the given Message within the group corresponding to the provided group ID.
 MessageGroup markMessageGroup(MessageGroup group)
          Mark all messages in the provided group.
 Message<?> removeMessage(java.util.UUID id)
          Remove the Message with the given id from the MessageStore, if present, and return it.
 MessageGroup removeMessageFromGroup(java.lang.Object groupId, Message<?> messageToRemove)
          Remove a Message from the group with the provided group ID.
 void removeMessageGroup(java.lang.Object groupId)
          Remove the MessageGroup with the provided group ID.
 void setValueSerializer(org.springframework.data.redis.serializer.RedisSerializer<?> valueSerializer)
           
 
Methods inherited from class org.springframework.integration.store.AbstractMessageGroupStore
expireMessageGroups, getMarkedMessageCountForAllMessageGroups, getMessageCountForAllMessageGroups, getMessageGroupCount, registerMessageGroupExpiryCallback, setExpiryCallbacks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedisMessageStore

public RedisMessageStore(org.springframework.data.redis.connection.RedisConnectionFactory connectionFactory)
Method Detail

setValueSerializer

public void setValueSerializer(org.springframework.data.redis.serializer.RedisSerializer<?> valueSerializer)

getMessage

public Message<?> getMessage(java.util.UUID id)
Description copied from interface: MessageStore
Return the Message with the given id, or null if no Message with that id exists in the MessageStore.

Specified by:
getMessage in interface MessageStore

addMessage

public <T> Message<T> addMessage(Message<T> message)
Description copied from interface: MessageStore
Put the provided Message into the MessageStore. The store may need to mutate the message internally, and if it does then the return value can be different than the input. The id of the return value will be used as an index so that the MessageStore.getMessage(UUID) and MessageStore.removeMessage(UUID) behave properly. Since messages are immutable, putting the same message more than once is a no-op.

Specified by:
addMessage in interface MessageStore
Returns:
the message that was stored

removeMessage

public Message<?> removeMessage(java.util.UUID id)
Description copied from interface: MessageStore
Remove the Message with the given id from the MessageStore, if present, and return it. If no Message with that id is present in the store, this will return null.

Specified by:
removeMessage in interface MessageStore

getMessageCount

@ManagedAttribute
public long getMessageCount()
Description copied from interface: MessageStore
Optional attribute giving the number of messages in the store. Implementations may decline to respond by throwing an exception.

Specified by:
getMessageCount in interface MessageStore
Returns:
the number of messages

getMessageGroup

public MessageGroup getMessageGroup(java.lang.Object groupId)
Will create a new instance of SimpleMessageGroup initializing it with data collected from the Redis Message Store.

Specified by:
getMessageGroup in interface MessageGroupStore
Returns:
a group of messages, empty if none exists for this key

addMessageToGroup

public MessageGroup addMessageToGroup(java.lang.Object groupId,
                                      Message<?> message)
Add a Message to the group with the provided group ID.

Specified by:
addMessageToGroup in interface MessageGroupStore
Parameters:
groupId - the group id to store the message under
message - a message

markMessageGroup

public MessageGroup markMessageGroup(MessageGroup group)
Mark all messages in the provided group.

Specified by:
markMessageGroup in interface MessageGroupStore
Parameters:
group - a MessageGroup with no unmarked messages

removeMessageFromGroup

public MessageGroup removeMessageFromGroup(java.lang.Object groupId,
                                           Message<?> messageToRemove)
Remove a Message from the group with the provided group ID.

Specified by:
removeMessageFromGroup in interface MessageGroupStore
Parameters:
groupId - the groupId for the group containing the message
messageToRemove - the message to be removed

markMessageFromGroup

public MessageGroup markMessageFromGroup(java.lang.Object groupId,
                                         Message<?> messageToMark)
Mark the given Message within the group corresponding to the provided group ID.

Specified by:
markMessageFromGroup in interface MessageGroupStore
Parameters:
groupId - the groupId for the group containing the message
messageToMark - the message to be marked

removeMessageGroup

public void removeMessageGroup(java.lang.Object groupId)
Remove the MessageGroup with the provided group ID.

Specified by:
removeMessageGroup in interface MessageGroupStore
Parameters:
groupId - the id of the group to remove

iterator

public java.util.Iterator<MessageGroup> iterator()
Specified by:
iterator in interface java.lang.Iterable<MessageGroup>
Specified by:
iterator in class AbstractMessageGroupStore