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<MessageGroup>,BasicMessageGroupStore,MessageGroupStore,MessageStore
public class JdbcMessageStore extends AbstractMessageGroupStore implements MessageStore
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
- Author:
- Dave Syer, Oleg Zhurakousky, Matt Stine, Gunnar Hillert, Will Schipp, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.store.MessageGroupStore
MessageGroupStore.MessageGroupCallback -
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_TABLE_PREFIXDefault value for the table prefix property. -
Constructor Summary
Constructors Constructor Description JdbcMessageStore(DataSource dataSource)Create aMessageStorewith all mandatory properties.JdbcMessageStore(JdbcOperations jdbcOperations)Create aMessageStorewith all mandatory properties. -
Method Summary
Modifier and Type Method Description voidaddAllowedPatterns(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.voidcompleteGroup(Object groupId)Completes this MessageGroup.protected 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.MessageGroupMetadatagetGroupMetadata(Object groupId)Obtain the group metadata without fetching any messages; must supply all other group properties; may include the id of the first message.protected JdbcOperationsgetJdbcOperations()To be used to get a reference to JdbcOperations in case this class is subclassedMessage<?>getMessage(UUID id)longgetMessageCount()Optional attribute giving the number of messages in the store.intgetMessageCountForAllMessageGroups()Optional attribute giving the number of messages in the store over all groups.MessageGroupgetMessageGroup(Object groupId)Return all Messages currently in the MessageStore that were stored usingBasicMessageGroupStore.addMessageToGroup(Object, Message)with this group id.intgetMessageGroupCount()Optional attribute giving the number of message groups.MessageMetadatagetMessageMetadata(UUID id)Collection<Message<?>>getMessagesForGroup(Object groupId)Retrieve messages for the provided group id.Message<?>getOneMessageFromGroup(Object groupId)Return the oneMessagefromMessageGroup.protected StringgetQuery(org.springframework.integration.jdbc.store.JdbcMessageStore.Query base)Replace patterns in the input to produce a valid SQL query.Iterator<MessageGroup>iterator()intmessageGroupSize(Object groupId)Returns the size of this MessageGroup.Message<?>pollMessageFromGroup(Object groupId)Polls Message from thisMessageGroup(in FIFO style if supported by the implementation) while also removing the polledMessageMessage<?>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.voidsetDeserializer(Deserializer<? extends Message<?>> deserializer)A converter for deserializing byte arrays to messages.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.voidsetLobHandler(LobHandler lobHandler)Override theLobHandlerthat is used to create and unpack large objects in SQL queries.voidsetRegion(String region)A unique grouping identifier for all messages persisted with this store.voidsetSerializer(Serializer<? super Message<?>> serializer)A converter for serializing messages to byte arrays for storage.voidsetTablePrefix(String tablePrefix)Public setter for the table prefix property.Stream<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, getMessageGroupFactory, isTimeoutOnIdle, registerMessageGroupExpiryCallback, removeMessagesFromGroup, setExpiryCallbacks, setLazyLoadMessageGroups, setTimeoutOnIdleMethods inherited from class org.springframework.integration.store.AbstractBatchingMessageGroupStore
getRemoveBatchSize, setMessageGroupFactory, setRemoveBatchSize
-
Field Details
-
DEFAULT_TABLE_PREFIX
Default value for the table prefix property.- See Also:
- Constant Field Values
-
-
Constructor Details
-
JdbcMessageStore
Create aMessageStorewith all mandatory properties.- Parameters:
dataSource- aDataSource
-
JdbcMessageStore
Create aMessageStorewith all mandatory properties.- Parameters:
jdbcOperations- aJdbcOperations- Since:
- 4.3.9
-
-
Method Details
-
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
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
A converter for serializing messages to byte arrays for storage.- Parameters:
serializer- the serializer to set
-
setDeserializer
A converter for deserializing byte arrays to messages.- 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
-
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.
-
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.
-
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).
-
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.
-
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.
-
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
-
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
-
messageGroupSize
Description copied from interface:BasicMessageGroupStoreReturns the size of this MessageGroup.- Specified by:
messageGroupSizein interfaceBasicMessageGroupStore- Parameters:
groupId- The group identifier.- Returns:
- The size.
-
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.
-
getGroupMetadata
Description copied from interface:MessageGroupStoreObtain the group metadata without fetching any messages; must supply all other group properties; may include the id of the first message.- Specified by:
getGroupMetadatain interfaceMessageGroupStore- Overrides:
getGroupMetadatain classAbstractMessageGroupStore- Parameters:
groupId- The group id.- Returns:
- The metadata.
-
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.
-
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.
-
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.
-
pollMessageFromGroup
Description copied from interface:BasicMessageGroupStorePolls 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.
-
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.- Specified by:
streamMessagesForGroupin interfaceMessageGroupStore- Parameters:
groupId- the group id to retrieve messages.- Returns:
- the
Streamfor messages in this group.
-
iterator
- Specified by:
iteratorin interfaceIterable<MessageGroup>- Specified by:
iteratorin interfaceMessageGroupStore- Returns:
- The iterator of currently accumulated
MessageGroups.
-
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
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
-