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

Implementation for KafkaRecord / blanket implementation #225

Open
DirkRusche opened this issue Apr 16, 2024 · 1 comment
Open

Implementation for KafkaRecord / blanket implementation #225

DirkRusche opened this issue Apr 16, 2024 · 1 comment

Comments

@DirkRusche
Copy link
Contributor

I have an AWS Lambda that consumes messages from Kafka topics, using the crate aws_lambda_events which provides the struct KafkaRecord.
Unfortunately, I was unable to use this library out of the box.
I ended up understanding what the library does and implementing a Deserializer similar to rdkafka.

While doing that, I noticed that the implementation impl BinaryDeserializer for ConsumerRecordDeserializer and impl<'a, T: Headers<'a>> BinaryDeserializer for Deserializer<'a, T> are almost the same.
I was wondering if this library can provide a blanket implementation for some T that implements a given trait.
The trait should provide methods to retrieve the headers, the payload and also provide the CE prefix (as it is ce_ with Kafka and ce- with http).

Something like that (just as a sketch):

trait CustomDeserializeTrait {
    fn headers(&self) -> HashMap<String, String>;
    fn payload(&self) -> Option<Vec<u8>>;
    
    fn prefix() -> &'static str;
}

impl BinaryDeserializer for T where T : CustomDeserializeTrait {
...
}

If this is from interest and I find some time, I could open a PR.
Let me know 😊

@Lazzaretti
Copy link
Member

Hey @DirkRusche,
Sorry for the late response. It would be great if we could simplify this.
It would be great if you could find some time to make a PR!

Also, an example with an AWS Lambda and Kafka would be really great :)

Feel free to ping me on Slack if you need help: https://cloud-native.slack.com/team/UTV7ZGPAR

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

No branches or pull requests

2 participants