使用replyChannel时,使用java config从子流中的网关返回

时间:2015-09-12 08:42:25

标签: spring spring-integration spring-dsl

我有以下配置

@Bean
public IntegrationFlow mainFlow(){
 return IntegrationFlows.from("channel1")
        .route("condition", p -> p
                .subFlowMapping("true", flow -> flow.gateway("channel2"))
                .subFlowMapping("false" flow -> {
                    flow.gateway("channel3", c -> c.replyChannel("aggregatorOutputChannel"));
                    flow.gateway("channel4");
                 })
        .get();
}

@Bean
public MessageChannel channel3()
{
    return MessageChannels.publishSubscribe().applySequence(true).get();
}

@Bean
public IntegrationFlow flow1(){
  return IntegrationFlows.from("channel3")
     .transform(s -> {
        System.out.println(s);
        return s;
      }
     .channel("aggregatorInputChannel")
     .get();
}

@Bean
public IntegrationFlow flow2(){
  return IntegrationFlows.from("channel3")
     .split()
     .transform(s -> {
        System.out.println(s);
        return s;
      }
     .aggregate()
     .channel("aggregatorInputChannel")
     .get();
}

@Bean
public IntegrationFlow aggregatorFlow(){
        return IntegrationFlows.from("aggregatorInputChannel")
                .aggregate((AggregatorSpec s) -> s.groupTimeout(60000)
                        .outputProcessor(new AggregationMessageGroupProcessor())
                        .sendPartialResultOnExpiry(true)
                        .expireGroupsUponCompletion(true)
                        .releaseStrategy(new TimeoutOrSequenceCountComparatorReleaseStrategy(4, 60000)), null)
                .gateway("postAggregation")
                .channel("aggregatorOutputChannel")
                .get();
}

频道3是一个pub-sub频道,有2个消费者在完成后处理消息并在aggregatorInputChannel中发送消息。然而,我观察的是,即使消息最终放在aggregatorOutputChannel中(我通过聚合器bean定义调试,我可以看到消息进入aggregatorOutputChannel),channel3上的网关阻塞并且永远不会返回。结果,消息永远不会进入channel4。

我在这里遗漏了什么吗?或做错了什么?

AggregationMessageGroupProcessor是我的自定义聚合器,我所做的只是覆盖aggregatePayloads方法

public class AggregationMessageGroupProcessor extends AbstractAggregatingMessageGroupProcessor {

  @Override
  protected final Object aggregatePayloads(MessageGroup group, Map<String, Object> headers) {
      group.getOne().getPayload();
  }
}

谢谢!

0 个答案:

没有答案