如何在 spring 集成中使用 java dsl 将 db poller xml 配置转换为 java 配置
How to convert db poller xml configurations to java configurations using java dsl in spring integration
正在尝试在 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
定义中使用。
请参阅此文档: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 class 在这里提到:
<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) {
可以使用 endpointConfigurer
回调和 Pollers
工厂配置 poller
。
<int:service-activator>
只是 Java DSL 中的 handle()
并且没有理由在 from()
工厂中的 JdbcPollingChannelAdapter
和方法链中的下一个 .handle()
。它只是自然地插入其中,让我们避免直接频道的样板代码。
正在尝试在 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
定义中使用。
请参阅此文档: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 class 在这里提到:
<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) {
可以使用 endpointConfigurer
回调和 Pollers
工厂配置 poller
。
<int:service-activator>
只是 Java DSL 中的 handle()
并且没有理由在 from()
工厂中的 JdbcPollingChannelAdapter
和方法链中的下一个 .handle()
。它只是自然地插入其中,让我们避免直接频道的样板代码。