Class JdbcMessageStore

java.lang.Object
org.springframework.integration.store.AbstractBatchingMessageGroupStore
org.springframework.integration.store.AbstractMessageGroupStore
org.springframework.integration.jdbc.store.JdbcMessageStore
All Implemented Interfaces:
Iterable<org.springframework.integration.store.MessageGroup>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.integration.store.BasicMessageGroupStore, org.springframework.integration.store.MessageGroupStore, org.springframework.integration.store.MessageStore

public class JdbcMessageStore extends org.springframework.integration.store.AbstractMessageGroupStore implements org.springframework.integration.store.MessageStore, org.springframework.beans.factory.BeanClassLoaderAware
Implementation of MessageStore using a relational database via JDBC. SQL scripts to create the necessary tables are packaged as org/springframework/integration/jdbc/schema-*.sql, where * is the target database type.

If you intend backing a MessageChannel using a JDBC-based Message Store, please consider using the channel-specific JdbcChannelMessageStore instead. This implementation is intended for correlation components (e.g. <aggregator>), <delayer> and similar.

Since:
2.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.store.MessageGroupStore

    org.springframework.integration.store.MessageGroupStore.MessageGroupCallback
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default value for the table prefix property.

    Fields inherited from class org.springframework.integration.store.AbstractMessageGroupStore

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a MessageStore with all mandatory properties.
    JdbcMessageStore(org.springframework.jdbc.core.JdbcOperations jdbcOperations)
    Create a MessageStore with all mandatory properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add patterns for packages/classes that are allowed to be deserialized.
    <T> org.springframework.messaging.Message<T>
    addMessage(org.springframework.messaging.Message<T> message)
     
    void
    addMessagesToGroup(Object groupId, org.springframework.messaging.Message<?>... messages)
     
    void
     
    protected org.springframework.messaging.Message<?>
    This method executes a call to the DB to get the oldest Message in the MessageGroup Override this method if need to.
    org.springframework.integration.store.MessageGroupMetadata
     
    protected org.springframework.jdbc.core.JdbcOperations
    To be used to get a reference to JdbcOperations in case this class is subclassed.
    org.springframework.messaging.Message<?>
     
    long
     
    int
     
    org.springframework.integration.store.MessageGroup
     
    int
     
    org.springframework.integration.store.MessageMetadata
     
    Collection<org.springframework.messaging.Message<?>>
     
    org.springframework.messaging.Message<?>
     
    protected String
    getQuery(org.springframework.integration.jdbc.store.JdbcMessageStore.Query base)
    Replace patterns in the input to produce a valid SQL query.
    Iterator<org.springframework.integration.store.MessageGroup>
     
    int
     
    org.springframework.messaging.Message<?>
     
    org.springframework.messaging.Message<?>
     
    void
     
    void
    removeMessagesFromGroup(Object groupId, Collection<org.springframework.messaging.Message<?>> messages)
     
    void
     
    void
    setDeserializer(org.springframework.core.serializer.Deserializer<? extends org.springframework.messaging.Message<?>> deserializer)
    A converter for deserializing byte arrays to message.
    void
    setGroupCondition(Object groupId, String condition)
     
    void
    setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber)
     
    void
    setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler)
    Override the LobHandler that is used to create and unpack large objects in SQL queries.
    void
    setRegion(String region)
    A unique grouping identifier for all messages persisted with this store.
    void
    setSerializer(org.springframework.core.serializer.Serializer<? super org.springframework.messaging.Message<?>> serializer)
    A converter for serializing messages to byte arrays for storage.
    void
    setTablePrefix(String tablePrefix)
    Public setter for the table prefix property.
    Stream<org.springframework.messaging.Message<?>>
     

    Methods inherited from class org.springframework.integration.store.AbstractMessageGroupStore

    addMessageToGroup, copy, expireMessageGroups, getMessageGroupFactory, isTimeoutOnIdle, registerMessageGroupExpiryCallback, removeMessagesFromGroup, setExpiryCallbacks, setLazyLoadMessageGroups, 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

    • DEFAULT_TABLE_PREFIX

      public static final String DEFAULT_TABLE_PREFIX
      Default value for the table prefix property.
      See Also:
  • Constructor Details

    • JdbcMessageStore

      public JdbcMessageStore(DataSource dataSource)
      Create a MessageStore with all mandatory properties.
      Parameters:
      dataSource - a DataSource
    • JdbcMessageStore

      public JdbcMessageStore(org.springframework.jdbc.core.JdbcOperations jdbcOperations)
      Create a MessageStore with all mandatory properties.
      Parameters:
      jdbcOperations - a JdbcOperations
      Since:
      4.3.9
  • Method Details

    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader classLoader)
      Specified by:
      setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware
    • setTablePrefix

      public void setTablePrefix(String tablePrefix)
      Public setter for the table prefix property. This will be prefixed to all the table names before queries are executed. Defaults to DEFAULT_TABLE_PREFIX.
      Parameters:
      tablePrefix - the tablePrefix to set
    • setRegion

      public void setRegion(String region)
      A unique grouping identifier for all messages persisted with this store. Using multiple regions allows the store to be partitioned (if necessary) for different purposes. Defaults to DEFAULT.
      Parameters:
      region - the region name to set
    • setLobHandler

      public void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler)
      Override the LobHandler that is used to create and unpack large objects in SQL queries. The default is fine for almost all platforms, but some Oracle drivers require a native implementation.
      Parameters:
      lobHandler - a LobHandler
    • setSerializer

      public void setSerializer(org.springframework.core.serializer.Serializer<? super org.springframework.messaging.Message<?>> serializer)
      A converter for serializing messages to byte arrays for storage.
      Parameters:
      serializer - the serializer to set
    • setDeserializer

      public void setDeserializer(org.springframework.core.serializer.Deserializer<? extends org.springframework.messaging.Message<?>> deserializer)
      A converter for deserializing byte arrays to message.
      Parameters:
      deserializer - the deserializer to set
    • 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
    • removeMessage

      public org.springframework.messaging.Message<?> removeMessage(UUID id)
      Specified by:
      removeMessage in interface org.springframework.integration.store.MessageStore
    • getMessageCount

      @ManagedAttribute public long getMessageCount()
      Specified by:
      getMessageCount in interface org.springframework.integration.store.MessageStore
    • getMessage

      public org.springframework.messaging.Message<?> getMessage(UUID id)
      Specified by:
      getMessage in interface org.springframework.integration.store.MessageStore
    • getMessageMetadata

      public org.springframework.integration.store.MessageMetadata getMessageMetadata(UUID id)
      Specified by:
      getMessageMetadata in interface org.springframework.integration.store.MessageStore
    • addMessage

      public <T> org.springframework.messaging.Message<T> addMessage(org.springframework.messaging.Message<T> message)
      Specified by:
      addMessage in interface org.springframework.integration.store.MessageStore
    • addMessagesToGroup

      public void addMessagesToGroup(Object groupId, org.springframework.messaging.Message<?>... messages)
      Specified by:
      addMessagesToGroup in interface org.springframework.integration.store.MessageGroupStore
    • getMessageGroupCount

      @ManagedAttribute public int getMessageGroupCount()
      Specified by:
      getMessageGroupCount in interface org.springframework.integration.store.MessageGroupStore
      Overrides:
      getMessageGroupCount in class org.springframework.integration.store.AbstractMessageGroupStore
    • getMessageCountForAllMessageGroups

      @ManagedAttribute public int getMessageCountForAllMessageGroups()
      Specified by:
      getMessageCountForAllMessageGroups in interface org.springframework.integration.store.MessageGroupStore
      Overrides:
      getMessageCountForAllMessageGroups in class org.springframework.integration.store.AbstractMessageGroupStore
    • messageGroupSize

      @ManagedAttribute public int messageGroupSize(Object groupId)
      Specified by:
      messageGroupSize in interface org.springframework.integration.store.BasicMessageGroupStore
    • getMessageGroup

      public org.springframework.integration.store.MessageGroup getMessageGroup(Object groupId)
      Specified by:
      getMessageGroup in interface org.springframework.integration.store.BasicMessageGroupStore
    • getGroupMetadata

      public org.springframework.integration.store.MessageGroupMetadata getGroupMetadata(Object groupId)
      Specified by:
      getGroupMetadata in interface org.springframework.integration.store.MessageGroupStore
      Overrides:
      getGroupMetadata in class org.springframework.integration.store.AbstractMessageGroupStore
    • removeMessagesFromGroup

      public void removeMessagesFromGroup(Object groupId, Collection<org.springframework.messaging.Message<?>> messages)
      Specified by:
      removeMessagesFromGroup in interface org.springframework.integration.store.MessageGroupStore
    • removeMessageGroup

      public void removeMessageGroup(Object groupId)
      Specified by:
      removeMessageGroup in interface org.springframework.integration.store.BasicMessageGroupStore
    • completeGroup

      public void completeGroup(Object groupId)
      Specified by:
      completeGroup in interface org.springframework.integration.store.MessageGroupStore
    • setGroupCondition

      public void setGroupCondition(Object groupId, String condition)
      Specified by:
      setGroupCondition in interface org.springframework.integration.store.MessageGroupStore
    • setLastReleasedSequenceNumberForGroup

      public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber)
      Specified by:
      setLastReleasedSequenceNumberForGroup in interface org.springframework.integration.store.MessageGroupStore
    • pollMessageFromGroup

      public org.springframework.messaging.Message<?> pollMessageFromGroup(Object groupId)
      Specified by:
      pollMessageFromGroup in interface org.springframework.integration.store.BasicMessageGroupStore
    • getOneMessageFromGroup

      public org.springframework.messaging.Message<?> getOneMessageFromGroup(Object groupId)
      Specified by:
      getOneMessageFromGroup in interface org.springframework.integration.store.MessageGroupStore
    • getMessagesForGroup

      public Collection<org.springframework.messaging.Message<?>> getMessagesForGroup(Object groupId)
      Specified by:
      getMessagesForGroup in interface org.springframework.integration.store.MessageGroupStore
    • streamMessagesForGroup

      public Stream<org.springframework.messaging.Message<?>> streamMessagesForGroup(Object groupId)
      Specified by:
      streamMessagesForGroup in interface org.springframework.integration.store.MessageGroupStore
    • iterator

      public Iterator<org.springframework.integration.store.MessageGroup> iterator()
      Specified by:
      iterator in interface Iterable<org.springframework.integration.store.MessageGroup>
      Specified by:
      iterator in interface org.springframework.integration.store.MessageGroupStore
    • getQuery

      protected String getQuery(org.springframework.integration.jdbc.store.JdbcMessageStore.Query base)
      Replace patterns in the input to produce a valid SQL query. This implementation lazily initializes a simple map-based cache, only replacing the table prefix on the first access to a named query. Further, accesses will be resolved from the cache.
      Parameters:
      base - the SQL query to be transformed
      Returns:
      a transformed query with replacements
    • getJdbcOperations

      protected org.springframework.jdbc.core.JdbcOperations getJdbcOperations()
      To be used to get a reference to JdbcOperations in case this class is subclassed.
      Returns:
      the JdbcOperations implementation
    • doPollForMessage

      protected org.springframework.messaging.Message<?> doPollForMessage(String groupIdKey)
      This method executes a call to the DB to get the oldest Message in the MessageGroup Override this method if need to. For example if your DB supports advanced function such as FIRST etc.
      Parameters:
      groupIdKey - String representation of message group ID
      Returns:
      a message; could be null if query produced no Messages