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.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,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, org.springframework.context.SmartLifecycle
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.
This class implements SmartLifecycle and calls getMessageGroupCount()
on start() to check if required tables are present in DB.
The application context will fail to start if the table is not present.
This check can be disabled via setCheckDatabaseOnStart(boolean).
- 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
FieldsModifier and TypeFieldDescriptionstatic final StringDefault value for the table prefix property.Fields inherited from class org.springframework.integration.store.AbstractMessageGroupStore
loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionJdbcMessageStore(DataSource dataSource) Create aMessageStorewith all mandatory properties.JdbcMessageStore(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Create aMessageStorewith all mandatory properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllowedPatterns(String... patterns) Add patterns for packages/classes that are allowed to be deserialized.<T> org.springframework.messaging.Message<T>addMessage(org.springframework.messaging.Message<T> message) voidaddMessagesToGroup(Object groupId, org.springframework.messaging.Message<?>... messages) voidcompleteGroup(Object groupId) 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.org.springframework.integration.store.MessageGroupMetadatagetGroupMetadata(Object groupId) protected org.springframework.jdbc.core.JdbcOperationsTo be used to get a reference to JdbcOperations in case this class is subclassed.org.springframework.messaging.Message<?>getMessage(UUID id) longintorg.springframework.messaging.Message<?>getMessageFromGroup(Object groupId, UUID messageId) org.springframework.integration.store.MessageGroupgetMessageGroup(Object groupId) intorg.springframework.integration.store.MessageMetadataCollection<org.springframework.messaging.Message<?>>getMessagesForGroup(Object groupId) org.springframework.messaging.Message<?>getOneMessageFromGroup(Object groupId) protected StringgetQuery(org.springframework.integration.jdbc.store.JdbcMessageStore.Query base) Replace patterns in the input to produce a valid SQL query.booleanbooleanIterator<org.springframework.integration.store.MessageGroup>iterator()intmessageGroupSize(Object groupId) org.springframework.messaging.Message<?>pollMessageFromGroup(Object groupId) org.springframework.messaging.Message<?>removeMessage(UUID id) booleanremoveMessageFromGroupById(Object groupId, UUID messageId) voidremoveMessageGroup(Object groupId) voidremoveMessagesFromGroup(Object groupId, Collection<org.springframework.messaging.Message<?>> messages) voidsetBeanClassLoader(ClassLoader classLoader) voidsetCheckDatabaseOnStart(boolean checkDatabaseOnStart) The flag to perform a database check query on start or not.voidsetDeserializer(org.springframework.core.serializer.Deserializer<? extends org.springframework.messaging.Message<?>> deserializer) A converter for deserializing byte arrays to message.voidsetGroupCondition(Object groupId, String condition) voidsetLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber) voidsetLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler) Override theLobHandlerthat is used to create and unpack large objects in SQL queries.voidA unique grouping identifier for all messages persisted with this store.voidsetSerializer(org.springframework.core.serializer.Serializer<? super org.springframework.messaging.Message<?>> serializer) A converter for serializing messages to byte arrays for storage.voidsetTablePrefix(String tablePrefix) Public setter for the table prefix property.voidstart()voidstop()Stream<org.springframework.messaging.Message<?>>streamMessagesForGroup(Object groupId) Methods inherited from class org.springframework.integration.store.AbstractMessageGroupStore
addMessageToGroup, copy, expireMessageGroups, 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, spliteratorMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, stop
-
Field Details
-
DEFAULT_TABLE_PREFIX
Default value for the table prefix property.- See Also:
-
-
Constructor Details
-
JdbcMessageStore
Create aMessageStorewith all mandatory properties.- Parameters:
dataSource- aDataSource
-
JdbcMessageStore
public JdbcMessageStore(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Create aMessageStorewith all mandatory properties.- Parameters:
jdbcOperations- aJdbcOperations- Since:
- 4.3.9
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setTablePrefix
Public setter for the table prefix property. This will be prefixed to all the table names before queries are executed. Defaults toDEFAULT_TABLE_PREFIX.- Parameters:
tablePrefix- the tablePrefix to set
-
setRegion
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 toDEFAULT.- Parameters:
region- the region name to set
-
setLobHandler
public void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler) Override theLobHandlerthat 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- aLobHandler
-
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
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
-
setCheckDatabaseOnStart
public void setCheckDatabaseOnStart(boolean checkDatabaseOnStart) The flag to perform a database check query on start or not.- Parameters:
checkDatabaseOnStart- false to not perform the database check.- Since:
- 6.2
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
removeMessage
- Specified by:
removeMessagein interfaceorg.springframework.integration.store.MessageStore
-
getMessageCount
@ManagedAttribute public long getMessageCount()- Specified by:
getMessageCountin interfaceorg.springframework.integration.store.MessageStore
-
getMessage
- Specified by:
getMessagein interfaceorg.springframework.integration.store.MessageStore
-
getMessageMetadata
- Specified by:
getMessageMetadatain interfaceorg.springframework.integration.store.MessageStore
-
addMessage
public <T> org.springframework.messaging.Message<T> addMessage(org.springframework.messaging.Message<T> message) - Specified by:
addMessagein interfaceorg.springframework.integration.store.MessageStore
-
addMessagesToGroup
public void addMessagesToGroup(Object groupId, org.springframework.messaging.Message<?>... messages) - Specified by:
addMessagesToGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
getMessageGroupCount
@ManagedAttribute public int getMessageGroupCount()- Specified by:
getMessageGroupCountin interfaceorg.springframework.integration.store.MessageGroupStore- Overrides:
getMessageGroupCountin classorg.springframework.integration.store.AbstractMessageGroupStore
-
getMessageCountForAllMessageGroups
@ManagedAttribute public int getMessageCountForAllMessageGroups()- Specified by:
getMessageCountForAllMessageGroupsin interfaceorg.springframework.integration.store.MessageGroupStore- Overrides:
getMessageCountForAllMessageGroupsin classorg.springframework.integration.store.AbstractMessageGroupStore
-
messageGroupSize
- Specified by:
messageGroupSizein interfaceorg.springframework.integration.store.BasicMessageGroupStore
-
getMessageGroup
- Specified by:
getMessageGroupin interfaceorg.springframework.integration.store.BasicMessageGroupStore
-
getGroupMetadata
- Specified by:
getGroupMetadatain interfaceorg.springframework.integration.store.MessageGroupStore- Overrides:
getGroupMetadatain classorg.springframework.integration.store.AbstractMessageGroupStore
-
removeMessagesFromGroup
public void removeMessagesFromGroup(Object groupId, Collection<org.springframework.messaging.Message<?>> messages) - Specified by:
removeMessagesFromGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
getMessageFromGroup
@Nullable public org.springframework.messaging.Message<?> getMessageFromGroup(Object groupId, UUID messageId) - Specified by:
getMessageFromGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
removeMessageFromGroupById
- Specified by:
removeMessageFromGroupByIdin interfaceorg.springframework.integration.store.MessageGroupStore
-
removeMessageGroup
- Specified by:
removeMessageGroupin interfaceorg.springframework.integration.store.BasicMessageGroupStore
-
completeGroup
- Specified by:
completeGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
setGroupCondition
- Specified by:
setGroupConditionin interfaceorg.springframework.integration.store.MessageGroupStore
-
setLastReleasedSequenceNumberForGroup
- Specified by:
setLastReleasedSequenceNumberForGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
pollMessageFromGroup
- Specified by:
pollMessageFromGroupin interfaceorg.springframework.integration.store.BasicMessageGroupStore
-
getOneMessageFromGroup
- Specified by:
getOneMessageFromGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
getMessagesForGroup
- Specified by:
getMessagesForGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
streamMessagesForGroup
- Specified by:
streamMessagesForGroupin interfaceorg.springframework.integration.store.MessageGroupStore
-
iterator
-
getQuery
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
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
-