-
Notifications
You must be signed in to change notification settings - Fork 20
Add highwatermark offset to eachBatch callback #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -863,6 +863,18 @@ class Consumer { | |
#createBatchPayload(messages) { | ||
const topic = messages[0].topic; | ||
const partition = messages[0].partition; | ||
const watermarkOffsets = this.#internalClient.getWatermarkOffsets(topic, partition); | ||
let highWatermark = '-1001'; | ||
let offsetLag_ = -1; | ||
let offsetLagLow_ = -1; | ||
|
||
if (Number.isInteger(watermarkOffsets.highOffset)) { | ||
highWatermark = watermarkOffsets.highOffset.toString(); | ||
/* While calculating lag, we subtract 1 from the high offset | ||
* for compability reasons with KafkaJS's API */ | ||
offsetLag_ = (watermarkOffsets.highOffset - 1) - messages[messages.length - 1].offset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference to other reviewers: getWatermarkOffsets is locally cached and does not have a discernible impact on performance. |
||
offsetLagLow_ = (watermarkOffsets.highOffset - 1) - messages[0].offset; | ||
} | ||
|
||
const messagesConverted = []; | ||
for (let i = 0; i < messages.length; i++) { | ||
|
@@ -892,13 +904,13 @@ class Consumer { | |
const batch = { | ||
topic, | ||
partition, | ||
highWatermark: '-1001', /* We don't fetch it yet. We can call committed() to fetch it but that might incur network calls. */ | ||
highWatermark, | ||
messages: messagesConverted, | ||
isEmpty: () => false, | ||
firstOffset: () => (messagesConverted[0].offset).toString(), | ||
lastOffset: () => (messagesConverted[messagesConverted.length - 1].offset).toString(), | ||
offsetLag: () => notImplemented(), | ||
offsetLagLow: () => notImplemented(), | ||
offsetLag: () => offsetLag_.toString(), | ||
offsetLagLow: () => offsetLagLow_.toString(), | ||
}; | ||
|
||
const returnPayload = { | ||
|
Uh oh!
There was an error while loading. Please reload this page.