Class JdbcMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class JdbcMessageHandler extends AbstractMessageHandler
A message handler that executes an SQL update. Dynamic query parameters are supported through the SqlParameterSourceFactory abstraction, the default implementation of which wraps the message so that its bean properties can be referred to by name in the query string, e.g.
 INSERT INTO ITEMS (MESSAGE_ID, PAYLOAD) VALUES (:headers[id], :payload)
 

When a message payload is an instance of Iterable, a NamedParameterJdbcOperations.batchUpdate(String, SqlParameterSource[]) is performed, where each SqlParameterSource instance is based on items wrapped into an internal Message implementation with headers from the request message. The item is wrapped only if it is not a Message already.

When a preparedStatementSetter is configured, it is applied for each item in the appropriate JdbcOperations.batchUpdate(String, BatchPreparedStatementSetter) function.

NOTE: The batch update is not supported when keysGenerated is in use.

N.B. do not use quotes to escape the header keys. The default SQL parameter source (from Spring JDBC) can also handle headers with dotted names (e.g. business.id)

Since:
2.0
Author:
Dave Syer, Artem Bilan, Trung Pham
  • Constructor Details

    • JdbcMessageHandler

      public JdbcMessageHandler(DataSource dataSource, String updateSql)
      Constructor taking DataSource from which the DB Connection can be obtained and the select query to execute to retrieve new rows.
      Parameters:
      dataSource - Must not be null
      updateSql - query to execute
    • JdbcMessageHandler

      public JdbcMessageHandler(JdbcOperations jdbcOperations, String updateSql)
      Constructor taking JdbcOperations instance to use for query execution and the select query to execute to retrieve new rows.
      Parameters:
      jdbcOperations - instance to use for query execution
      updateSql - query to execute
  • Method Details