Class JsonChannelMessageStorePreparedStatementSetter
ChannelMessageStorePreparedStatementSetter implementation that uses JSON
serialization for Message objects instead of Java serialization.
By default, this implementation stores the entire message (including headers and payload) as JSON,
with type information embedded using Jackson's @class property for proper deserialization.
IMPORTANT: JSON serialization exposes message content in text format in the database. Ensure proper database access controls and encryption for sensitive data. Consider the security implications before using this in production with sensitive information.
Database Requirements: This implementation requires modifying the MESSAGE_CONTENT column to a text-based type:
- PostgreSQL: Change from
BYTEAtoJSONB - MySQL: Change from
BLOBtoJSON - H2: Change from
LONGVARBINARYtoCLOB
Usage Example:
@Bean
JdbcChannelMessageStore messageStore(DataSource dataSource) {
JdbcChannelMessageStore store = new JdbcChannelMessageStore(dataSource);
store.setChannelMessageStoreQueryProvider(new PostgresChannelMessageStoreQueryProvider());
// Enable JSON serialization (requires schema modification)
store.setPreparedStatementSetter(
new JsonChannelMessageStorePreparedStatementSetter());
store.setMessageRowMapper(
new JsonMessageRowMapper("com.example"));
return store;
}
- Since:
- 7.0
- Author:
- Yoobin Yoon, Artem Bilan
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newJsonChannelMessageStorePreparedStatementSetterwith the defaultJsonObjectMapperconfigured for Spring Integration message serialization.JsonChannelMessageStorePreparedStatementSetter(JsonObjectMapper<?, ?> jsonObjectMapper) Create a newJsonChannelMessageStorePreparedStatementSetterwith a customJsonObjectMapper. -
Method Summary
Modifier and TypeMethodDescriptionvoidsetValues(PreparedStatement preparedStatement, Message<?> requestMessage, Object groupId, String region, boolean priorityEnabled) Perform a preparedStatement parameters population according provided arguments.
-
Constructor Details
-
JsonChannelMessageStorePreparedStatementSetter
public JsonChannelMessageStorePreparedStatementSetter()Create a newJsonChannelMessageStorePreparedStatementSetterwith the defaultJsonObjectMapperconfigured for Spring Integration message serialization.This constructor is suitable when serializing standard Spring Integration and Java classes. Custom payload types will require their package to be added to the corresponding
JsonMessageRowMapper. -
JsonChannelMessageStorePreparedStatementSetter
Create a newJsonChannelMessageStorePreparedStatementSetterwith a customJsonObjectMapper.This constructor allows full control over the JSON serialization configuration.
Note: The same JsonObjectMapper configuration should be used in the corresponding
JsonMessageRowMapperfor consistent serialization and deserialization.- Parameters:
jsonObjectMapper- theJsonObjectMapperto use for JSON serialization
-
-
Method Details
-
setValues
public void setValues(PreparedStatement preparedStatement, Message<?> requestMessage, Object groupId, String region, boolean priorityEnabled) throws SQLException Description copied from class:ChannelMessageStorePreparedStatementSetterPerform a preparedStatement parameters population according provided arguments. The default functionality is (parameter - data):- 1 - messageId
- 2 - groupKey
- 3 - region
- 4 - createdDate
- 5 - priority if enabled, otherwise null
- 6 - serialized message if
ChannelMessageStorePreparedStatementSetter.serializeris provided.
- Overrides:
setValuesin classChannelMessageStorePreparedStatementSetter- Parameters:
preparedStatement- thePreparedStatementto populate columns based on the provided argumentsrequestMessage- theMessageto storegroupId- the group id for the message to storeregion- the region in the target table to distinguish different database clientspriorityEnabled- the flag to indicate if priority has to be stored- Throws:
SQLException- the exception throws during data population
-