Skip to content

Commit

Permalink
fix: avoid sending Kafka messages that are too large (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus authored Nov 21, 2023
1 parent 0beaff5 commit 47f4dbe
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions graph-gateway/src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ impl KafkaClient {
}

pub fn send(&self, topic: &str, payload: &[u8]) {
// Don't bother attepting to send messages that the broker should reject.
const MAX_MSG_BYTES: usize = 1 << 20;
if payload.len() > MAX_MSG_BYTES {
tracing::warn!(kafka_producer_err = "msg too big");
}

let record = rdkafka::producer::BaseRecord::<'_, (), [u8]>::to(topic).payload(payload);
if let Err((kafka_producer_err, _)) = self.producer.send(record) {
tracing::error!(%kafka_producer_err, %topic);
Expand Down

0 comments on commit 47f4dbe

Please sign in to comment.