Skip to content

Commit 00f9ed4

Browse files
refactor: Adding millisecond to Kafka timestamp (#5202)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 957efac commit 00f9ed4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

crates/router/src/services/kafka.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,15 @@ impl KafkaProducer {
319319
BaseRecord::to(topic)
320320
.key(&event.key())
321321
.payload(&event.value()?)
322-
.timestamp(
323-
event
324-
.creation_timestamp()
325-
.unwrap_or_else(|| OffsetDateTime::now_utc().unix_timestamp() * 1_000),
326-
),
322+
.timestamp(event.creation_timestamp().unwrap_or_else(|| {
323+
(OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000)
324+
.try_into()
325+
.unwrap_or_else(|_| {
326+
// kafka producer accepts milliseconds
327+
// try converting nanos to millis if that fails convert seconds to millis
328+
OffsetDateTime::now_utc().unix_timestamp() * 1_000
329+
})
330+
})),
327331
)
328332
.map_err(|(error, record)| report!(error).attach_printable(format!("{record:?}")))
329333
.change_context(KafkaError::GenericError)

0 commit comments

Comments
 (0)