繁体   English   中英

使用默认架构注册表客户端而不是Avro架构注册表客户端的Spring Cloud Stream问题

[英]Issue with Spring Cloud Stream using the Default Schema Registry client instead of the Avro Schema Registry client

我们正在将Kafka与Spring Cloud Stream一起使用,并且需要在Spring Boot组件中连接到Confluent Schema Registry,请参阅https://github.com/donalthurley/KafkaConsumeScsAndConfluent

我们添加了以下配置来创建所需的ConfluentSchemaRegistryClient bean,请参见https://github.com/donalthurley/KafkaConsumeScsAndConfluent/blob/master/src/main/java/com/example/kafka/KafkaConfig.java ,该配置应覆盖默认模式Spring Cloud Stream中的注册表。

但是,在某些部署后,我们间歇性地看到以下故障。

org.springframework.messaging.MessageDeliveryException: failed to send Message to channel

根本原因显示此堆栈跟踪

Caused by: java.lang.NullPointerException
    at     org.springframework.cloud.stream.schema.client.DefaultSchemaRegistryClient.register(DefaultSchemaRegistryClient.java:71)
    at org.springframework.cloud.stream.schema.avro.AvroSchemaRegistryClientMessageConverter.resolveSchemaForWriting(AvroSchemaRegistryClientMessageConverter.java:238)
    at org.springframework.cloud.stream.schema.avro.AbstractAvroMessageConverter.convertToInternal(AbstractAvroMessageConverter.java:179)
    at org.springframework.messaging.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:201)
    at org.springframework.messaging.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:191)
    at org.springframework.messaging.converter.CompositeMessageConverter.toMessage(CompositeMessageConverter.java:83)
    at org.springframework.cloud.stream.binding.MessageConverterConfigurer$OutboundContentTypeConvertingInterceptor.doPreSend(MessageConverterConfigurer.java:322)
    at org.springframework.cloud.stream.binding.MessageConverterConfigurer$AbstractContentTypeInterceptor.preSend(MessageConverterConfigurer.java:351)
    at org.springframework.integration.channel.AbstractMessageChannel$ChannelInterceptorList.preSend(AbstractMessageChannel.java:611)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)

AvroSchemaRegistryClientMessageConverter调用DefaultSchemaRegistryClient的事实将向我们表明ConfluentSchemaRegistryClient bean的接线存在问题。

为了确保ConfluentSchemaRegistryClient bean正确连接,我们的配置中还需要其他一些东西吗?

它为我工作。 这就是我所做的:

  • 完全像您一样使用配置类
  • 在项目中使用了@EnableSchemaRegistryClient批注
  • 将avro序列化器添加到类路径中: io.confluent:kafka-avro-serializer
  • 设置属性如下:

    spring.cloud.stream.kafka.bindings.channel.consumer.configuration.schema.registry.url =您的注册表地址spring.cloud.stream.kafka.bindings.channel.consumer.configuration.specific.avro.reader = true

其中channel对应于您应用中的频道名称。

我认为最后一个属性对于告诉Spring使用Avro序列化器而不是默认序列化器非常重要。

我正在使用Spring Cloud Stream Elmhurst.RELEASE,因此如果您使用其他版本,则属性的名称可能会略有不同。

现在,我已将@EnableSchemaRegistryClient注释移至项目应用程序类,请参见https://github.com/donalthurley/KafkaConsumeScsAndConfluent/commit/b4cf5427d7ab0a4fed619fe54b042890f5ccb594并重新部署,这已解决了将其部署到环境中时遇到的问题。

我一直在使用@EnableSchemaRegistryClient注释对生产者和消费者类进行注释。

在我所有的本地测试中,这一直与我的本地docker confluent模式注册表相对应。 但是,在部署到我们的环境中时,它大部分时间都可以正常工作,但是在某些部署后偶尔会失败。

我没有在本地复制此文件。

我在本地测试中也注意到,如果删除Confluent Schema Registry的配置,则会得到相同的空指针异常堆栈跟踪。

所以我想我看到的问题是,当项目应用程序类中不存在@EnableSchemaRegistryClient批注时,AvroSchemaRegistryClientMessageConverter Bean未与融合的架构注册表Bean关联。

我不明白为什么确实需要这样做,但我认为这可能已经解决了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM