首页 > 解决方案 > 如何正确实施活页夹?

问题描述

在与 Oleg 讨论期间对问题进行了大量编辑

我正在尝试在 Spring Cloud Stream 中为 BigQuery 实现一个活页夹。

应用程序的完整代码可在GitHub 上获得。

到目前为止,我已经编写了一个BigQueryBinderConfiguration返回BigQueryBinder以下方式的类

@Configuration @EnableConfigurationProperties({ BigQueryConfiguration.class })
public class BigQueryBinderConfiguration {
    @Autowired BigQueryConfiguration configuration;

    @Bean
    BigQueryBinder bigQueryMessageChannelBinder(BigQueryConfiguration configuration, BigQueryProvisioningProvider provisioningProvider) {

        return new BigQueryBinder(configuration, provisioningProvider);
    }

    @Bean BigQueryProvisioningProvider provisioningProvider() {
        return new BigQueryProvisioningProvider(configuration);
    }
}

我的问题是,这样做时,我的其他活页夹(Rabbit 和 Kafka)不再被识别。

我的测试协议如下:如果我的应用程序注册为消费者,我启动我的应用程序并检查 rabbitmq 管理界面。当此代码未注释时,情况并非如此。

在调试对 的调用时bigQueryMessageChannelBinder(....),我观察到以下情况。

DefaultBinderFactory#getBinder(...)方法始终返回我的 BigQueryBinder 实例。调试表明调用this.context.getBeansOfType(Binder.class);返回的列表仅包含我的 BigQueryBinder。我很困惑,因为其他绑定器在我的类路径中,如果我删除工厂方法BigQueryBinderConfiguration#bigQueryMessageChannelBinder(....),一切正常。

我在调试期间发现DefaultBinderFactory这是用于将活页夹与配置名称相关联的类。我还发现 Binder 实现不应该出现在Map<String, Binder> binders. 但不幸的是,我的 Binder 实现出现在该列表中。我想这与豆的性质有关。但是如何?

标签: javaspringspring-cloud-stream

解决方案


我认为您可以做的最好的事情是首先查看我们的新TestChannelBinder.java。基本上它是一个由 Spring Integration 支持的完整的活页夹。换句话说,Spring Integration 和它的通道扮演消息代理的角色,就像 Rabbit、Kafka、GCP 和其他绑定器一样。这个活页夹的重要之处在于它有效地展示了实现一个正常工作的活页夹所需的最低限度。


推荐阅读