Skip to content

Commit

Permalink
Merge pull request #68 from svix/jplatte/sqs-max-payload-size
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Apr 4, 2024
2 parents 940a068 + 9fc5efd commit 8543c69
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions omniqueue/src/backends/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use crate::{
QueueError, Result,
};

/// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
const MAX_PAYLOAD_SIZE: usize = 262_144;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SqsConfig {
/// The queue's [DSN](https://aws.amazon.com/route53/what-is-dns/).
Expand Down Expand Up @@ -223,15 +226,7 @@ pub struct SqsProducer {

impl SqsProducer {
pub async fn send_raw(&self, payload: &str) -> Result<()> {
self.client
.send_message()
.queue_url(&self.queue_dsn)
.message_body(payload)
.send()
.await
.map_err(aws_to_queue_error)?;

Ok(())
self.send_raw_scheduled(payload, Duration::ZERO).await
}

pub async fn send_serde_json<P: Serialize + Sync>(&self, payload: &P) -> Result<()> {
Expand All @@ -240,6 +235,12 @@ impl SqsProducer {
}

pub async fn send_raw_scheduled(&self, payload: &str, delay: Duration) -> Result<()> {
if payload.len() > MAX_PAYLOAD_SIZE {
return Err(QueueError::Generic(
"payload exceeds SQS size limit of 256K".into(),
));
}

self.client
.send_message()
.queue_url(&self.queue_dsn)
Expand Down

0 comments on commit 8543c69

Please sign in to comment.