检索ID为1的Avro架构时出错,找不到主题。错误代码:40401

时间:2018-05-25 10:12:12

标签: apache-kafka avro confluent confluent-schema-registry

Caused by: org.apache.kafka.common.errors.SerializationException: Error retrieving Avro schema for id 1
Caused by: io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException: Subject not found.; error code: 40401

汇编版本4.1.0

我正在使用KTable从几个主题(topic_1,topic_2)中消费数据,加入数据,然后使用KStream将数据推送到另一个主题(topic_out)。 (Ktable.toStream())

数据采用avro格式

当我使用

检查架构时
curl -X GET http://localhost:8081/subjects/ 

我找到了

topic_1-value
topic_1-key
topic_2-value
topic_2-key
topic_out-value

但没有使用topic_out-key的主题。为什么没有创建?

来自topic_out的输出:

kafka-avro-console-consumer --bootstrap-server localhost:9092 --from-beginning --property print.key=true --topic topic_out

"code1  "   {"code":{"string":"code1  "},"personid":{"string":"=NA="},"agentoffice":{"string":"lic1        "},"status":{"string":"a"},"sourcesystem":{"string":"ILS"},"lastupdate":{"long":1527240990138}}

我可以看到正在生成的密钥,但没有密钥主题。

为什么需要密钥主题?
我将此主题提供给另一个连接器(hdfs-sink)以将数据推送到hdfs,但它失败并出现以下错误

Caused by: org.apache.kafka.common.errors.SerializationException: Error retrieving Avro schema for id 5\nCaused by: io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException: Subject not found.; error code: 40401

当我查看schema-registry.logs时,我可以看到:

[2018-05-24 15:40:06,230] INFO 127.0.0.1 - - 
[24/May/2018:15:40:06 +0530] "POST /subjects/topic_out-key?deleted=true HTTP/1.1" 404 51  9 (io.confluent.rest-utils.requests:77)

任何想法为什么没有创建主题topic_out-key?

1 个答案:

答案 0 :(得分:1)

  

不知道为什么主题topic_out-key未被创建的任何想法

因为Kafka Streams输出的键是一个字符串,而不是Avro编码的字符串。

您可以验证使用kafka-console-consumer代替并添加--property print.value=false并在打印值时没有看到与同一命令相比的任何特殊字符(这表明数据是二进制Avro)

在Kafka Connect中,您必须对key.converter属性使用Kafka的StringConverter类,而不是Confluent Avro一个。