Class MongoDbMessageStore

All Implemented Interfaces:
Iterable<MessageGroup>, Aware, BeanClassLoaderAware, InitializingBean, ApplicationContextAware, BasicMessageGroupStore, MessageGroupStore, MessageStore

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
  • Field Details

  • Constructor Details

    • MongoDbMessageStore

      public MongoDbMessageStore(MongoDatabaseFactory mongoDbFactory)
      Create a MongoDbMessageStore using the provided MongoDatabaseFactory.and the default collection name.
      Parameters:
      mongoDbFactory - The mongodb factory.
    • MongoDbMessageStore

      public MongoDbMessageStore(MongoDatabaseFactory mongoDbFactory, @Nullable String collectionName)
      Create a MongoDbMessageStore using the provided MongoDatabaseFactory and collection name.
      Parameters:
      mongoDbFactory - The mongodb factory.
      collectionName - The collection name.
  • Method Details

    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader classLoader)
      Specified by:
      setBeanClassLoader in interface BeanClassLoaderAware
    • setApplicationContext

      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
      Specified by:
      setApplicationContext in interface ApplicationContextAware
      Throws:
      BeansException
    • addAllowedPatterns

      public void addAllowedPatterns(String... patterns)
      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

      public void setCustomConverters(Object... customConverters)
      Configure a set of converters to use in the MappingMongoConverter. Must be instances of org.springframework.core.convert.converter.Converter, org.springframework.core.convert.converter.ConverterFactory, org.springframework.core.convert.converter.GenericConverter or org.springframework.data.convert.ConverterBuilder.ConverterAware.
      Parameters:
      customConverters - the converters to use.
      Since:
      5.1.6
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • 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
      Type Parameters:
      T - The payload type.
      Parameters:
      message - The message.
      Returns:
      The message that was stored.
    • getMessage

      public Message<?> getMessage(UUID id)
      Specified by:
      getMessage in interface MessageStore
      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

      public MessageMetadata getMessageMetadata(UUID id)
      Description copied from interface: MessageStore
      Return a MessageMetadata for the Message by provided id.
      Specified by:
      getMessageMetadata in interface MessageStore
      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

      @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.
    • removeMessage

      public Message<?> removeMessage(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
      Parameters:
      id - THe message identifier.
      Returns:
      The message.
    • getMessageGroup

      public MessageGroup getMessageGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Return all Messages currently in the MessageStore that were stored using BasicMessageGroupStore.addMessageToGroup(Object, Message) with this group id.
      Specified by:
      getMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      A group of messages, empty if none exists for this key.
    • addMessagesToGroup

      public void addMessagesToGroup(Object groupId, Message<?>... messages)
      Description copied from interface: MessageGroupStore
      Store messages with an association to a group id. This can be used to group messages together.
      Specified by:
      addMessagesToGroup in interface MessageGroupStore
      Parameters:
      groupId - The group id to store messages under.
      messages - The messages to add.
    • removeMessagesFromGroup

      public void removeMessagesFromGroup(Object groupId, Collection<Message<?>> messages)
      Description copied from interface: MessageGroupStore
      Persist the deletion of messages from the group.
      Specified by:
      removeMessagesFromGroup in interface MessageGroupStore
      Parameters:
      groupId - The groupId for the group containing the message(s).
      messages - The messages to be removed.
    • removeMessageGroup

      public void removeMessageGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Remove the message group with this id.
      Specified by:
      removeMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The id of the group to remove.
    • iterator

      public Iterator<MessageGroup> iterator()
      Specified by:
      iterator in interface Iterable<MessageGroup>
      Specified by:
      iterator in interface MessageGroupStore
      Returns:
      The iterator of currently accumulated MessageGroups.
    • pollMessageFromGroup

      public Message<?> pollMessageFromGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Poll Message from this MessageGroup (in FIFO style if supported by the implementation) while also removing the polled Message.
      Specified by:
      pollMessageFromGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      The message.
    • messageGroupSize

      public int messageGroupSize(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Return the size of this MessageGroup.
      Specified by:
      messageGroupSize in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      The size.
    • setGroupCondition

      public void setGroupCondition(Object groupId, String condition)
      Description copied from interface: MessageGroupStore
      Add 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:
      setGroupCondition in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      condition - The condition to store into the group.
    • setLastReleasedSequenceNumberForGroup

      public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber)
      Description copied from interface: MessageGroupStore
      Allows you to set the sequence number of the last released Message. Used for Resequencing use cases
      Specified by:
      setLastReleasedSequenceNumberForGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      sequenceNumber - The sequence number.
    • completeGroup

      public void completeGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Completes 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:
      completeGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
    • getOneMessageFromGroup

      public Message<?> getOneMessageFromGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Return the one Message from MessageGroup.
      Specified by:
      getOneMessageFromGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      the Message.
    • getMessagesForGroup

      public Collection<Message<?>> getMessagesForGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Retrieve messages for the provided group id.
      Specified by:
      getMessagesForGroup in interface MessageGroupStore
      Parameters:
      groupId - The group id to retrieve messages for.
      Returns:
      the messages for group.
    • streamMessagesForGroup

      public Stream<Message<?>> streamMessagesForGroup(Object groupId)
      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 of MessageGroupStore.getMessagesForGroup(Object).
      Specified by:
      streamMessagesForGroup in interface MessageGroupStore
      Parameters:
      groupId - the group id to retrieve messages.
      Returns:
      the Stream for messages in this group.
    • getMessageCountForAllMessageGroups

      @ManagedAttribute public int getMessageCountForAllMessageGroups()
      Description copied from interface: MessageGroupStore
      Optional attribute giving the number of messages in the store over all groups. Implementations may decline to respond by throwing an exception.
      Specified by:
      getMessageCountForAllMessageGroups in interface MessageGroupStore
      Overrides:
      getMessageCountForAllMessageGroups in class AbstractMessageGroupStore
      Returns:
      the number of messages
    • getMessageGroupCount

      @ManagedAttribute public int getMessageGroupCount()
      Description copied from interface: MessageGroupStore
      Optional attribute giving the number of message groups. Implementations may decline to respond by throwing an exception.
      Specified by:
      getMessageGroupCount in interface MessageGroupStore
      Overrides:
      getMessageGroupCount in class AbstractMessageGroupStore
      Returns:
      the number message groups