Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kafka-avro-console-producer not respecting --property parse.headers=true #2390

Closed
aymkhalil opened this issue Sep 23, 2022 · 5 comments · Fixed by #2494
Closed

kafka-avro-console-producer not respecting --property parse.headers=true #2390

aymkhalil opened this issue Sep 23, 2022 · 5 comments · Fixed by #2494

Comments

@aymkhalil
Copy link

aymkhalil commented Sep 23, 2022

I'm using the confluentinc/cp-schema-registry:7.2.1 docker image and trying to produce Avro messages with headers. The command is:

printf 'h1:v1,h2:v2\t{"field":"value0"}' | kafka-avro-console-producer --broker-list broker:9092 --property 'value.schema={"type":"record","name":"test","namespace":"ns","fields":[{"name":"field","type":"string"}]}' --property schema.registry.url=http://localhost:8081 --property parse.headers=true --topic users

The exception I'm getting (seems the reader is not respecting the \t delimiter and trying to parse the entire input as JSON):

[2022-09-23 05:03:00,996] INFO Kafka startTimeMs: 1663909380987 (org.apache.kafka.common.utils.AppInfoParser)
org.apache.kafka.common.errors.SerializationException: Error deserializing json h1:v1,h2:v2	{"field":"value0"} to Avro of schema {"type":"record","name":"test","namespace":"ns","fields":[{"name":"field","type":"string"}]}
	at io.confluent.kafka.formatter.AvroMessageReader.readFrom(AvroMessageReader.java:131)
	at io.confluent.kafka.formatter.SchemaMessageReader.readMessage(SchemaMessageReader.java:325)
	at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:50)
	at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'h1': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"h1:v1,h2:v2\u0009{"field":"value0"}"; line: 1, column: 3]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2391)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:745)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2961)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2002)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:802)
	at org.apache.avro.io.JsonDecoder.configure(JsonDecoder.java:124)
	at org.apache.avro.io.JsonDecoder.<init>(JsonDecoder.java:66)
	at org.apache.avro.io.JsonDecoder.<init>(JsonDecoder.java:74)
	at org.apache.avro.io.DecoderFactory.jsonDecoder(DecoderFactory.java:266)
	at io.confluent.kafka.schemaregistry.avro.AvroSchemaUtils.toObject(AvroSchemaUtils.java:215)
	at io.confluent.kafka.formatter.AvroMessageReader.readFrom(AvroMessageReader.java:124)
	... 3 more

Running the same command (leaving out the schema related config) with the kafka-console-producer tool works just fine:

printf 'h1:v1,h2:v2\t{"field":"value0"}' | kafka-console-producer --broker-list broker:9092 --property parse.headers=true --topic users
@OneCricketeer
Copy link
Contributor

OneCricketeer commented Sep 30, 2022

@OneCricketeer
Copy link
Contributor

As a workaround, kcat supports headers (and Avro)

https://github.com/edenhill/kcat#examples

@DennisFederico
Copy link

DennisFederico commented Jul 31, 2023

Doesn't seem to be fixed on 7.3.3
image

@rayokota
Copy link
Member

@DennisFederico , this was added to 7.4.0+

@DennisFederico
Copy link

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants