$ the-wire · showcase
Spring Kafka fixes multi-value header loss with JSON types
By RepoJournal · Filed · About Spring
Spring Kafka now preserves all values of multi-value headers when JSON type mapping is in play, closing a data-loss bug in JsonKafkaHeaderMapper.
Spring Kafka's JsonKafkaHeaderMapper was dropping earlier values of multi-value headers. In toHeaders, headers without a spring_json_header_types entry were the only ones routed through fromUserHeader, which holds the multi-value collection logic. Any non-byte[] outbound value produces a JSON types entry, and populateJsonValueHeader used headers.put(...) in every branch, so successive values overwrote each other and only the last value survived. The fix in commit f2ccb74 is in the develop branch; it is not yet released. If you send multi-value headers with non-byte[] values using JSON type mapping, your consumers have been seeing only the final value. [1]
Coming along in the same develop branch, the PR initially called 'Apply Nullability to ReplyingKafkaOperations' brings consistent @Nullable annotations to sendAndReceive and its overloads in both ReplyingKafkaOperations and ReplyingKafkaTemplate. This is an API annotation change, not a runtime behavior change in itself, but it does affect nullability contracts for callers and tooling. The work is marked for auto-cherry-pick to the 4.1.x and 4.0.x maintenance branches, so it will land there as well. [2]
Action items
- → Review JsonKafkaHeaderMapper behavior in your Kafka producers if you send multi-value headers with non-byte[] values; the fix lands in a future release of spring-kafka spring-projects/spring-kafka [plan]
- → Watch for the nullability annotation update to ReplyingKafkaOperations in 4.0.x and 4.1.x maintenance branches spring-projects/spring-kafka [monitor]
References
- [1] GH-4623: Fix multi-value headers with JSON types ↗ spring-projects/spring-kafka
- [2] Apply Nullability to ReplyingKafkaOperations (#4621) ↗ spring-projects/spring-kafka