[英]Spring cloud stream custom binder not registered. Disables the kafka binder if used @Configuration
I'm trying to make a custom spring cloud stream binder but it just wont register itself: 我正在尝试制作自定义的春季云流活页夹,但它本身不会注册:
Binder Implementation: 活页夹实现:
public class DPSBinder implements Binder<SubscribableChannel, ConsumerProperties, ProducerProperties> {
private DecisionPersistenceServiceClient dpsClient;
private MessageHandler dpsClientConsumerMessageHandler = null;
public DPSBinder(DecisionPersistenceServiceClient dpsClient) {
this.dpsClient = dpsClient;
}
@Override
public Binding<SubscribableChannel> bindConsumer(String name, String group, SubscribableChannel inboundBindTarget,
ConsumerProperties consumerProperties) {
return null;
}
@Override
public Binding<SubscribableChannel> bindProducer(String name, SubscribableChannel outboundBindTarget,
ProducerProperties producerProperties) {
switch (name) {
case "PERSIST_POST":
this.dpsClientConsumerMessageHandler = message -> dpsClient.persist((DPAPayload) message.getPayload());
break;
default:
this.dpsClientConsumerMessageHandler = null;
}
if (this.dpsClientConsumerMessageHandler != null)
this.subscribe(outboundBindTarget);
return () -> this.dpsClientConsumerMessageHandler = null;
}
public void subscribe(SubscribableChannel outboundBindTarget) {
outboundBindTarget.subscribe(this.dpsClientConsumerMessageHandler);
}}
configuration class: 配置类:
@Configuration
public class DPSBinderConfiguration {
@Bean
public DPSBinder dpsBinder(DecisionPersistenceServiceClient dpsClient) {
return new DPSBinder(dpsClient);
}}
spring.binders file: spring.binders文件:
dps:something.something.DPSBinderConfiguration
application.yml application.yml
application.yml
spring:
cloud:
stream:
bindings:
input:
destination: DPP_EVENTS
group: dpp-local
binder: kafka
output:
destination: PERSIST_POST
binder: dps
binders:
kafka:
type: kafka
dps:
type: dps
I've followed the spring cloud stream guidelines for creating a custome binder but this is not working. 我已经按照Spring Cloud Stream准则创建了一个自定义活页夹,但这是行不通的。 Moreover, using the @Configuration for creating binder beans disables the kafka binder which i've added on classpath.
此外,使用@Configuration创建活页夹bean会禁用我在类路径上添加的kafka活页夹。
I found the issue. 我发现了问题。 Actually @Configuration should not be used where the binding bean is being declared.
实际上,不应在声明绑定bean的地方使用@Configuration。 Also, there were some logical issues in My binder implementation which i fixed.
另外,我修复的我的资料夹实现中存在一些逻辑问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.