动态入站适配器连接不起作用

Dynamic Inbound adapter hookup isn't working

嘿,这是对我之前发布的关于将消息驱动的通道适配器连接到多个队列而不写出每个队列的问题的跟进。

How to hook up a list of message driven adapters without actually writing each one out?

我尝试遵循建议的方法:

现在我有了这个配置(子),它从它的环境中获取属性(比如队列名称)并相应地创建消息驱动的适配器。

@Autowired
private ApplicationContext context;

@Value("${id}")
private String id;

@Value("${primaryConnection}")
private String primaryConnection;

@Value("${queueName}")
private String queueName;   

@Bean
public IntegrationFlow primaryInitiationListenerFlow() {
    return IntegrationFlows.from(Jms
                .messageDriverChannelAdapter(context.getBean(primaryConnection, ConnectionFactory.class))
                .autoStartup(false)
                .destination(queueName)
                .configureListenerContainer(listenerContainerSpec())
                .id(id + "PrimaryIn")
                .get())
            .channel("initiationChannel")
            .get();
}

在应用程序启动时,我遍历我拥有的队列名称列表,并为每个队列名称实例化上述上下文,并将我的主上下文作为父上下文,并传入适当的环境。

public void onApplicationEvent(ContextRefreshedEvent event) {
    for(String infoKey : clientConfig.getPairs().keySet()) {
        PairInfo info = clientConfig.getPairs().get(infoKey);
        Properties properties = info.getProperties();
        StandardEnvironment environment = new StandardEnvironment();
        environment.getPropertySources().addLast(new PropertiesPropertySource("connectionProps", properties));
        AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
        child.register(InboundFlow.class);
        child.setId(properties.getProperty("id"));
        child.setParent(context);
        child.setEnvironment(environment);
        child.refresh();
    }
}

子上下文的所有这些实例现在都被送入不同的队列,并将消息放入由父级监听的公共通道(initiationChannel)。

@Bean
public IntegrationFlow initiationAndDataFlow() {
    return IntegrationFlows
            .from("initiationChannel")
            .handle(//doStuff)
            .get();
}

我已经在父级中定义了 initiationChannel 并像 Gary 在示例中所做的那样进行设置。

但是当我启动 spring 上下文时,我收到此错误消息说 initiationChannel 没有发布者:

Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: >Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: >Factory method 'initiationAndDataFlow' threw exception; nested exception is >java.lang.NoClassDefFoundError: org.reactivestreams.Publisher

我有点需要先加载父上下文(与订阅者一起),然后将其分配给每个子上下文,因此当有父上下文加载时,不会有任何人发布到频道。

我不知道我做错了什么。感谢您的帮助。

java.lang.NoClassDefFoundError: org.reactivestreams.Publisher

您的类路径中缺少 reactive-streams-1.0.0.jar

您应该为您的项目使用 maven 或 gradle 以确保所有依赖项都已解决。