简体   繁体   English

Spring Cloud Stream自定义活页夹未注册。 如果使用@Configuration,则禁用kafka绑定程序

[英]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.

相关问题 Spring Cloud Stream Kafka Binder 运行时配置更新 - Spring Cloud Stream Kafka Binder Configuration update at runtime 空指针:带有活页夹 kafka 的 Spring Cloud 流 - Null pointer: Spring cloud stream with binder kafka Spring Cloud Stream Kafka活页夹压缩 - Spring Cloud Stream Kafka binder compression Spring Stream kafka Binder 测试自定义标头 - Spring Stream kafka Binder Test Custom Headers Confluent Cloud Schema Registry Unauthorized错误的spring-cloud-stream-binder-kafka配置 - spring-cloud-stream-binder-kafka configuration for Confluent Cloud Schema Registry Unauthorized error Kafka中的JSON错误-Spring Cloud Stream Kafka Binder - Bad JSON in Kafka - Spring Cloud Stream Kafka Binder Spring云kafka binder查询 - Spring cloud kafka binder query 如何处理 Spring 云 stream kafka 流活页夹中的序列化错误? - How to handle Serialization error in Spring cloud stream kafka streams binder? 使用 spring-cloud-stream-binder-kafka 将 GlobalStateStore 绑定到处理器中 - Binding GlobalStateStore into Processor with spring-cloud-stream-binder-kafka Spring-Cloud-Stream-Kafka-Binder 函数风格忽略自定义 De/Serializer 和/或 useNativeEncoding? - Spring-Cloud-Stream-Kafka-Binder functional style ignores custom De/Serializer and/or useNativeEncoding?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM