RouteToRecipients Java DSL 无法将多条消息发送到 defaultOutputChannel
RouteToRecipients Java DSL fails to send multiple messages to defaultOutputChannel
我是使用 Java 配置 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}]
有人可以帮助我吗?
网关模式代表request/reply场景——一请求一回复。这与我们只有一个 return
from Java 方法完全相同。因此,流仍然在拆分的消息中看到 replyChannel
,但那个已经被使用过,因此我们无法向同一请求发送更多回复。
如果您真的考虑将 THREE FOUR
作为回复字符串,您应该考虑在发送到网关的 replyChannel
之前使用聚合器。
我是使用 Java 配置 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}]
有人可以帮助我吗?
网关模式代表request/reply场景——一请求一回复。这与我们只有一个 return
from Java 方法完全相同。因此,流仍然在拆分的消息中看到 replyChannel
,但那个已经被使用过,因此我们无法向同一请求发送更多回复。
如果您真的考虑将 THREE FOUR
作为回复字符串,您应该考虑在发送到网关的 replyChannel
之前使用聚合器。