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

标签 java spring spring-integration

嘿,这是我之前发布的关于将消息驱动的 channel 适配器连接到多个队列而不将每个队列都写出来的问题的后续。

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

我尝试遵循建议的方法:

Spring multiple imapAdapter

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

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

子上下文的所有这些实例现在都输入到不同的队列中,并将消息放入由父上下文监听的公共(public) channel (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

我需要首先加载父上下文(带有订阅者),然后将其分配给每个子上下文,因此当父上下文加载时,不会有人发布到 channel 。

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

最佳答案

java.lang.NoClassDefFoundError: org.reactivestreams.Publisher

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

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

关于java - 动态入站适配器连接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33721603/

相关文章:

java - 使用 Estimote SDK 的信标检测在 Android Lollipop 中崩溃

java - QueryDsl 对 Map 字段键的 Web 查询

spring-integration - 当与代理的连接断开时,如何防止AMQP(RabbitMQ)消息被黑洞?

esb - spring integration esb的可靠性

java - 目标是从我的项目中删除文件不起作用

具有抽象方法的 Java 高级枚举并用于分支

java - 特定子串的长度

java - 在 spring 中有条件地创建 bean

java - 从父 POM 覆盖 spring-boot 版本

java - 具有单个 war 文件的 Spring 多模块项目,其中所有模块仅依赖于公共(public)模块