Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Better interoperability between Micronaut and Spring Kafka #605
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".
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.
The String header should be the same string as was sent by Micronaut.
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.
From Spring Kafka docs
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 managed to create a simple custom