gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:07:56 24 4
gpt4 key购买 nike

我是使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com