Kafka - 从命令行生成时出错(字符("<"(代码 60)):预期为有效值)



我在笔记本电脑上旋转了docker的kafka(带有docker-compose(。

之后,用以下方式创建了新的Kafka主题:

kafka-topics --zookeeper localhost:2181  --create --topic simple    --replication-factor 1 --partitions 1

(尚未在架构注册表中创建模式(。

现在尝试生产(基于此示例 - 步骤3 -https://docs.confluent.io/4.0.0/quickstart.html(:

kafka-avro-console-producer 
         --broker-list localhost:9092 --topic simple 
         --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'

输入值:

{"f1": "value1"}

错误:

{"f1": "value1"}
org.apache.kafka.common.errors.SerializationException: Error registering Avro schema: {"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}
Caused by: io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 2]; error code: 50005
    at io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:191)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:218)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:307)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:299)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:294)
    at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.registerAndGetId(CachedSchemaRegistryClient.java:61)
    at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:100)
    at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.serializeImpl(AbstractKafkaAvroSerializer.java:79)
    at io.confluent.kafka.formatter.AvroMessageReader.readMessage(AvroMessageReader.java:166)
    at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:59)
    at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)

如何解决这个问题?
可以是因为Kafka群集使用SSL,但是错误是虚假的?谢谢。

kafka-avro-console-producer,默认情况下,假设模式注册表正在端口http://localhost:8081侦听。但是,如果另一个过程正在聆听该端口,可能会发生奇怪的错误。

为了克服此问题,您可以使用--property schema.registry.url=http://localhost:18081

在运行生产者时指定模式URL

例如,

kafka-avro-console-producer 
         --broker-list localhost:9092 --topic simple 
         --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}' 
         --property schema.registry.url=http://localhost:18081

i有相同的错误,但在我的情况下,解决方案有所不同。我在这里发布,以防其他人觉得这很有用。

此错误是关于访问架构注册表和预期响应。因此,要么该配置不正确,因此客户端无法评估模式注册表,或者未识别响应。

  1. 因此,请检查您提供正确的配置,如Giorgos所述,在这种情况下,--property schema.registry.url。另请参阅:https://docs.confluent.io/5.5.1/schema-registry/serdes-develop/serdes-avro.html

  2. 您也可以curl架构注册表查看是否得到任何响应,例如

    curl -X GET http://localhost:8081/subjects
    

    另请参见:https://docs.confluent.io/5.5.5.1/schema-registry/develop/using.html


  1. 在我的情况下,问题是一个过滤流量的Web代理。所以检查:

    • NO_PROXYno_proxy以及
    • HTTP_PROXYhttp_proxy
    • HTTPS_PROXYhttps_proxy

    确保没有什么可以拦截对注册表的呼叫。如果要创建JVM应用程序,则相应的标志为:

    • http.nonProxyHosts
    • http.proxyHosthttp.proxyPort,或
    • https.proxyHosthttps.proxyPort

相关内容

最新更新