Skip to content

Add partition to HighLevelProducer callback#506

Open
Dustin (GiHoon1123) wants to merge 1 commit into
confluentinc:masterfrom
GiHoon1123:fix/high-level-producer-partition
Open

Add partition to HighLevelProducer callback#506
Dustin (GiHoon1123) wants to merge 1 commit into
confluentinc:masterfrom
GiHoon1123:fix/high-level-producer-partition

Conversation

@GiHoon1123

@GiHoon1123 Dustin (GiHoon1123) commented Jul 6, 2026

Copy link
Copy Markdown

Summary

HighLevelProducer's produce() callback only receives (err, offset), even though the underlying delivery-report event already includes the partition the 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 raw delivery-report event and correlating it back to the produce() call.

The KafkaJS-compatible producer (lib/kafkajs/_producer.js) already extracts report.partition for its own delivery callback, so this brings HighLevelProducer in line with it.

Changes

  • lib/producer/high-level-producer.js: forward report.partition through the internal delivery emitter and into the produce() callback as a third argument (callback(err, offset, partition)), non-breaking for existing two-arg callbacks.
  • types/rdkafka.d.ts: add optional partition to the HighLevelProducer.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 passing
  • tsc -p . — no type errors

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
@GiHoon1123 Dustin (GiHoon1123) requested review from a team as code owners July 6, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HighLevelProducer produce callback only returns the offset, not partition

1 participant