提问者:小点点

手动注册Spring集成流和多个子流


升级到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:用null定义
  • IntegrationFlow1. subFlow#1:用null定义

共1个答案

匿名用户

这已在Spring Cloud Stream2.1.1中修复:https://github.com/spring-cloud/spring-cloud-stream/commit/794c75f5364b51d7ec89335b08bfaca0f6d4d139#diff-737803e2a91ac21a17baf06ff7b4cbac.

考虑升级到Fishtown SR3,甚至Germantown GA:https://spring.io/projects/spring-cloud-stream#learn