go-queue icon indicating copy to clipboard operation
go-queue copied to clipboard

feat(kq): add batch push methods for Kafka producer

Open codeErrorSleep opened this issue 4 months ago • 0 comments

Greptile Summary

Updated On: 2025-09-13 07:25:43 UTC

This PR adds batch push functionality to the Kafka producer in the kq package, introducing two new methods: BatchPush and BatchPushWithKeys. The changes enhance the existing Pusher struct with efficient bulk messaging capabilities.

The implementation includes:

  • A new KeyValue struct to represent key-value pairs for batch operations
  • BatchPush(ctx, msgs []string) method that automatically generates timestamp-based keys for a slice of messages
  • BatchPushWithKeys(ctx, keyValues []KeyValue) method that accepts explicit key-value pairs
  • Both methods handle empty input gracefully and maintain consistency with existing sync/async patterns
  • Proper tracing context injection for each message using the existing internal message carrier pattern
  • Support for both direct WriteMessages calls (sync mode) and executor-based batching (async mode)

The batch methods fit well into the existing architecture by reusing the established executor pattern and maintaining the same error handling and tracing mechanisms used by single-message methods like Push and PushWithKey. This allows users to leverage Kafka's native batch write capabilities for improved throughput while preserving the same behavioral patterns.

Comprehensive test coverage was added for both new methods, including normal operations, empty input handling, and error propagation scenarios.

Confidence score: 4/5

  • This PR is safe to merge with only minor considerations around test completeness
  • Score reflects well-structured implementation that follows existing patterns, but tests don't fully cover async executor path and tracing context injection
  • Pay closer attention to the test coverage gaps for async mode behavior and tracing functionality

codeErrorSleep avatar Sep 13 '25 07:09 codeErrorSleep