2017-09-19 5 views
1

に複数のメッセージを送信するために失敗し、私は次のコードで遊んでいます:RouteToRecipients JavaのDSLは、私はJavaのコンフィグを使用して、春の統合で初心者ですdefaultOutputChannel

@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(); 
    } 
} 

私は2番目の統合の流れからの出力と思いますTHREE FOURなるが、それは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.springframewor[email protected]7c343fee, sequenceNumber=4, errorChannel=org.springframewor[email protected]7c343fee, sequenceSize=4, correlationId=6502c0da-c246-0c1a-64c2-211192c5248a, id=c26a054c-ab10-039e-d773-07457faf07f6, timestamp=1505822478046}] 

は、誰かが私を助けてくださいもらえますか?

答えて

0

ゲートウェイパターンは、要求/応答シナリオを表します.1つの要求と1つの応答です。それはまったく同じですが、私たちはJavaメソッドからreturnを1つしか持っていません。したがって、フローは依然として分割されたメッセージ内のreplyChannelを参照していますが、そのメッセージはすでに使用されているため、同じ要求に対してさらに返信することはできません。

実際に返信文字列としてTHREE FOURがあると思われる場合は、ゲートウェイのreplyChannelに送信する前にアグリゲータを使用することを検討する必要があります。

+0

ありがとうございました。私はflow2()に集約EIPメソッドを追加し、get()の前に.handle(System.out :: println)を追加しました。今は出力がありません。何か覚えていますか? –

+0

さて、 '.handle(System.out :: println)'は一方向です。間違いなく返事が起こることはありません。 '.handle((p、h) - > {System.out.println(p); return p;})'または単に '.log()'を使うことを考えてください。 '.aggregate()'の問題で、適切な 'ReleaseStrategy'が必要です。分割されたアイテムのすべてが 'flow2'に到達するわけではないので、カスタムロジックが必要です。 –

関連する問題