@ManagedResource
public class JdbcMessageStore
extends org.springframework.integration.store.AbstractMessageGroupStore
implements org.springframework.integration.store.MessageStore, org.springframework.beans.factory.InitializingBean
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.
Notice: Starting with Spring Integration 3.0, this class will move to package:
org.springframework.integration.jdbc.store
.
If you intend backing a MessageChannel
using a JDBC-based Message Store,
please consider using the channel-specific JdbcChannelMessageStore
instead.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CREATED_DATE_KEY
The name of the message header that stores a timestamp for the time the message was inserted.
|
static int |
DEFAULT_LONG_STRING_LENGTH |
static java.lang.String |
DEFAULT_TABLE_PREFIX
Default value for the table prefix property.
|
static java.lang.String |
SAVED_KEY
The name of the message header that stores a flag to indicate that the message has been saved.
|
Constructor and Description |
---|
JdbcMessageStore()
Convenient constructor for configuration use.
|
JdbcMessageStore(javax.sql.DataSource dataSource)
Create a
MessageStore with all mandatory properties. |
Modifier and Type | Method and Description |
---|---|
<T> org.springframework.messaging.Message<T> |
addMessage(org.springframework.messaging.Message<T> message) |
org.springframework.integration.store.MessageGroup |
addMessageToGroup(java.lang.Object groupId,
org.springframework.messaging.Message<?> message) |
void |
afterPropertiesSet() |
void |
completeGroup(java.lang.Object groupId) |
protected org.springframework.messaging.Message<?> |
doPollForMessage(java.lang.String groupIdKey)
This method executes a call to the DB to get the oldest Message in the MessageGroup
Override this method if need to.
|
protected org.springframework.jdbc.core.JdbcOperations |
getJdbcOperations()
To be used to get a reference to JdbcOperations
in case this class is subclassed
|
org.springframework.messaging.Message<?> |
getMessage(java.util.UUID id) |
long |
getMessageCount() |
int |
getMessageCountForAllMessageGroups() |
org.springframework.integration.store.MessageGroup |
getMessageGroup(java.lang.Object groupId) |
int |
getMessageGroupCount() |
protected java.lang.String |
getQuery(org.springframework.integration.jdbc.JdbcMessageStore.Query base)
Replace patterns in the input to produce a valid SQL query.
|
java.util.Iterator<org.springframework.integration.store.MessageGroup> |
iterator() |
int |
messageGroupSize(java.lang.Object groupId) |
org.springframework.messaging.Message<?> |
pollMessageFromGroup(java.lang.Object groupId) |
org.springframework.messaging.Message<?> |
removeMessage(java.util.UUID id) |
org.springframework.integration.store.MessageGroup |
removeMessageFromGroup(java.lang.Object groupId,
org.springframework.messaging.Message<?> messageToRemove) |
void |
removeMessageGroup(java.lang.Object groupId) |
void |
setDataSource(javax.sql.DataSource dataSource)
The JDBC
DataSource to use when interacting with the database. |
void |
setDeserializer(org.springframework.core.serializer.Deserializer<? extends org.springframework.messaging.Message<?>> deserializer)
A converter for deserializing byte arrays to messages.
|
void |
setJdbcTemplate(org.springframework.jdbc.core.JdbcOperations jdbcTemplate)
The
JdbcOperations to use when interacting with the database. |
void |
setLastReleasedSequenceNumberForGroup(java.lang.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(java.lang.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(java.lang.String tablePrefix)
Public setter for the table prefix property.
|
public static final java.lang.String DEFAULT_TABLE_PREFIX
public static final int DEFAULT_LONG_STRING_LENGTH
public static final java.lang.String SAVED_KEY
public static final java.lang.String CREATED_DATE_KEY
public JdbcMessageStore()
public JdbcMessageStore(javax.sql.DataSource dataSource)
MessageStore
with all mandatory properties.dataSource
- a DataSource
public void setTablePrefix(java.lang.String tablePrefix)
DEFAULT_TABLE_PREFIX
.tablePrefix
- the tablePrefix to setpublic void setRegion(java.lang.String region)
DEFAULT
.region
- the region name to setpublic void setDataSource(javax.sql.DataSource dataSource)
DataSource
to use when interacting with the database. Either this property can be set or the
jdbcTemplate
.dataSource
- a DataSource
public void setJdbcTemplate(org.springframework.jdbc.core.JdbcOperations jdbcTemplate)
JdbcOperations
to use when interacting with the database. Either this property can be set or the
dataSource
.jdbcTemplate
- a JdbcOperations
public void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler)
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.lobHandler
- a LobHandler
public void setSerializer(org.springframework.core.serializer.Serializer<? super org.springframework.messaging.Message<?>> serializer)
serializer
- the serializer to setpublic void setDeserializer(org.springframework.core.serializer.Deserializer<? extends org.springframework.messaging.Message<?>> deserializer)
deserializer
- the deserializer to setpublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
public org.springframework.messaging.Message<?> removeMessage(java.util.UUID id)
removeMessage
in interface org.springframework.integration.store.MessageStore
@ManagedAttribute public long getMessageCount()
getMessageCount
in interface org.springframework.integration.store.MessageStore
public org.springframework.messaging.Message<?> getMessage(java.util.UUID id)
getMessage
in interface org.springframework.integration.store.MessageStore
public <T> org.springframework.messaging.Message<T> addMessage(org.springframework.messaging.Message<T> message)
addMessage
in interface org.springframework.integration.store.MessageStore
public org.springframework.integration.store.MessageGroup addMessageToGroup(java.lang.Object groupId, org.springframework.messaging.Message<?> message)
addMessageToGroup
in interface org.springframework.integration.store.BasicMessageGroupStore
@ManagedAttribute public int getMessageGroupCount()
getMessageGroupCount
in interface org.springframework.integration.store.MessageGroupStore
getMessageGroupCount
in class org.springframework.integration.store.AbstractMessageGroupStore
@ManagedAttribute public int getMessageCountForAllMessageGroups()
getMessageCountForAllMessageGroups
in interface org.springframework.integration.store.MessageGroupStore
getMessageCountForAllMessageGroups
in class org.springframework.integration.store.AbstractMessageGroupStore
@ManagedAttribute public int messageGroupSize(java.lang.Object groupId)
messageGroupSize
in interface org.springframework.integration.store.BasicMessageGroupStore
public org.springframework.integration.store.MessageGroup getMessageGroup(java.lang.Object groupId)
getMessageGroup
in interface org.springframework.integration.store.BasicMessageGroupStore
public org.springframework.integration.store.MessageGroup removeMessageFromGroup(java.lang.Object groupId, org.springframework.messaging.Message<?> messageToRemove)
removeMessageFromGroup
in interface org.springframework.integration.store.MessageGroupStore
public void removeMessageGroup(java.lang.Object groupId)
removeMessageGroup
in interface org.springframework.integration.store.BasicMessageGroupStore
public void completeGroup(java.lang.Object groupId)
completeGroup
in interface org.springframework.integration.store.MessageGroupStore
public void setLastReleasedSequenceNumberForGroup(java.lang.Object groupId, int sequenceNumber)
setLastReleasedSequenceNumberForGroup
in interface org.springframework.integration.store.MessageGroupStore
public org.springframework.messaging.Message<?> pollMessageFromGroup(java.lang.Object groupId)
pollMessageFromGroup
in interface org.springframework.integration.store.BasicMessageGroupStore
public java.util.Iterator<org.springframework.integration.store.MessageGroup> iterator()
iterator
in interface java.lang.Iterable<org.springframework.integration.store.MessageGroup>
iterator
in interface org.springframework.integration.store.MessageGroupStore
protected java.lang.String getQuery(org.springframework.integration.jdbc.JdbcMessageStore.Query base)
base
- the SQL query to be transformedprotected org.springframework.jdbc.core.JdbcOperations getJdbcOperations()
protected org.springframework.messaging.Message<?> doPollForMessage(java.lang.String groupIdKey)
groupIdKey
- String representation of message group ID