GH-8680: Check DB for table on start (#8690)
* GH-8680: Check DB for table on start Fixes https://github.com/spring-projects/spring-integration/issues/8680 If database is not initialized properly before application start, we may lose messages at runtime when we fail to insert data into DB * Implement `SmartLifecycle` on `JdbcMessageStore`, `JdbcChannelMessageStore`, `JdbcMetadataStore`, and `DefaultLockRepository` to perform `SELECT COUNT` query in `start()` to fail fast if no required table is present. * Refactor `AbstractJdbcChannelMessageStoreTests` into JUnit 5 and use `MySqlContainerTest` for more coverage * Fix newly failed tests which had DB not initialized before * Exclude `commons-logging` from `commons-dbcp2` dependency to avoid classpath conflict * Document the new feature * * Fix HTTP URL in the `DataSource-mysql-context.xml` * Fix language in docs Co-authored-by: Gary Russell <grussell@vmware.com> * * Add `setCheckDatabaseOnStart(false)` to disable the check query for all the SI JDBC components * Fix language in Javadocs Co-authored-by: Gary Russell <grussell@vmware.com> --------- Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
@@ -386,6 +386,7 @@ Furthermore, the index for `PriorityChannel` is commented out because it is not
|
||||
|
||||
NOTE: When using the `OracleChannelMessageStoreQueryProvider`, the priority channel index **must** be added because it is included in a hint in the query.
|
||||
|
||||
[[jdbc-db-init]]
|
||||
==== Initializing the Database
|
||||
|
||||
Before starting to use JDBC message store components, you should provision a target database with the appropriate objects.
|
||||
@@ -397,6 +398,10 @@ A common way to use these scripts is to reference them in a https://docs.spring.
|
||||
Note that the scripts are provided as samples and as specifications of the required table and column names.
|
||||
You may find that you need to enhance them for production use (for, example, by adding index declarations).
|
||||
|
||||
Starting with version 6.2, the `JdbcMessageStore`, `JdbcChannelMessageStore`, `JdbcMetadataStore`, and `DefaultLockRepository` implement `SmartLifecycle` and perform a`SELECT COUNT` query, on their respective tables, in the `start()` method to ensure that the required table (according to the provided prefix) is present in the target database.
|
||||
If the required table does not exist, the application context fails to start.
|
||||
The check can be disabled via `setCheckDatabaseOnStart(false)`.
|
||||
|
||||
[[jdbc-message-store-generic]]
|
||||
==== The Generic JDBC Message Store
|
||||
|
||||
|
||||
@@ -45,3 +45,9 @@ See <<./web-sockets.adoc#websocket-client-container-attributes, WebSockets Suppo
|
||||
|
||||
The `KafkaMessageSource` now extracts an `ErrorHandlingDeserializer` configuration from the consumer properties and re-throws `DeserializationException` extracted from failed record headers.
|
||||
See <<./kafka.adoc#kafka-inbound-pollable, Kafka Inbound Channel Adapter>> for more information.
|
||||
|
||||
[[x6.2-jdbc]]
|
||||
=== JDBC Support Changes
|
||||
|
||||
The `JdbcMessageStore`, `JdbcChannelMessageStore`, `JdbcMetadataStore`, and `DefaultLockRepository` implement `SmartLifecycle` and perform a`SELECT COUNT` query, on their respective tables, in the `start()` method to ensure that the required table (according to the provided prefix) is present in the target database.
|
||||
See <<./jdbc.adoc#jdbc-db-init, Initializing the Database>> for more information.
|
||||
|
||||
Reference in New Issue
Block a user