Kafka - 从命令行生成时出错(字符('<'(代码 60)):预期有效值) [英] Kafka - error when producing from command line (character ('<' (code 60)): expected a valid value)

查看:22
本文介绍了Kafka - 从命令行生成时出错(字符('<'(代码 60)):预期有效值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的笔记本电脑上旋转了一个 Docker 中的 Kafka(使用 docker-compose).

I spinned on my laptop a Kafka in Docker (with docker-compose).

之后,创建了新的 kafka 主题:

After that, created new kafka topic with:

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

(尚未在架构注册表中创建架构).

(did not create schema in Schema Registry yet).

现在尝试制作(基于此示例 - 第 3 步 - https://docs.confluent.io/4.0.0/quickstart.html):

Now trying to produce (based on this example - step 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 但错误是假的?谢谢.

How to solve this?
Can it be because Kafka cluster uses SSL but error is bogus? Thanks.

推荐答案

我遇到了同样的错误,但在我的情况下解决方案有所不同.我在这里发帖以防其他人觉得这很有用.

I had the same error but the solution was different in my case. I am posting here in case someone else finds this useful.

此错误与访问架构注册表和预期响应有关.因此,要么配置不正确,客户端无法评估架构注册表,要么无法识别响应.

This error is about accessing the schema registry and the expected response. So either the configuration is not correct and the client cannot assess the schema registry or the response is not recognised.

  1. 因此,请检查您提供的配置是否正确,--property schema.registry.url 在这种情况下为 Giorgos 提到.另见:https://docs.confluent.io/5.5.1/schema-registry/serdes-develop/serdes-avro.html

  1. So, check that you provide the correct configuration, --property schema.registry.url in this case as Giorgos mentioned. See also: https://docs.confluent.io/5.5.1/schema-registry/serdes-develop/serdes-avro.html

您还可以curl模式注册表以查看是否有任何响应,例如

You can also curl the schema registry to see if you get any response, like

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

另见:https://docs.confluent.io/5.5.1/schema-registry/develop/using.html


  1. 就我而言,问题是过滤流量的网络代理.所以检查:

  1. In my case the problem was a web proxy that filtered the traffic. So check:

  • NO_PROXYno_proxy 以及
  • HTTP_PROXYhttp_proxy
  • HTTPS_PROXYhttps_proxy
  • NO_PROXY, no_proxy as well as
  • HTTP_PROXY, http_proxy and
  • HTTPS_PROXY, https_proxy

确保没有任何东西拦截对注册表的调用.如果您正在创建一个 jvm 应用程序,那么相应的标志是:

to ensure that nothing intercepts the call to the registry. If you are creating a jvm application then the corresponding flags are:

  • http.nonProxyHosts,
  • http.proxyHosthttp.proxyPort,或
  • https.proxyHosthttps.proxyPort.
  • http.nonProxyHosts,
  • http.proxyHost and http.proxyPort, or
  • https.proxyHost and https.proxyPort.

这篇关于Kafka - 从命令行生成时出错(字符('&lt;'(代码 60)):预期有效值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