Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 春季云流汇合KStream Avro消费_Spring Boot_Apache Kafka_Apache Kafka Streams_Spring Cloud Stream_Confluent Schema Registry - Fatal编程技术网

Spring boot 春季云流汇合KStream Avro消费

Spring boot 春季云流汇合KStream Avro消费,spring-boot,apache-kafka,apache-kafka-streams,spring-cloud-stream,confluent-schema-registry,Spring Boot,Apache Kafka,Apache Kafka Streams,Spring Cloud Stream,Confluent Schema Registry,我正在尝试使用SpringBoot2.0将来自kafka主题的融合avro消息作为Kstream 我可以将消息作为MessageChannel使用,但不能作为KStream使用 DemokstreamApplication.java KafkaConsumer.java KstreamBinding.java 更新1: 我应用了德图兰斯基的建议,错误消失了。但是,仍然无法将消息作为KStream使用。控制台中没有错误 更新2: 应用了sobychacko的建议,消息在对象中具有空值 我对GitH

我正在尝试使用SpringBoot2.0将来自kafka主题的融合avro消息作为Kstream

我可以将消息作为MessageChannel使用,但不能作为KStream使用

DemokstreamApplication.java

KafkaConsumer.java

KstreamBinding.java

更新1:

我应用了德图兰斯基的建议,错误消失了。但是,仍然无法将消息作为KStream使用。控制台中没有错误

更新2:

应用了sobychacko的建议,消息在对象中具有空值

我对GitHub示例进行了修改,以从spring boot本身生成消息,并且仍然将其作为空值获取


感谢您在这个问题上花时间。

尝试spring.cloud.stream.kafka.streams.binder.configuration.schema.registry.url:…

尝试spring.cloud.stream.kafka.binder.configuration.schema.registry.url:…

以下实现将不会实现您的意图:

@StreamListener
    public void processOrganization(@Input(KstreamBinding.ORGANIZATION)KStream<String, Organization> organization) {
        log.info("Organization Received:" + organization);
 }
配置中还存在一个问题,您错误地将avro Serde分配给实际上是字符串的键。更改如下:

default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
通过这些更改,每次向主题发送内容时,我都会收到日志语句。但是,在发送groovy脚本时有一个问题,我没有从您的组织域中获得任何实际数据,但我会让您解决这个问题

关于组织域对象为空的问题的更新 发生这种情况是因为您有一种混合模式的序列化策略。您在生产者端使用SpringCloud Stream的avro消息转换器,但在Kafka Streams处理器上使用合流的avro Serdes。我刚刚尝试了Confluent的序列化程序,从生产者到处理器,我都能看到出站的组织域。下面是修改后的配置,以使序列化一致

spring:
  application:
    name: kstream
  cloud:
    stream:
      schemaRegistryClient:
        endpoint: http://localhost:8081
      schema:
        avro:
          schema-locations: classpath:avro/Organization.avsc
      bindings:
        organizationInput:
          destination: organization-updates
          group: demokstream.org
          consumer:
            useNativeDecoding: true
        organizationOutput:
          destination: organization-updates
          producer:
            useNativeEncoding: true
      kafka:
        bindings:
          organizationOutput:
            producer:
              configuration:
                key.serializer: org.apache.kafka.common.serialization.StringSerializer
                value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
                schema.registry.url: http://localhost:8081
        streams:
          binder:
            brokers: localhost
            configuration:
              schema.registry.url: http://localhost:8081
              commit:
                interval:
                  ms: 1000
              default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde


您还可以从主应用程序类中删除Kafkanconfig类以及EnableSchemaRegistrCyclient注释

以下实现无法实现您的预期:

@StreamListener
    public void processOrganization(@Input(KstreamBinding.ORGANIZATION)KStream<String, Organization> organization) {
        log.info("Organization Received:" + organization);
 }
配置中还存在一个问题,您错误地将avro Serde分配给实际上是字符串的键。更改如下:

default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
通过这些更改,每次向主题发送内容时,我都会收到日志语句。但是,在发送groovy脚本时有一个问题,我没有从您的组织域中获得任何实际数据,但我会让您解决这个问题

关于组织域对象为空的问题的更新 发生这种情况是因为您有一种混合模式的序列化策略。您在生产者端使用SpringCloud Stream的avro消息转换器,但在Kafka Streams处理器上使用合流的avro Serdes。我刚刚尝试了Confluent的序列化程序,从生产者到处理器,我都能看到出站的组织域。下面是修改后的配置,以使序列化一致

