本文介绍了如何正确实施活页夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

I'm trying to implement a binder for BigQuery in Spring Cloud Stream.

完整的应用代码可在 GitHub 上获得.

Full code of application is avaiable on GitHub.

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

So far, I've written a BigQueryBinderConfiguration class which returns a BigQueryBinder the following way

@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)不再被识别.

My problem is that when doing so, my other binders (Rabbit and Kafka) are no more recognized.

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

My testing protocol is as follows : I start my application and check in rabbitmq admin interface if my application registers as a consumer. This is not the case when this code is uncommented.

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

When debugging call to bigQueryMessageChannelBinder(....), I observe the following things.

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

The DefaultBinderFactory#getBinder(...) method always return my BigQueryBinder instance. Debugging indicates that the call to this.context.getBeansOfType(Binder.class); returns a list that only contains my BigQueryBinder. I'm puzzled, because the other binders are in my classpath, and if I remove the factory method BigQueryBinderConfiguration#bigQueryMessageChannelBinder(....), everything works fine.

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

I've discovered during debug that DefaultBinderFactory is the class that is used to associate a binder to a configuration name. I've also discovered that Binder implementations should not appear in Map<String, Binder> binders. But unfortunatly, my Binder implementation appear in that list. i guess it has something to do with the bean nature. But how ?

推荐答案

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

I think the best thing you can do is to first look at our new TestChannelBinder.java. Basically it's a full blown binder backed by Spring Integration. In other words Spring Integration and it's channels play a role of a message broker the same was Rabbit, Kafka, GCP and other binders.What's important about this binder is that it effectively demonstrates a bare minimum of what's required to implement a functioning binder.

这篇关于如何正确实施活页夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 18:17