Add partition to HighLevelProducer callback#506
Open
Dustin (GiHoon1123) wants to merge 1 commit into
Open
Conversation
The delivery report already contains the partition a message was actually produced to, but HighLevelProducer only forwarded the offset to the produce() callback and discarded the partition. This adds partition as a third callback argument, matching the KafkaJS-compatible producer, which already exposes it. Fixes confluentinc#238
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HighLevelProducer'sproduce()callback only receives(err, offset), even though the underlyingdelivery-reportevent already includes thepartitionthe message landed in. So there's no way to know which partition a message went to (e.g. for observability/instrumentation) without separately subscribing to the rawdelivery-reportevent and correlating it back to theproduce()call.The KafkaJS-compatible producer (
lib/kafkajs/_producer.js) already extractsreport.partitionfor its own delivery callback, so this bringsHighLevelProducerin line with it.Changes
lib/producer/high-level-producer.js: forwardreport.partitionthrough the internal delivery emitter and into theproduce()callback as a third argument (callback(err, offset, partition)), non-breaking for existing two-arg callbacks.types/rdkafka.d.ts: add optionalpartitionto theHighLevelProducer.produce()callback type.test/producer/high-level-producer.spec.js: add a test that simulates a delivery report and asserts the partition is passed through to the callback.Fixes #238
Test plan
mocha --ui exports test/producer/high-level-producer.spec.js— 20/20 passingtsc -p .— no type errors