RouteToRecipients Java DSL无法向defaultOutputChannel发送多条消息
我是使用Java Config进行spring集成的初学者,正在使用以下代码:RouteToRecipients Java DSL无法向defaultOutputChannel发送多条消息,java,spring-integration,dsl,spring-java-config,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 c
@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();
}
}
我认为第二个集成流的输出应该是3-4,但它只输出3个警告:
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方法中只有一个
return
完全相同。因此,流仍然可以在拆分的消息中看到replyChannel
,但该消息已被使用,因此,我们无法对同一请求发送更多的回复
如果你真的认为有<代码> 34 /代码>作为回复字符串,你应该考虑在发送给网关的<代码> RetryChans之前使用聚合器。 网关模式表示请求/应答场景-一个请求和一个应答。这与Java方法中只有一个
return
完全相同。因此,流仍然可以在拆分的消息中看到replyChannel
,但该消息已被使用,因此,我们无法对同一请求发送更多的回复
如果你真的认为有<代码> 34 /代码>作为回复字符串,你应该考虑在发送给网关的<代码> RetryChans之前使用聚合器。 谢谢你的回复。我在flow2()中添加了聚合EIP方法,在get()之前添加了.handle(System.out::println),现在没有输出。你有什么想法吗?嗯,
.handle(System.out::println)
是单向的。答案肯定不会出现。您应该考虑使用<代码>句柄((p,h)-> { So..Out.PrtLn(p);返回p;})或只是<代码>。.aggregate()
的问题是,您需要有一个适当的发布策略
。由于并非所有拆分的项目都将到达flow2
,因此您需要一些自定义逻辑。感谢您的回复。我在flow2()中添加了聚合EIP方法,在get()之前添加了.handle(System.out::println),现在没有输出。你有什么想法吗?嗯,.handle(System.out::println)
是单向的。答案肯定不会出现。您应该考虑使用<代码>句柄((p,h)-> { So..Out.PrtLn(p);返回p;})或只是<代码>。.aggregate()
的问题是,您需要有一个适当的发布策略
。由于并非所有拆分的项目都将到达flow2
,因此需要一些自定义逻辑。