Skip to content

Commit da733dd

Browse files
committed
Set timestamps in last-event-id +1 millisecond to avoid duplicate messages on reconnect
Summary: Bug: T199433 Reviewers: Ottomata, Pchelolo Reviewed By: Ottomata, Pchelolo Differential Revision: https://phabricator.wikimedia.org/D1091
1 parent 72a9e95 commit da733dd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/KafkaSSE.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,10 @@ class KafkaSSE {
574574
/**
575575
* Given a kafkaMessage consumed from node-rdkafka KafkaConsumer,
576576
* This will update the this.latestOffsetsMap with the kafkaMessage's
577-
* topic, partition, and offset + 1.
577+
* topic, partition, and offset|timestamp + 1.
578+
*
579+
* NOTE: + 1 is necessary for Last-Event-ID for EventSource auto-resuming on reconnect.
580+
* Without the + 1, the previously consumed message will be reconsumed.
578581
*
579582
* @param {KafkaMessage} kafkaMessage
580583
*/
@@ -591,12 +594,9 @@ class KafkaSSE {
591594

592595
// Set either timestamp or offset, depending on the configuration of useTimestampForId
593596
if (this.options.useTimestampForId) {
594-
this.latestOffsetsMap[`${kafkaMessage.topic}/${kafkaMessage.partition}`].timestamp = kafkaMessage.timestamp;
597+
this.latestOffsetsMap[`${kafkaMessage.topic}/${kafkaMessage.partition}`].timestamp = kafkaMessage.timestamp + 1;
595598
}
596599
else {
597-
// TODO: Should we send offset + 1 or just offset? +1 is the easiest way to avoid
598-
// duplicates during auto-resume. But, if this message doesn't
599-
// make it to the client, they will skip it during auto resume.
600600
this.latestOffsetsMap[`${kafkaMessage.topic}/${kafkaMessage.partition}`].offset = kafkaMessage.offset + 1;
601601
}
602602

0 commit comments

Comments
 (0)