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

Add basic support for converting Avro records to JSON for output #151

Merged
merged 12 commits into from
Jul 8, 2019

Conversation

llofberg
Copy link
Contributor

@llofberg llofberg commented Aug 19, 2018

This change is Reviewable

Requires libavro and libserdes to compile.
@Marcelovk
Copy link

This is awesome, I was able to compile with it and is much better than using kafka-avro-console-consumer. The only thing that I missed is the documentation in the command line describing -a,-A and -s options

Copy link

@sknop sknop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me on Mac after a small modification of configure.kafkacat.

Great work!

if [[ $WITH_AVRO == y ]] && \
mkl_lib_check --static=-lserdes "serdes" HAVE_SERDES disable CC "-lserdes -lavro" \
"#include <stdlib.h>
#include <libserdes/serdes-avro.h>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like on Mac you need to include
#include <sys/types.h>
as well or the test compile will fail.

Copy link

@sknop sknop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: specifying -A or -a without -s "schema-registry-url" crashes kafkacat with segmentation fault. Should be caught and properly dealt with in the argument parsing.

@ryansobol
Copy link

Patiently awaiting this feature...

@casidiablo
Copy link

My C mojo is very rusty... it took me a while to compile it on MacOS. This is what I had to do:

brew install cmake
brew install automake
brew install pkgconfig
brew install jansson

./bootstrap.sh

@homer6
Copy link

homer6 commented Jan 18, 2019

@edenhill @sknop What is still required for this to be merged into the mainline?

@edenhill
Copy link
Owner

Sorry for the delay, busy finalizing the librdkafka v1.0 release. Will tend to this in a week or two.

@arifalkner
Copy link

@casidiablo You also have to install avro-c to compile:

brew install avro-c

@KarthikRangaraju
Copy link

Looking forward to this feature to get merged 👍

@arifalkner
Copy link

@edenhill What's the ETA on getting this merged?

@edenhill
Copy link
Owner

librdkafka v1.0.0 is going out tonight, should be able to address kafkacat PRs next week and get a new kafkacat release out.

@jataggart
Copy link

this would be really great to have, any updates?

@bigkraig
Copy link

friendly ping @edenhill

@avegancafe
Copy link

Any update on this? I use kafkacat quite often and would love this support!

@arifalkner
Copy link

I understand if you are swamped with work and might also consider accepting other people to maintain this repo. I appreciate all the hard work you've put into this tool and I'm sure we'd love to help continue support your workload for continuing on adding new features

@edenhill
Copy link
Owner

Please try out this docker image to consume Avro-encoded messages:
docker run edenhill/kafkacat:sr-wip -b YOURBROKER -s YOUR_SR_URL -C -t YOUR_TOPIC -a value -Ee -J | jq .payload.some.avro.field

@cecchisandrone
Copy link

Please try out this docker image to consume Avro-encoded messages:
docker run edenhill/kafkacat:sr-wip -b YOURBROKER -s YOUR_SR_URL -C -t YOUR_TOPIC -a value -Ee -J | jq .payload.some.avro.field

I tried and I receive "payload_error": "Invalid CP1 magic byte 32, expected 0". there is no request to schema registry. I was wondering what is the subject convention to gather the schema. Is it modifiable?

@edenhill
Copy link
Owner

@cecchisandrone That means the message value/payload was not serialized by a schema-registry-aware producer.

The schema-registry-aware avro producer prefixes the serialized avro data with a short header that includes a magic value and the schema-id, this is what the consumer uses to look up the schema and deserialize the message.

@Marcelovk
Copy link

@edenhill That command works correcly for me. I also tried with -f "%k : %s\n" . This feature will be a great addition to kafkacat

@edenhill edenhill mentioned this pull request Jun 18, 2019
@cecchisandrone
Copy link

Tested with a correct topic. It seems to work.

 * refactoring and fixes of the original PR
 * added key_error, payload_error optional fields to JSON message
   envelope to indicate deserialization errors.
 * prepare for future Avro producer when we (or preferably avro-c)
   figure out how to convert JSON to Avro.
 * fix librdkafka version in bootstrap.sh
 * make Dockerfile rely more on bootstrap.sh
 * use edenhill fork of yajl to allow embedding the avro-to-json
   deserialized message key/value directly in the JSON envelope with -J.
@edenhill edenhill force-pushed the output_avro_as_json branch from 2546e5f to 3ba4ebc Compare July 5, 2019 16:26
@edenhill
Copy link
Owner

edenhill commented Jul 7, 2019

Added generic deserializers (for various ints, char, string, inpspired by Python's struct.unpack) and changed the command line arguments.
I believe this is a more flexible and future-proof path forward.

Please try out this latest change in with edenhill/kafkacat:serdes-wip (docker image).

@edenhill edenhill force-pushed the output_avro_as_json branch 4 times, most recently from 7cbaaf4 to edc5d3e Compare July 8, 2019 21:49
@edenhill edenhill force-pushed the output_avro_as_json branch from edc5d3e to 490b3c3 Compare July 8, 2019 21:54
@edenhill edenhill merged commit c0e4521 into edenhill:master Jul 8, 2019
@edenhill
Copy link
Owner

edenhill commented Jul 8, 2019

Thanks for your contribution and your patience!

@cecchisandrone
Copy link

Is there also a plan to support for AVRO serialization?

@cecchisandrone
Copy link

Also, I wanted to test this on latest master build on windows. Should I need to enable something in the build config? I receive this message after building kafkacat on windows:
% ERROR: This build of kafkacat lacks Avro/Schema-Registry support

@edenhill
Copy link
Owner

We'll add Avro serialization in a later version (incremental delivery, aight?!).

Windows support is further down the line since libserdes is not supported on Windows yet.

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 this pull request may close these issues.