java - RouteToRecipients Java DSL 无法将多个消息发送到 defaultOutputChannel

标签 java spring-integration dsl spring-java-config

我是使用 Java Config 进行 Spring 集成的初学者,我正在使用以下代码:

@EnableIntegration
@Configuration
@EnableAutoConfiguration
@IntegrationComponentScan
public class testing {
    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext ctx = new SpringApplicationBuilder(org.springframework.integration.samples.si4demo.springone.h.testing.class).web(WebApplicationType.NONE).run(args);
        System.out.println(ctx.getBean(org.springframework.integration.samples.si4demo.springone.h.testing.FooService.class).foo1("one two three four"));
        ctx.close();
    }

    @MessagingGateway(defaultRequestChannel="foo1")
    public interface FooService { String foo1(String request);}

    @Bean(name = PollerMetadata.DEFAULT_POLLER)
    public PollerMetadata poller() { return Pollers.fixedDelay(100).maxMessagesPerPoll(10).get();}

    @Bean
    public MessageChannel foo1() { return new DirectChannel(); }

    @Bean
    public MessageChannel foo2() { return new QueueChannel(5);}

    @Bean
    public MessageChannel foo3() { return new QueueChannel(5);}

    @Bean
    public MessageChannel foo4() { return new QueueChannel(5);}

    @Bean
    public MessageChannel foo5() { return new QueueChannel(5);}

    @Bean
    IntegrationFlow flow() {
        return IntegrationFlows.from(foo1()).split(e->e.delimiters(" ")).channel(foo2())
                .routeToRecipients(r->r.defaultOutputChannel(foo3()).
                        recipient("foo4","'one'==payload").
                        recipient("foo5","'two'==payload"))
                .get();
    }

    @Bean IntegrationFlow flow2()
    {
        return IntegrationFlows.from(foo3()).transform(String.class,s->s.toUpperCase())
                .get();
    }
}

我认为第二个集成流程的输出应该是三四,但它只输出三并带有警告:

15:01:18.046 [task-scheduler-2] WARN  o.s.m.c.GenericMessagingTemplate$TemporaryReplyChannel - Reply message received but the receiving thread has already received a reply:GenericMessage [payload=FOUR, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7c343fee, sequenceNumber=4, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@7c343fee, sequenceSize=4, correlationId=6502c0da-c246-0c1a-64c2-211192c5248a, id=c26a054c-ab10-039e-d773-07457faf07f6, timestamp=1505822478046}]

有人可以帮我吗?

最佳答案

网关模式代表请求/回复场景 - 一个请求和一个回复。这与 Java 方法只有一个返回的方式完全相同。因此,流程仍然会在分割的消息中看到 replyChannel,但该 channel 已被使用,因此,我们无法向同一请求发送更多回复。

如果您确实考虑使用 THREE FOUR 作为回复字符串,则应考虑在发送到网关的 replyChannel 之前使用聚合器。

关于java - RouteToRecipients Java DSL 无法将多个消息发送到 defaultOutputChannel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46299978/

相关文章:

java - 单击按钮打开空白屏幕

java - 带有 Crystal Reports 插件的 Eclipse 中的 JSP 支持

java - 嵌套注入(inject)导致 Bean 转换错误

blogs - 领域特定语言博主

elasticsearch - 如何在match_all elasticsearch中增加字段

java - 从其类返回泛型类型的实例

java - 警告 : Error while registering Oracle JDBC Diagnosability MBean

spring - 如何在 batch-int :job-launching-gateway? 中运行异步批处理作业

java - Spring Integration Gateway 中的静态和动态 header

groovy - 在 Groovy DSL 中使用 'owner' 属性