Class JsonChannelMessageStorePreparedStatementSetter

java.lang.Object
org.springframework.integration.jdbc.store.channel.ChannelMessageStorePreparedStatementSetter
org.springframework.integration.jdbc.store.channel.JsonChannelMessageStorePreparedStatementSetter

public class JsonChannelMessageStorePreparedStatementSetter extends ChannelMessageStorePreparedStatementSetter
A 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 BYTEA to JSONB
  • MySQL: Change from BLOB to JSON
  • H2: Change from LONGVARBINARY to CLOB
See the reference documentation for schema migration instructions.

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 Details

    • JsonChannelMessageStorePreparedStatementSetter

      public JsonChannelMessageStorePreparedStatementSetter()
      Create a new JsonChannelMessageStorePreparedStatementSetter with the default JsonObjectMapper configured 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

      public JsonChannelMessageStorePreparedStatementSetter(JsonObjectMapper<?,?> jsonObjectMapper)
      Create a new JsonChannelMessageStorePreparedStatementSetter with a custom JsonObjectMapper.

      This constructor allows full control over the JSON serialization configuration.

      Note: The same JsonObjectMapper configuration should be used in the corresponding JsonMessageRowMapper for consistent serialization and deserialization.

      Parameters:
      jsonObjectMapper - the JsonObjectMapper to 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: ChannelMessageStorePreparedStatementSetter
      Perform 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.serializer is provided.
      An inheritor may consider to call this method for population common properties and perform custom message serialization logic for the parameter #6. Any custom data structure population can be achieved with full overriding of this method.
      Overrides:
      setValues in class ChannelMessageStorePreparedStatementSetter
      Parameters:
      preparedStatement - the PreparedStatement to populate columns based on the provided arguments
      requestMessage - the Message to store
      groupId - the group id for the message to store
      region - the region in the target table to distinguish different database clients
      priorityEnabled - the flag to indicate if priority has to be stored
      Throws:
      SQLException - the exception throws during data population