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
Better interoperability between Micronaut and Spring Kafka #605
Comments
From Spring Kafka docs
https://docs.spring.io/spring-kafka/reference/htmlsingle/#headers |
To be honest I don't think we should be providing workarounds for weird things that Spring Kafka is doing. The reason Micronaut receives a double quoted string is because Spring Kafka is encoding the String as JSON in the header value. The API for headers in Kafka is that each header should have a string name and a byte[] value. Micronaut is encoding the value into a byte[] by searching for an appropriate Serde in the Serde registry: You could override the SerdeRegistry to provide custom serialisation if that is what you are after. Why Spring is not able to decode the value I don't know.. probably Spring Kafka requires configuration on how to decode it, but it seems to me that Spring Kafka is imposing some assumptions on messaging format that makes it then harder for other Kafka producers to interoperate with it |
I agree that Micronaut should not provide workarounds out of the box. But someone needs to blog about alternatives to solve this problem. And right now I'm not that person, but I'm working on it. |
I managed to create a simple custom |
I looked briefly at the Micronaut side but I was not able to create a working prototype. I could not find out how to pick a custom serializer just for the headers. |
The interoperability between Micronaut and Spring Cloud Stream Kafka binder gives me headache. Micronaut sends Kafka headers as byte arrays but Spring seems to send quoted strings. When Micronaut receives a message from Spring, header values are wrapped with "double quotes".
I don't think Micronaut does something wrong I'm just worried that interoperability issues like this will make it hard for developers to migrate.
Can we have a config option in Micronaut to quote message header values?
Steps to Reproduce
Create a Kafka client with Micronaut that contains a String header
On the Spring side create a Kafka listener with a String header
If you print the header in the Spring listener it will be byte values, not a String.
Spring recieved message from 77,105,99,114,111,110,97,117,116
Expected Behaviour
The String header should be the same string as was sent by Micronaut.
Actual Behaviour
Doing the opposite is also a problem. If you send a String header from Spring, it will be received by Micronaut wrapped with double quotes.
Environment Information
Example Application
https://github.com/goeh/micronaut-kafka-spring-issue
The text was updated successfully, but these errors were encountered: