Skip to content

Commit

Permalink
Make SQS backend take an aws_sdk_sqs::Config instead of SdkConfig
Browse files Browse the repository at this point in the history
The `aws_config::SdkConfig` is the base AWS configuration, and doesn't
include any SQS-specific config options. We now allow users to pass
in an `aws_sdk_sqs::Config` struct (which can be built from an
`SdkConfig`), allowing SQS-specific options like timeouts and
interceptors to be configured.
  • Loading branch information
svix-aaron1011 committed Jun 10, 2024
1 parent 62ca8fa commit 48d387f
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions omniqueue/src/backends/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ pub struct SqsConfig {
pub struct SqsConfigFull {
queue_dsn: String,
override_endpoint: bool,
aws_config: Option<aws_config::SdkConfig>,
sqs_config: Option<aws_sdk_sqs::Config>,
}

impl SqsConfigFull {
async fn take_aws_config(&mut self) -> aws_config::SdkConfig {
if let Some(cfg) = self.aws_config.take() {
async fn take_sqs_config(&mut self) -> aws_sdk_sqs::Config {
if let Some(cfg) = self.sqs_config.take() {
cfg
} else if self.override_endpoint {
aws_config::from_env()
.endpoint_url(&self.queue_dsn)
.load()
.await
aws_sdk_sqs::Config::from(
&aws_config::from_env()
.endpoint_url(&self.queue_dsn)
.load()
.await,
)
} else {
aws_config::load_from_env().await
aws_sdk_sqs::Config::from(&aws_config::load_from_env().await)
}
}
}
Expand All @@ -62,7 +64,7 @@ impl From<SqsConfig> for SqsConfigFull {
Self {
queue_dsn,
override_endpoint,
aws_config: None,
sqs_config: None,
}
}
}
Expand All @@ -78,7 +80,7 @@ impl From<String> for SqsConfigFull {
Self {
queue_dsn: dsn,
override_endpoint: false,
aws_config: None,
sqs_config: None,
}
}
}
Expand Down Expand Up @@ -121,8 +123,8 @@ impl QueueBackend for SqsBackend {
type Config = SqsConfigFull;

async fn new_pair(mut cfg: SqsConfigFull) -> Result<(SqsProducer, SqsConsumer)> {
let aws_cfg = cfg.take_aws_config().await;
let client = Client::new(&aws_cfg);
let aws_cfg = cfg.take_sqs_config().await;
let client = Client::from_conf(aws_cfg);

let producer = SqsProducer {
client: client.clone(),
Expand All @@ -138,8 +140,8 @@ impl QueueBackend for SqsBackend {
}

async fn producing_half(mut cfg: SqsConfigFull) -> Result<SqsProducer> {
let aws_cfg = cfg.take_aws_config().await;
let client = Client::new(&aws_cfg);
let aws_cfg = cfg.take_sqs_config().await;
let client = Client::from_conf(aws_cfg);

let producer = SqsProducer {
client,
Expand All @@ -150,8 +152,8 @@ impl QueueBackend for SqsBackend {
}

async fn consuming_half(mut cfg: SqsConfigFull) -> Result<SqsConsumer> {
let aws_cfg = cfg.take_aws_config().await;
let client = Client::new(&aws_cfg);
let aws_cfg = cfg.take_sqs_config().await;
let client = Client::from_conf(aws_cfg);

let consumer = SqsConsumer {
client,
Expand All @@ -163,12 +165,12 @@ impl QueueBackend for SqsBackend {
}

impl QueueBuilder<SqsBackend> {
/// Set the AWS configuration to use.
/// Set the SQS configuration to use.
///
/// If you _don't_ call this method, the AWS configuration will be loaded
/// If you _don't_ call this method, the SQS configuration will be loaded
/// from the process environment, via [`aws_config::load_from_env`].
pub fn aws_config(mut self, value: aws_config::SdkConfig) -> Self {
self.config.aws_config = Some(value);
pub fn sqs_config(mut self, value: aws_sdk_sqs::Config) -> Self {
self.config.sqs_config = Some(value);
self
}

Expand Down

0 comments on commit 48d387f

Please sign in to comment.