Class AbstractKeyValueMessageStore
java.lang.Object
org.springframework.integration.store.AbstractBatchingMessageGroupStore
org.springframework.integration.store.AbstractMessageGroupStore
org.springframework.integration.store.AbstractKeyValueMessageStore
- All Implemented Interfaces:
Iterable<MessageGroup>
,BasicMessageGroupStore
,MessageGroupStore
,MessageStore
- Direct Known Subclasses:
HazelcastMessageStore
,RedisMessageStore
public abstract class AbstractKeyValueMessageStore
extends AbstractMessageGroupStore
implements MessageStore
Base class for implementations of Key/Value style
MessageGroupStore
and MessageStore
.- Since:
- 2.1
- Author:
- Oleg Zhurakousky, Gary Russell, Artem Bilan, Ngoc Nhan, Youbin Wu
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.store.MessageGroupStore
MessageGroupStore.MessageGroupCallback
-
Field Summary
Fields inherited from class org.springframework.integration.store.AbstractMessageGroupStore
GROUP_ID_MUST_NOT_BE_NULL, INTERRUPTED_WHILE_OBTAINING_LOCK, logger
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
AbstractKeyValueMessageStore
(String prefix) Construct an instance based on the provided prefix for keys to distinguish between different store instances in the same target key-value database. -
Method Summary
Modifier and TypeMethodDescription<T> Message<T>
addMessage
(Message<T> message) Put the provided Message into the MessageStore.protected void
doAddMessage
(Message<?> message) protected void
doAddMessage
(Message<?> message, Object groupId) protected void
doAddMessagesToGroup
(Object groupId, Message<?>... messages) protected void
doCompleteGroup
(Object groupId) protected abstract Collection<?>
doListKeys
(String keyPattern) protected Message<?>
doPollMessageFromGroup
(Object groupId) protected abstract Object
protected abstract void
doRemoveAll
(Collection<Object> ids) protected boolean
doRemoveMessageFromGroupById
(Object groupId, UUID messageId) protected void
doRemoveMessageGroup
(Object groupId) Remove the MessageGroup with the provided group ID.protected void
doRemoveMessagesFromGroup
(Object groupId, Collection<Message<?>> messages) protected abstract Object
doRetrieve
(Object id) protected void
doSetGroupCondition
(Object groupId, String condition) protected void
doSetLastReleasedSequenceNumberForGroup
(Object groupId, int sequenceNumber) protected abstract void
protected abstract void
doStoreIfAbsent
(Object id, Object objectToStore) getGroupMetadata
(Object groupId) Obtain the group metadata without fetching any messages; must supply all other group properties; may include the id of the first message.Return the configured prefix for message group keys to distinguish between different store instances in the same target key-value database.Message<?>
getMessage
(UUID messageId) long
Optional attribute giving the number of messages in the store.Message<?>
getMessageFromGroup
(Object groupId, UUID messageId) Retrieve aMessage
from a group by id.getMessageGroup
(Object groupId) Will create a new instance of SimpleMessageGroup if necessary.getMessageMetadata
(UUID messageId) Return the configured prefix for message keys to distinguish between different store instances in the same target key-value database.Collection<Message<?>>
getMessagesForGroup
(Object groupId) Retrieve messages for the provided group id.Message<?>
getOneMessageFromGroup
(Object groupId) Return the oneMessage
fromMessageGroup
.iterator()
int
messageGroupSize
(Object groupId) Return the size of this MessageGroup.Message<?>
removeMessage
(UUID id) Remove the Message with the given id from the MessageStore, if present, and return it.streamMessagesForGroup
(Object groupId) Return a stream for messages stored in the provided group.Methods inherited from class org.springframework.integration.store.AbstractMessageGroupStore
addMessagesToGroup, addMessageToGroup, completeGroup, copy, executeLocked, executeLocked, expireMessageGroups, getLockRegistry, getMessageCountForAllMessageGroups, getMessageGroupCount, getMessageGroupFactory, isTimeoutOnIdle, pollMessageFromGroup, registerMessageGroupExpiryCallback, removeMessageFromGroupById, removeMessageGroup, removeMessagesFromGroup, removeMessagesFromGroup, setExpiryCallbacks, setGroupCondition, setLastReleasedSequenceNumberForGroup, setLazyLoadMessageGroups, setLockRegistry, setTimeoutOnIdle
Methods inherited from class org.springframework.integration.store.AbstractBatchingMessageGroupStore
getRemoveBatchSize, setMessageGroupFactory, setRemoveBatchSize
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
MESSAGE_KEY_PREFIX
- See Also:
-
MESSAGE_GROUP_KEY_PREFIX
- See Also:
-
-
Constructor Details
-
AbstractKeyValueMessageStore
protected AbstractKeyValueMessageStore() -
AbstractKeyValueMessageStore
Construct an instance based on the provided prefix for keys to distinguish between different store instances in the same target key-value database. Defaults to an empty string - no prefix. The actual prefix for messages isprefix + MESSAGE_
; for message groups -prefix + GROUP_OF_MESSAGES_
- Parameters:
prefix
- the prefix to use- Since:
- 4.3.12
-
-
Method Details
-
getMessagePrefix
Return the configured prefix for message keys to distinguish between different store instances in the same target key-value database. Defaults to the "MESSAGE_" - without a custom prefix.- Returns:
- the prefix for keys
- Since:
- 4.3.12
-
getGroupPrefix
Return the configured prefix for message group keys to distinguish between different store instances in the same target key-value database. Defaults to the "GROUP_OF_MESSAGES_" - without custom prefix.- Returns:
- the prefix for keys
- Since:
- 4.3.12
-
getMessage
- Specified by:
getMessage
in interfaceMessageStore
- Parameters:
messageId
- The message identifier.- Returns:
- The Message with the given id, or null if no Message with that id exists in the MessageStore.
-
getMessageMetadata
Description copied from interface:MessageStore
- Specified by:
getMessageMetadata
in interfaceMessageStore
- Parameters:
messageId
- The message identifier.- Returns:
- The MessageMetadata with the given id, or null if no Message with that id exists in the MessageStore or the message has no metadata (legacy message from an earlier version).
-
addMessage
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 theMessageStore.getMessage(UUID)
andMessageStore.removeMessage(UUID)
behave properly. Since messages are immutable, putting the same message more than once is a no-op.- Specified by:
addMessage
in interfaceMessageStore
- Type Parameters:
T
- The payload type.- Parameters:
message
- The message.- Returns:
- The message that was stored.
-
doAddMessage
-
doAddMessage
-
removeMessage
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 returnnull
. If this method is implemented on aMessageGroupStore
, the message is removed from the store only if no groups holding this message.- Specified by:
removeMessage
in interfaceMessageStore
- Parameters:
id
- the message identifier.- Returns:
- the message (if any).
-
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 interfaceMessageStore
- Returns:
- The number of messages.
-
getMessageGroup
Will create a new instance of SimpleMessageGroup if necessary.- Specified by:
getMessageGroup
in interfaceBasicMessageGroupStore
- Parameters:
groupId
- The group identifier.- Returns:
- A group of messages, empty if none exists for this key.
-
getGroupMetadata
Description copied from interface:MessageGroupStore
Obtain the group metadata without fetching any messages; must supply all other group properties; may include the id of the first message.- Specified by:
getGroupMetadata
in interfaceMessageGroupStore
- Overrides:
getGroupMetadata
in classAbstractMessageGroupStore
- Parameters:
groupId
- The group id.- Returns:
- The metadata.
-
doAddMessagesToGroup
- Specified by:
doAddMessagesToGroup
in classAbstractMessageGroupStore
-
doRemoveMessagesFromGroup
- Specified by:
doRemoveMessagesFromGroup
in classAbstractMessageGroupStore
-
getMessageFromGroup
Description copied from interface:MessageGroupStore
Retrieve aMessage
from a group by id. Returnnull
if message does not belong to the requested group.- Specified by:
getMessageFromGroup
in interfaceMessageGroupStore
- Parameters:
groupId
- The groupId for the group containing the message.messageId
- The message id.- Returns:
- message by id if it belongs to requested group.
-
doRemoveMessageFromGroupById
- Overrides:
doRemoveMessageFromGroupById
in classAbstractMessageGroupStore
-
doCompleteGroup
- Specified by:
doCompleteGroup
in classAbstractMessageGroupStore
-
doRemoveMessageGroup
Remove the MessageGroup with the provided group ID.- Specified by:
doRemoveMessageGroup
in classAbstractMessageGroupStore
-
doSetGroupCondition
- Specified by:
doSetGroupCondition
in classAbstractMessageGroupStore
-
doSetLastReleasedSequenceNumberForGroup
- Specified by:
doSetLastReleasedSequenceNumberForGroup
in classAbstractMessageGroupStore
-
doPollMessageFromGroup
- Specified by:
doPollMessageFromGroup
in classAbstractMessageGroupStore
-
getOneMessageFromGroup
Description copied from interface:MessageGroupStore
Return the oneMessage
fromMessageGroup
.- Specified by:
getOneMessageFromGroup
in interfaceMessageGroupStore
- Parameters:
groupId
- The group identifier.- Returns:
- the
Message
.
-
getMessagesForGroup
Description copied from interface:MessageGroupStore
Retrieve messages for the provided group id.- Specified by:
getMessagesForGroup
in interfaceMessageGroupStore
- Parameters:
groupId
- The group id to retrieve messages for.- Returns:
- the messages for group.
-
streamMessagesForGroup
Description copied from interface:MessageGroupStore
Return a stream for messages stored in the provided group. The persistent implementations return a Stream which has to be closed once fully processed (e.g. through a try-with-resources clause). By default, it streams a result ofMessageGroupStore.getMessagesForGroup(Object)
.- Specified by:
streamMessagesForGroup
in interfaceMessageGroupStore
- Parameters:
groupId
- the group id to retrieve messages.- Returns:
- the
Stream
for messages in this group.
-
iterator
- Specified by:
iterator
in interfaceIterable<MessageGroup>
- Specified by:
iterator
in interfaceMessageGroupStore
- Returns:
- The iterator of currently accumulated
MessageGroup
s.
-
messageGroupSize
Description copied from interface:BasicMessageGroupStore
Return the size of this MessageGroup.- Specified by:
messageGroupSize
in interfaceBasicMessageGroupStore
- Parameters:
groupId
- The group identifier.- Returns:
- The size.
-
doRetrieve
-
doStore
-
doStoreIfAbsent
-
doRemove
-
doRemoveAll
-
doListKeys
-