java - 如何正确实施活页夹?
问题描述
在与 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 实现出现在该列表中。我想这与豆的性质有关。但是如何?
解决方案
我认为您可以做的最好的事情是首先查看我们的新TestChannelBinder.java。基本上它是一个由 Spring Integration 支持的完整的活页夹。换句话说,Spring Integration 和它的通道扮演消息代理的角色,就像 Rabbit、Kafka、GCP 和其他绑定器一样。这个活页夹的重要之处在于它有效地展示了实现一个正常工作的活页夹所需的最低限度。
推荐阅读
- python - system() 在 C 中调用的 Python 脚本无法将变量发送到文件
- django - Django 聚合函数是否使用索引?
- r - 计算列中出现的条纹
- node.js - 如何授权 HTTP POST 请求以使用 REST API 执行数据流模板
- react-native - React Native Expo localhost请求在android模拟器上不起作用
- excel - VBA 根据列表中的文件名导入工作表
- node.js - 如何间歇性地检查已添加到 nodejs Google Tasks API 中任务列表的新任务?
- java - Java ME SDK 平台检测失败 - Netbeans
- entity-framework - 如何解决:只有在 .Join with .Include 之后,我才会收到“No coercion operator”错误
- sml - 你如何做模式匹配是标准 ML?