Crates.io | sqs_worker |
lib.rs | sqs_worker |
version | 0.1.5 |
source | src |
created_at | 2023-05-12 16:07:01.916569 |
updated_at | 2023-12-19 02:29:12.457418 |
description | A simple listener for message in a queue using AWS-SDK for Rust |
homepage | https://github.com/Landeed/sqs_worker |
repository | https://github.com/Landeed/sqs_worker |
max_upload_size | |
id | 863095 |
size | 79,742 |
Available on crates: crates.io/sqs_worker
Documentation available at: docs.rs/sqs_worker
sqs_worker = "0.1.4"
Simple example: /examples/simple.rs
use sqs_worker::{SQSListener, SQSListenerClientBuilder};
use std::env;
#[tokio::main]
async fn main() -> eyre::Result<()> {
env_logger::init();
color_eyre::install()?;
let queue_url = env::var("QUEUE_URL").unwrap_or("".to_string());
let region = env::var("REGION").ok();
let listener = SQSListener::new(queue_url, |message| {
println!("Message received {:#?}", message)
});
let client = SQSListenerClientBuilder::new(region)
.listener(listener)
.build()?;
let _ = client.start().await;
Ok(())
}
Example with creds: /examples/with_creds.rs
use sqs_worker::{EnvironmentVariableCredentialsProvider, SQSListener, SQSListenerClientBuilder};
use std::env;
#[tokio::main]
async fn main() -> eyre::Result<()> {
env_logger::init();
color_eyre::install()?;
let queue_url = env::var("QUEUE_URL").expect("QUEUE_URL env variable needs to be present");
let region = env::var("REGION").ok();
let credentials_provider = EnvironmentVariableCredentialsProvider::new();
let listener = SQSListener::new(queue_url, |message| {
println!("Message received {:#?}", message.body())
});
let client = SQSListenerClientBuilder::new_with(region, credentials_provider)
.listener(listener)
.build()?;
let _ = client.start().await;
Ok(())
}