Class MongoDbMessageStore
java.lang.Object
org.springframework.integration.store.AbstractBatchingMessageGroupStore
org.springframework.integration.store.AbstractMessageGroupStore
org.springframework.integration.mongodb.store.MongoDbMessageStore
- All Implemented Interfaces:
Iterable<MessageGroup>,Aware,BeanClassLoaderAware,InitializingBean,ApplicationContextAware,BasicMessageGroupStore,MessageGroupStore,MessageStore
public class MongoDbMessageStore
extends AbstractMessageGroupStore
implements MessageStore, BeanClassLoaderAware, ApplicationContextAware, InitializingBean
An implementation of both the
MessageStore and
MessageGroupStore
strategies that relies upon MongoDB for persistence.- Since:
- 2.1
- Author:
- Mark Fisher, Oleg Zhurakousky, Sean Brandt, Jodie StJohn, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.store.MessageGroupStore
MessageGroupStore.MessageGroupCallback -
Field Summary
FieldsFields inherited from class org.springframework.integration.store.AbstractMessageGroupStore
logger -
Constructor Summary
ConstructorsConstructorDescriptionMongoDbMessageStore(MongoDatabaseFactory mongoDbFactory) Create a MongoDbMessageStore using the providedMongoDatabaseFactory.and the default collection name.MongoDbMessageStore(MongoDatabaseFactory mongoDbFactory, String collectionName) Create a MongoDbMessageStore using the providedMongoDatabaseFactoryand collection name. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllowedPatterns(String... patterns) Add patterns for packages/classes that are allowed to be deserialized.<T> Message<T>addMessage(Message<T> message) Put the provided Message into the MessageStore.voidaddMessagesToGroup(Object groupId, Message<?>... messages) Store messages with an association to a group id.voidvoidcompleteGroup(Object groupId) Completes this MessageGroup.Message<?>getMessage(UUID id) longOptional attribute giving the number of messages in the store.intOptional attribute giving the number of messages in the store over all groups.getMessageGroup(Object groupId) Return all Messages currently in the MessageStore that were stored usingBasicMessageGroupStore.addMessageToGroup(Object, Message)with this group id.intOptional attribute giving the number of message groups.Collection<Message<?>>getMessagesForGroup(Object groupId) Retrieve messages for the provided group id.Message<?>getOneMessageFromGroup(Object groupId) Return the oneMessagefromMessageGroup.iterator()intmessageGroupSize(Object groupId) Return the size of this MessageGroup.Message<?>pollMessageFromGroup(Object groupId) Poll Message from thisMessageGroup(in FIFO style if supported by the implementation) while also removing the polledMessage.Message<?>removeMessage(UUID id) Remove the Message with the given id from the MessageStore, if present, and return it.voidremoveMessageGroup(Object groupId) Remove the message group with this id.voidremoveMessagesFromGroup(Object groupId, Collection<Message<?>> messages) Persist the deletion of messages from the group.voidsetApplicationContext(ApplicationContext applicationContext) voidsetBeanClassLoader(ClassLoader classLoader) voidsetCustomConverters(Object... customConverters) Configure a set of converters to use in theMappingMongoConverter.voidsetGroupCondition(Object groupId, String condition) Add a condition sentence into the group.voidsetLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) Allows you to set the sequence number of the last released Message.streamMessagesForGroup(Object groupId) Return a stream for messages stored in the provided group.Methods inherited from class org.springframework.integration.store.AbstractMessageGroupStore
addMessageToGroup, copy, expireMessageGroups, getGroupMetadata, getMessageGroupFactory, isTimeoutOnIdle, registerMessageGroupExpiryCallback, removeMessagesFromGroup, setExpiryCallbacks, setLazyLoadMessageGroups, setTimeoutOnIdleMethods inherited from class org.springframework.integration.store.AbstractBatchingMessageGroupStore
getRemoveBatchSize, setMessageGroupFactory, setRemoveBatchSizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SEQUENCE_NAME
- See Also:
-
-
Constructor Details
-
MongoDbMessageStore
Create a MongoDbMessageStore using the providedMongoDatabaseFactory.and the default collection name.- Parameters:
mongoDbFactory- The mongodb factory.
-
MongoDbMessageStore
Create a MongoDbMessageStore using the providedMongoDatabaseFactoryand collection name.- Parameters:
mongoDbFactory- The mongodb factory.collectionName- The collection name.
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
addAllowedPatterns
Add patterns for packages/classes that are allowed to be deserialized. A class can be fully qualified or a wildcard '*' is allowed at the beginning or end of the class name. Examples:com.foo.*,*.MyClass.- Parameters:
patterns- the patterns.- Since:
- 5.4
-
setCustomConverters
Configure a set of converters to use in theMappingMongoConverter. Must be instances oforg.springframework.core.convert.converter.Converter,org.springframework.core.convert.converter.ConverterFactory,org.springframework.core.convert.converter.GenericConverterororg.springframework.data.convert.ConverterBuilder.ConverterAware.- Parameters:
customConverters- the converters to use.- Since:
- 5.1.6
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
addMessage
Description copied from interface:MessageStorePut 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:
addMessagein interfaceMessageStore- Type Parameters:
T- The payload type.- Parameters:
message- The message.- Returns:
- The message that was stored.
-
getMessage
- Specified by:
getMessagein interfaceMessageStore- Parameters:
id- 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:
getMessageMetadatain interfaceMessageStore- Parameters:
id- 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).
-
getMessageCount
Description copied from interface:MessageStoreOptional attribute giving the number of messages in the store. Implementations may decline to respond by throwing an exception.- Specified by:
getMessageCountin interfaceMessageStore- Returns:
- The number of messages.
-
removeMessage
Description copied from interface:MessageStoreRemove 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:
removeMessagein interfaceMessageStore- Parameters:
id- THe message identifier.- Returns:
- The message.
-
getMessageGroup
Description copied from interface:BasicMessageGroupStoreReturn all Messages currently in the MessageStore that were stored usingBasicMessageGroupStore.addMessageToGroup(Object, Message)with this group id.- Specified by:
getMessageGroupin interfaceBasicMessageGroupStore- Parameters:
groupId- The group identifier.- Returns:
- A group of messages, empty if none exists for this key.
-
addMessagesToGroup
Description copied from interface:MessageGroupStoreStore messages with an association to a group id. This can be used to group messages together.- Specified by:
addMessagesToGroupin interfaceMessageGroupStore- Parameters:
groupId- The group id to store messages under.messages- The messages to add.
-
removeMessagesFromGroup
Description copied from interface:MessageGroupStorePersist the deletion of messages from the group.- Specified by:
removeMessagesFromGroupin interfaceMessageGroupStore- Parameters:
groupId- The groupId for the group containing the message(s).messages- The messages to be removed.
-
removeMessageGroup
Description copied from interface:BasicMessageGroupStoreRemove the message group with this id.- Specified by:
removeMessageGroupin interfaceBasicMessageGroupStore- Parameters:
groupId- The id of the group to remove.
-
iterator
- Specified by:
iteratorin interfaceIterable<MessageGroup>- Specified by:
iteratorin interfaceMessageGroupStore- Returns:
- The iterator of currently accumulated
MessageGroups.
-
pollMessageFromGroup
Description copied from interface:BasicMessageGroupStorePoll Message from thisMessageGroup(in FIFO style if supported by the implementation) while also removing the polledMessage.- Specified by:
pollMessageFromGroupin interfaceBasicMessageGroupStore- Parameters:
groupId- The group identifier.- Returns:
- The message.
-
messageGroupSize
Description copied from interface:BasicMessageGroupStoreReturn the size of this MessageGroup.- Specified by:
messageGroupSizein interfaceBasicMessageGroupStore- Parameters:
groupId- The group identifier.- Returns:
- The size.
-
setGroupCondition
Description copied from interface:MessageGroupStoreAdd a condition sentence into the group. Can be used later on for making some decisions for group, e.g. release strategy for correlation handler can consult this condition instead of iterating all the messages in group.- Specified by:
setGroupConditionin interfaceMessageGroupStore- Parameters:
groupId- The group identifier.condition- The condition to store into the group.
-
setLastReleasedSequenceNumberForGroup
Description copied from interface:MessageGroupStoreAllows you to set the sequence number of the last released Message. Used for Resequencing use cases- Specified by:
setLastReleasedSequenceNumberForGroupin interfaceMessageGroupStore- Parameters:
groupId- The group identifier.sequenceNumber- The sequence number.
-
completeGroup
Description copied from interface:MessageGroupStoreCompletes this MessageGroup. Completion of the MessageGroup generally means that this group should not be allowing any more mutating operation to be performed on it. For example any attempt to add/remove new Message form the group should not be allowed.- Specified by:
completeGroupin interfaceMessageGroupStore- Parameters:
groupId- The group identifier.
-
getOneMessageFromGroup
Description copied from interface:MessageGroupStoreReturn the oneMessagefromMessageGroup.- Specified by:
getOneMessageFromGroupin interfaceMessageGroupStore- Parameters:
groupId- The group identifier.- Returns:
- the
Message.
-
getMessagesForGroup
Description copied from interface:MessageGroupStoreRetrieve messages for the provided group id.- Specified by:
getMessagesForGroupin interfaceMessageGroupStore- Parameters:
groupId- The group id to retrieve messages for.- Returns:
- the messages for group.
-
streamMessagesForGroup
Description copied from interface:MessageGroupStoreReturn 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:
streamMessagesForGroupin interfaceMessageGroupStore- Parameters:
groupId- the group id to retrieve messages.- Returns:
- the
Streamfor messages in this group.
-
getMessageCountForAllMessageGroups
Description copied from interface:MessageGroupStoreOptional attribute giving the number of messages in the store over all groups. Implementations may decline to respond by throwing an exception.- Specified by:
getMessageCountForAllMessageGroupsin interfaceMessageGroupStore- Overrides:
getMessageCountForAllMessageGroupsin classAbstractMessageGroupStore- Returns:
- the number of messages
-
getMessageGroupCount
Description copied from interface:MessageGroupStoreOptional attribute giving the number of message groups. Implementations may decline to respond by throwing an exception.- Specified by:
getMessageGroupCountin interfaceMessageGroupStore- Overrides:
getMessageGroupCountin classAbstractMessageGroupStore- Returns:
- the number message groups
-