2 unstable releases
0.2.0 | Aug 3, 2021 |
---|---|
0.1.0 | Aug 3, 2021 |
#7 in #sqs
20KB
241 lines
sqs_listener
Getting Started
Available on crates: crates.io/sqs_listener
Documentation available at: docs.rs/sqs_listener
sqs_listener = "0.1.0"
Simple Example
Simple example: /examples/simple.rs
use sqs_listener::{Region, SQSListener, SQSListenerClientBuilder};
#[tokio::main]
async fn main() -> eyre::Result<()> {
env_logger::init();
color_eyre::install()?;
let listener = SQSListener::new("".to_string(), |message| {
println!("Message received {:#?}", message)
});
let client = SQSListenerClientBuilder::new(Region::UsEast1)
.listener(listener)
.build()?;
let _ = client.start().await;
Ok(())
}
Start a listener using AWS creds
Example with creds: /examples/with_creds.rs
use std::env;
use sqs_listener::{
credential::StaticProvider, request::HttpClient, Region, SQSListener, SQSListenerClientBuilder,
};
#[tokio::main]
async fn main() -> eyre::Result<()> {
env_logger::init();
color_eyre::install()?;
let aws_access_key_id =
env::var("AWS_ACCESS_KEY_ID").expect("AWS_ACCESS_KEY_ID env variable needs to be present");
let aws_secret_access_key = env::var("AWS_SECRET_ACCESS_KEY")
.expect("AWS_SECRET_ACCESS_KEY env variable needs to be present");
let listener = SQSListener::new("".to_string(), |message| {
println!("Message received {:#?}", message)
});
let client = SQSListenerClientBuilder::new_with(
HttpClient::new().expect("failed to create request dispatcher"),
StaticProvider::new_minimal(aws_access_key_id, aws_secret_access_key),
Region::UsEast1,
)
.listener(listener)
.build()?;
let _ = client.start().await;
Ok(())
}
Dependencies
~11–22MB
~303K SLoC