kcat icon indicating copy to clipboard operation
kcat copied to clipboard

Add support for Base64-encoded output of key and/or payload data

Open jjlin opened this issue 5 years ago • 11 comments

Also includes some refactoring of Avro-related code and minor doc fixes.

jjlin avatar Nov 08 '19 05:11 jjlin

Here's a first cut at base64 support using a derivative of Jouni Malinen's base64 implementation. I started from PR #164, but it's diverged almost completely since then.

A few notes:

  • The way I'm looking at it, for the consumer, there can be an input transform ("deserialization") when reading off the Kafka topic. That corresponds to the existing -s option. There can also be an output transform (serialization) as we write to stdout/file. That corresponds to the -S option I added in this PR. Ideally these two options should be independent (e.g., you might want to unpack values read off the Kafka topic, but then write it out base64-encoded to avoid ambiguities when piped to some other tool). In this PR, -s and -S can't be used concurrently.

  • I added a consumer example (kafkacat -b mybroker -t mytopic -S base64 -K,) to the README. I think this is a pretty useful output format for piping to another tool, which can then easily read one complete key/value pair per line. There's an obvious producer analog for reading base64-encoded key/value pairs from stdin/file, splitting on the delimiter, decoding them, and writing to Kafka. Unfortunately, as in PR #151, the producer is not set up for handling this yet.

  • I've never really used Avro, so I don't have the background or environment to test the changes I made there. Hopefully someone can help with that.

jjlin avatar Nov 08 '19 05:11 jjlin

👍 for this feature

wojtek-oledzki avatar Jan 18 '20 23:01 wojtek-oledzki

Hi @jjlin - what's the current status of you work? I'm planning to build kafkacat using your branch to move some binary data. Is there anything I need to be aware of?

It would be great if the -S base64 will endup in master at some point :)

wojtek-oledzki avatar Jan 20 '20 13:01 wojtek-oledzki

@wojtek-oledzki AFAIK, the base64-encoding functionality works fine, and I'm using it myself.

jjlin avatar Jan 20 '20 19:01 jjlin

@jjlin how do you import data back to Kafka when exported with -S base64?

wojtek-oledzki avatar Jan 21 '20 09:01 wojtek-oledzki

@wojtek-oledzki To clarify what I said about "the producer is not set up for handling this yet", the kafkacat producer doesn't support transformations currently, so base64-decoding is not supported yet either.

jjlin avatar Jan 21 '20 19:01 jjlin

I also needed the producer mode and created a PR for that: https://github.com/jjlin/kafkacat/pull/1

fryckbos avatar Jan 30 '20 22:01 fryckbos

@edenhill Following up since it's been a few months. What would it take to get this merged? Is there anything you want changed in the overall approach?

jjlin avatar Mar 24 '20 04:03 jjlin

It would be great to have this PR integrated asap. I see that PR also adds base64 to -J which is great. RIght now -J is broken with binary data since it assumes that data is in UTF-8

modax avatar Apr 03 '20 06:04 modax

@edenhill May we get your thoughts on this PR?

kafkacat is a great tool, however its current limitation to non-binary data prevents us from using it.

Of the kafkacat PRs for base64 output that I have seen, this is the one I like most, because it can also encode the keys.

EugenDueck avatar Sep 02 '20 06:09 EugenDueck

hi @edenhill could you please review/respond to this PR? This feature would be very useful. If the project is dead (as asked in #424) at least make it official so people can readjust. I'm willing to make a small donation to the project if that is helpful, I get that OSS maintenance requires time and effort.

jsenko avatar Nov 03 '23 01:11 jsenko