Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor: Adding millisecond to Kafka timestamp (#5202)

ShivanshMathurJuspay00f9ed4cae60
diff --git a/crates/router/src/services/kafka.rs b/crates/router/src/services/kafka.rs
index d1abda2105..baa78339d9 100644
--- a/crates/router/src/services/kafka.rs
+++ b/crates/router/src/services/kafka.rs
@@ -319,11 +319,15 @@ impl KafkaProducer {
BaseRecord::to(topic)
.key(&event.key())
.payload(&event.value()?)
- .timestamp(
- event
- .creation_timestamp()
- .unwrap_or_else(|| OffsetDateTime::now_utc().unix_timestamp() * 1_000),
- ),
+ .timestamp(event.creation_timestamp().unwrap_or_else(|| {
+ (OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000)
+ .try_into()
+ .unwrap_or_else(|_| {
+ // kafka producer accepts milliseconds
+ // try converting nanos to millis if that fails convert seconds to millis
+ OffsetDateTime::now_utc().unix_timestamp() * 1_000
+ })
+ })),
)
.map_err(|(error, record)| report!(error).attach_printable(format!("{record:?}")))
.change_context(KafkaError::GenericError)