JDBC Metadata Store

版本 5.0 引入了 JDBC MetadataStore (参见 Metadata Store)实现。你可以使用 JdbcMetadataStore 在应用程序重新启动后维护元数据状态。此 MetadataStore 实现可以用作下列适配器:

Version 5.0 introduced the JDBC MetadataStore (see Metadata Store) implementation. You can use the JdbcMetadataStore to maintain the metadata state across application restarts. This MetadataStore implementation can be used with adapters such as the following:

要将这些适配器配置为使用 JdbcMetadataStore,请使用 bean 名称 metadataStore 声明一个 Spring bean。Feed 入站通道适配器和 feed 入站通道适配器都会自动选取并使用已声明的 JdbcMetadataStore ,如下例所示:

To configure these adapters to use the JdbcMetadataStore, declare a Spring bean by using a bean name of metadataStore. The Feed inbound channel adapter and the feed inbound channel adapter both automatically pick up and use the declared JdbcMetadataStore, as the following example shows:

@Bean
public MetadataStore metadataStore(DataSource dataSource) {
    return new JdbcMetadataStore(dataSource);
}

org.springframework.integration.jdbc 包有几个 RDMBS 供应商的数据库架构脚本。例如,以下列表显示元数据表的 H2 DDL:

The org.springframework.integration.jdbc package has Database schema scripts for several RDMBS vendors. For example, the following listing shows the H2 DDL for the metadata table:

CREATE TABLE INT_METADATA_STORE  (
	METADATA_KEY VARCHAR(255) NOT NULL,
	METADATA_VALUE VARCHAR(4000),
	REGION VARCHAR(100) NOT NULL,
	constraint INT_METADATA_STORE_PK primary key (METADATA_KEY, REGION)
);

您可以更改 INT_ 前缀以匹配目标数据库设计要求。您还可以配置 JdbcMetadataStore 以使用自定义前缀。

You can change the INT_ prefix to match the target database design requirements. You can also configure JdbcMetadataStore to use the custom prefix.

JdbcMetadataStore 实施 ConcurrentMetadataStore,使其能够可靠地在多个应用程序实例之间共享,其中只有一个实例可以存储或修改键的值。所有这些操作都是原子的,这归功于事务保证。

The JdbcMetadataStore implements ConcurrentMetadataStore, letting it be reliably shared across multiple application instances, where only one instance can store or modify a key’s value. All of these operations are atomic, thanks to transaction guarantees.

事务管理必须使用 JdbcMetadataStore。入站通道适配器可以在轮询器配置中提供对 TransactionManager 的引用。与 MetadataStore 非事务实现不同,使用 JdbcMetadataStore 时,条目仅在事务提交后才显示在目标表中。回滚发生时,不会向 INT_METADATA_STORE 表中添加任何条目。

Transaction management must use JdbcMetadataStore. Inbound channel adapters can be supplied with a reference to the TransactionManager in the poller configuration. Unlike non-transactional MetadataStore implementations, with JdbcMetadataStore, the entry appears in the target table only after the transaction commits. When a rollback occurs, no entries are added to the INT_METADATA_STORE table.

自 5.0.7 版本起,您可以使用针对 RDBMS 供应商特定的 lockHint 选项配置 JdbcMetadataStore,以便对元数据存储条目使用基于锁的查询。默认情况下,它是 FOR UPDATE,如果目标数据库不支持行锁定功能,则可以配置为空字符串。在用于更新之前锁定行的 SELECT 表达式中,请咨询供应商以了解特定和可能的提示。

Since version 5.0.7, you can configure the JdbcMetadataStore with the RDBMS vendor-specific lockHint option for lock-based queries on metadata store entries. By default, it is FOR UPDATE and can be configured with an empty string if the target database does not support row locking functionality. Consult with your vendor for particular and possible hints in the SELECT expression for locking rows before updates.