-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Spring Kafka does not allow multiple headers with same key #3067
Comments
@poznachowski If we change this outright so that multiple values are allowed, it may break existing consumer applications relying on a single value for the header. For example, suppose a producer application sends two values for a key. In that case, a consumer application built with a prior version of Spring Kafka may stop working or result in incorrect behavior. Even if we introduce some special headers on the producer side to opt-in for this, how do the existing consumer apps know about it? It feels like we need to think through the consequences before implementing this feature. |
Well, that is a I don't treat this is a bug since we never advertised such a behavior from the We may revise the default logic into something similar what we have in the Kafka record has always had a multi-entry capabilities... |
@poznachowski We had an internal discussion on this matter and this is something we can adjust in the |
Thank you for quick response. Everything makes sense. I'm willing to help with a PR. Any guidelines would be much appreciated. |
@poznachowski Here are the contribution guidelines: https://github.com/spring-projects/spring-kafka/blob/main/CONTRIBUTING.adoc. If you have any specific questions, please let us know. |
…ey with SimpleKafkaHeaderMapper
I added very basic draft of |
…ey with SimpleKafkaHeaderMapper
…h SimpleKafkaHeaderMapper
…h SimpleKafkaHeaderMapper
…h SimpleKafkaHeaderMapper
I'm using Spring Kafka 3.1.2
Apache Kafka allows to have multiple headers with same key, but Spring Kafka limits that.
Sample project reproducting the issue is available here:
https://github.com/poznachowski/sample-spring-kafka-headers
When I use Listener with
ConsumerRecord
directly as payload I can see all the headers:ConsumerRecord payload: SomePayload[value=payload], headers: RecordHeaders(headers = [RecordHeader(key = testHeader, value = [118, 97, 108, 117, 101, 49]), RecordHeader(key = testHeader, value = [118, 97, 108, 117, 101, 50])], isReadOnly = false)
But I'd like to use much more convenient Spring abstractions such as:
@Payload
and@Headers
, but with this approach I'm getting only a singletestHeader
value:headers: {kafka_offset=11, testHeader=[B@67388d79, ...
The reason for that is that
KafkaHeaderMapper
implementations usesMap.put
method that effective replaces value with the latest.The text was updated successfully, but these errors were encountered: