手动注册弹簧积分流和多个子流

时间:2019-07-10 15:16:08

标签: spring-integration spring-cloud-stream

升级到Spring Boot 2.1.6.RELEASE后,应用程序启动失败,并显示以下信息:

org.springframework.cloud.stream.binder.AbstractMessageChannelBinder中的字段集成流只需要一个bean,但是找到了2个:...

我正在尝试使用IntegrationFlowContext类手动注册流。

@Component
public class FlowCreator{

  @Autowired
  private IntegrationFlowContext flowContext;

  @Autowired
  private FlowExample flowExample;


  @PostConstruct
  public void registerIntegrationFlows() {

    flowContext.registration(flowExample.integrationFlow1())
    .id("integrationFlow1")
    .register();

    flowContext.registration(flowExample.integrationFlow2())
    .id("integrationFlow2")
    .register();
}

@Component
public class FlowExample {

  public IntegrationFlow integrationFlow1() {
    return IntegrationFlows.from("input")
        .<Object, Class<?>>route(Object::getClass, routeMessages()) //
        .get();
  }

  private Consumer<RouterSpec<Class<?>, MethodInvokingRouter>> routeMessages() {
    return m -> m //
        .subFlowMapping(Boolean.class, subFlow1()) 
        .subFlowMapping(Integer.class, subFlow2())
        .defaultOutputChannel("discardChannel");
  }

  private IntegrationFlow subFlow1() {
    return sf -> sf.channel("Channel1");
  }

  private IntegrationFlow subFlow2() {
    return sf -> sf.channel("Channel2");
  }

  public IntegrationFlow integrationFlow2() {
    return IntegrationFlows.from("input")
        .channel("channel3")
        .get();
  }
}

现在出现以下错误:

org.springframework.cloud.stream.binder.AbstractMessageChannelBinder中的字段集成流只需要一个bean,但是找到了2个:

  • integrationFlow1.subFlow#0:定义为空
  • integrationFlow1.subFlow#1:定义为空

1 个答案:

答案 0 :(得分:1)