java - 如何在spring集成中使用java dsl将db poller xml配置转换为java配置
问题描述
尝试在 spring 集成中轮询数据库。我有 XML 代码,但我想将 XML 配置转换为 java DSL。
XML 代码:
<context:component-scan
base-package="org.springintegration.polling.dbpoller" />
<int:channel id="fromdb">
<int:queue />
</int:channel>
<int:poller default="true" fixed-rate="5000" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/springboot" />
<property name="username" value="root" />
<property name="password" value="mh" />
</bean>
<int:service-activator input-channel="fromdb"
ref="jdbcMessageHandler" />
<int-jdbc:inbound-channel-adapter
channel="fromdb" data-source="dataSource" query="SELECT * FROM Items WHERE INVENTORY_STATUS = 0"
update="UPDATE Items SET INVENTORY_STATUS = 1">
<int:poller fixed-delay="4000" />
</int-jdbc:inbound-channel-adapter>
我对java DSL了解不多。有人可以告诉我如何转换吗?
谢谢
解决方案
没有特定于 JDBC 的 Java DSL 工厂和构建器,但<int-jdbc:inbound-channel-adapter>
可以在IntegrationFlow
定义中使用 a 后面的组件。请参阅此文档:https ://docs.spring.io/spring-integration/docs/current/reference/html/overview.html#finding-class-names-for-java-and-dsl-configuration
<int-jdbc:inbound-channel-adapter>
因此,这里提到了一个 Java 类:
<xsd:element name="inbound-channel-adapter">
<xsd:annotation>
<xsd:documentation>
Defines a Polling Channel Adapter for the
'org.springframework.integration.jdbc.JdbcPollingChannelAdapter'
for polling a database.
</xsd:documentation>
</xsd:annotation>
这JdbcPollingChannelAdapter
是一个MessageSource
实现,因此可以在 Java DSL 中使用以下工厂方法IntegrationFlows
:
/**
* Populate the provided {@link MessageSource} object to the {@link IntegrationFlowBuilder} chain.
* The {@link org.springframework.integration.dsl.IntegrationFlow} {@code startMessageSource}.
* In addition use {@link SourcePollingChannelAdapterSpec} to provide options for the underlying
* {@link org.springframework.integration.endpoint.SourcePollingChannelAdapter} endpoint.
* @param messageSource the {@link MessageSource} to populate.
* @param endpointConfigurer the {@link Consumer} to provide more options for the
* {@link org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean}.
* @return new {@link IntegrationFlowBuilder}.
* @see MessageSource
* @see SourcePollingChannelAdapterSpec
*/
public static IntegrationFlowBuilder from(MessageSource<?> messageSource,
@Nullable Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
poller
可以使用该回调endpointConfigurer
和通过Pollers
工厂进行配置。
这<int:service-activator>
只是handle()
在 Java DSL 中,没有理由在您JdbcPollingChannelAdapter
的from()
工厂和.handle()
方法链中的下一个之间指定一个通道。它只是自然地插入其中,让我们避免直接通道的样板代码。
推荐阅读
- sql - 按日期在分组集中复制具有多个组的分组集的值
- python-3.x - 尝试使用 Raspberry pi 3 读取电机值
- charts - 如何实现居中折线图?
- typescript - Webpack,babel - node_modules 不排除在捆绑包中
- reactjs - 进行选择后隐藏或最小化搜索构面组件
- css - 具有唯一行名的网格重复
- coldfusion - 如何使用 Coldfusion 获取响应负载?
- ios - 如何通过 object.name 谓词数组内的对象
- php - Yii2模块未配置!- 选项:configFile 是必需的错误 - codeception
- python - 通过 Selenium 进行 Web 抓取时遇到“列表索引超出范围”异常