Spring 集成 DSL :: 从 xml 调用频道时遇到问题

Spring integration DSL :: facing issue when calling channel from the xml

我做了一个简单的 DSL,它从数据库中检索数据并在服务激活器中进行简单的转换。

    @Bean
public IntegrationFlow mainFlow() {
    return IntegrationFlows.from("userChannel")
                .channel("queryChannel")
                .handle("sampleConvertor","convertUser")
                .get();

queryChannel 是 jdbc 出站网关,sampleConverter 是服务激活器。

<int-jdbc:outbound-gateway query="select * from employee where employee_id=:payload"
request-channel="queryChannel" data-source="dataSource"/>

问题是从数据库中检索数据后,流程不会转到 serviceActivator,它只是 returns 返回数据库响应。

在xml配置中,我曾经像下面这样在链内调用网关。

<int:gateway id="query.gateway" request-channel="queryChannel"/>

请在这里指出我做错了什么。提前致谢。

将 Java DSL 和 XML 配置结合起来有点不寻常,但它们仍然可以一起工作。

你的问题我认为你忽略了一个事实,即你的 queryChannel 在运行时有两个订阅者,而不是调用链。

第一个是<int-jdbc:outbound-gateway>,第二个是那个.handle("sampleConvertor","convertUser")。是的,当您在 IntegrationFlow 中声明一个频道时,下一个 EIP-method 会为该频道生成一个 subscriber。同时,当您在 XML 配置中使用像 request-channelinput-channel 这样的频道时,也会带来订阅者。

因此,您在 DirectChannelRoundRobinLoadBalancingStrategy 上有两个订阅者,因此只有其中一个会处理一条消息,如果它是 request-replly 组件,那么 <int-jdbc:outbound-gateway> 它将在 output-channel 或 headers 中的 replyChannel 中生成一条消息。在你的例子中,故事恰好是关于 replyChannel 的,因此你不会去 .handle("sampleConvertor","convertUser") 因为它不是链中的下一个,而只是 round-robin 算法的平行宇宙.

如果你真的想在调用 <int-jdbc:outbound-gateway> 后达到 .handle("sampleConvertor","convertUser"),你应该考虑使用 .gateway("queryChannel") 而不是 .channel()