首页 > 解决方案 > Spring Integration DSL:将一些消息发送到 Flow inputChannel 的简单方法

问题描述

如果我想生成一些示例数据来测试 Spring Integration DSL 功能,那么到目前为止我想出的一种方法是这样的:

@Bean
public IntegrationFlow myFlow() {
    return IntegrationFlows
            .from(Http.inboundChannelAdapter("numbers").get())
            .scatterGather(s -> s
                    .applySequence(true)
                    .recipientFlow(f -> f.handle((a, b) -> Arrays.asList(1,2,3,4,5,6,7,8,9,10)))
            )
            .split() // unpack the wrapped list
            .split() // unpack the elements of the list
            .log()
            .get();
}

是否有另一种/更好的方法来做同样的事情?对于如此基本的东西,使用 Scatter-Gather EIP 似乎有点过头了……

标签: spring-integrationspring-integration-dsl

解决方案


您确实可以将流程中的特定内容注入MessageChannel到某个测试组件中,以将消息直接发送到该通道,以便从流程中的预期端点进行处理。目前尚不清楚 scatter-gather 在您的流程中的作用以及您在标题中谈论的频道在哪里,但另一种方法是使用@MessagingGateway界面。

在文档中查看更多信息:

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-channels


推荐阅读