spring:
  application:
    name: kstream
  cloud:
    stream:
      schemaRegistryClient:
        endpoint: http://localhost:8081
      schema:
        avro:
          schema-locations: classpath:avro/Organization.avsc
      bindings:
        organizationInput:
          destination: organization-updates
          group: demokstream.org
          consumer:
            useNativeDecoding: true
        organizationOutput:
          destination: organization-updates
          producer:
            useNativeEncoding: true
      kafka:
        bindings:
          organizationOutput:
            producer:
              configuration:
                key.serializer: org.apache.kafka.common.serialization.StringSerializer
                value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
                schema.registry.url: http://localhost:8081
        streams:
          binder:
            brokers: localhost
            configuration:
              schema.registry.url: http://localhost:8081
              commit:
                interval:
                  ms: 1000
              default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde


您还可以从主应用程序类中删除Kafkanconfig类以及EnableSchemaRegistrCyclient注释

谢谢德图兰斯基。我看到错误消失了。但是,我无法将消息作为KStream使用,并且没有报告错误。您能否将该示例简化为一个处理器?以及一些复制该问题的说明。我还想知道您是否可以升级到活页夹的最新版本3.0.0.release并重试。我已将示例应用程序简化为只有一个处理器,并在此处的自述中添加了说明,正如你所建议的,我试图升级到最新的3.0.0.RELEASE,但收到了失败的内省类,在同一个read me中捕获到了这一点。当你说升级到3.0.0.RELEASE时,我想我可能也需要升级spring boot,不是吗?只是检查是否无法在SpringBoot2.0.0.RELEASE中工作。非常感谢。谢谢德图兰斯基。我看到错误消失了。但是,我无法将消息作为KStream使用,并且没有报告错误。您能否将该示例简化为一个处理器?以及一些复制该问题的说明。我还想知道您是否可以升级到活页夹的最新版本3.0.0.release并重试。我已将示例应用程序简化为只有一个处理器,并在此处的自述中添加了说明,正如你所建议的,我试图升级到最新的3.0.0.RELEASE,但收到了失败的内省类,在同一个read me中捕获到了这一点。当你说升级到3.0.0.RELEASE时,我想我可能也需要升级spring boot,不是吗?只是检查是否无法在SpringBoot2.0.0.RELEASE中工作。非常感谢。谢谢你回来。我认为空对象问题与groovy无关,它似乎在其他地方。我试图从斯普林那里传达信息
使用相同的GitHub示例引导自身并获得相同的空对象。下面是我更新的提交答案。请尝试进行这些更改,看看它是否解决了您的问题。感谢更新。是的,提供的更新解决方案有效。使用下面的属性是有效的。spring.cloud.stream.bindings.organizationInput.consumer.UseNativeDecode=true spring.cloud.stream.bindings.organizationOutput.producer.UseNativeEncode=true感谢您回到这里。我认为空对象问题与groovy无关,它似乎在其他地方。我尝试使用相同的GitHub示例从spring boot本身生成消息,并获得相同的空对象。下面是我更新的提交答案。请尝试进行这些更改,看看它是否解决了您的问题。感谢更新。是的,提供的更新解决方案有效。使用下面的属性是有效的。spring.cloud.stream.bindings.organizationInput.consumer.UseNativeDecode=true spring.cloud.stream.bindings.organizationOutput.producer.UseNativeEncode=true
public interface KstreamBinding {

    String ORGANIZATION_INPUT= "organizationInput";
    String ORGANIZATION_OUTPUT= "organizationOutput";

    @Input(ORGANIZATION_INPUT)
    KStream<String, Organization> organizationInputMessageChannel();

    @Output(ORGANIZATION_OUTPUT)
    MessageChannel organizationOutputMessageChannel();
}
@StreamListener
    public void processOrganization(@Input(KstreamBinding.ORGANIZATION)KStream<String, Organization> organization) {
        log.info("Organization Received:" + organization);
 }
 @StreamListener
    public void processOrganization(@Input(KstreamBinding.ORGANIZATION) KStream<String, Organization> organization) {

        organization.foreach((s, organization1) -> log.info("Organization Received:" + organization1));
    }
default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
spring:
  application:
    name: kstream
  cloud:
    stream:
      schemaRegistryClient:
        endpoint: http://localhost:8081
      schema:
        avro:
          schema-locations: classpath:avro/Organization.avsc
      bindings:
        organizationInput:
          destination: organization-updates
          group: demokstream.org
          consumer:
            useNativeDecoding: true
        organizationOutput:
          destination: organization-updates
          producer:
            useNativeEncoding: true
      kafka:
        bindings:
          organizationOutput:
            producer:
              configuration:
                key.serializer: org.apache.kafka.common.serialization.StringSerializer
                value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
                schema.registry.url: http://localhost:8081
        streams:
          binder:
            brokers: localhost
            configuration:
              schema.registry.url: http://localhost:8081
              commit:
                interval:
                  ms: 1000
              default:
                key:
                  serde: org.apache.kafka.common.serialization.Serdes$StringSerde
                value:
                  serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde