You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor share consumer acknowledgment interfaces and improve code quality
- Simplify to single AcknowledgingShareConsumerAwareMessageListener interface with nullable acknowledgment
- Remove redundant ShareConsumerAwareMessageListener interface
- Clean up ShareAcknowledgmentMode enum by removing unnecessary string property
- Replace verbose null checks with Boolean.TRUE.equals() pattern
- Use enum values for acknowledgment mode validation instead of hardcoded strings
- Update tests and documentation to use unified interface
- Fix spacing issues in @nullable annotations
- Fixing other formatting issues
Improve share consumer polling behavior and add isShareConsumer() helper
- Add isShareConsumer() helper method to AbstractKafkaListenerEndpoint for cleaner boolean checks
- Replace verbose Boolean.TRUE.equals() pattern with cleaner isShareConsumer() call
- Handle KIP-932 IllegalStateException when polling with unacknowledged records in explicit mode
- Add minimal 10ms delay to prevent tight loop while maintaining responsiveness
- Remove problematic pre-poll blocking logic that prevented proper exception handling
The share consumer now properly handles the broker's IllegalStateException when attempting
to poll with unacknowledged records, as specified in KIP-932. This maintains heartbeat
while waiting for acknowledgments and prevents CPU-intensive tight loops.
Fix thread safety in ShareConsumer acknowledgments
ShareConsumer is not thread-safe and requires all access to happen on the consumer thread.
The previous implementation allowed acknowledgment calls from listener threads to directly
access the consumer, causing ConcurrentModificationException.
Changes:
- Add PendingAcknowledgment queue to safely pass acknowledgments between threads
- Process queued acknowledgments on the consumer thread during poll loop
- Remove direct consumer access from ShareConsumerAcknowledgment.acknowledgeInternal()
- Add notifyAcknowledged() callback for acknowledgment completion
This ensures all ShareConsumer interactions happen on the owning consumer thread,
eliminating race conditions between polling and acknowledgment operations.
The thread safety issue was exposed by removing the pre-poll sleep, which previously
masked the concurrent access by creating timing windows where the consumer was dormant.
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
This feature helps developers quickly identify when acknowledgment calls are missing from their code, preventing the common issue of "Spring Kafka does not consume new records any more" due to forgotten acknowledgments.
453
+
389
454
[[share-acknowledgment-examples]]
390
455
=== Acknowledgment Examples
391
456
@@ -406,7 +471,6 @@ Always ensure records are acknowledged in all code paths.
406
471
else {
407
472
acknowledgment.release(); // Temporary failure - retry later
408
473
}
409
-
}
410
474
else {
411
475
acknowledgment.reject(); // Invalid order - don't retry
0 commit comments