sqs_worker

Crates.iosqs_worker
lib.rssqs_worker
version0.1.5
sourcesrc
created_at2023-05-12 16:07:01.916569
updated_at2023-12-19 02:29:12.457418
descriptionA simple listener for message in a queue using AWS-SDK for Rust
homepagehttps://github.com/Landeed/sqs_worker
repositoryhttps://github.com/Landeed/sqs_worker
max_upload_size
id863095
size79,742
(Jonathan-Landeed)

documentation

https://docs.rs/sqs_worker/0.1.0/sqs_worker/

README

sqs_worker

Build Status Crates.io Documentation Rust 1.52+

Getting Started

Available on crates: crates.io/sqs_worker

Documentation available at: docs.rs/sqs_worker

sqs_worker = "0.1.4"

Simple Example

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(())
}

Start a listener using AWS creds

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(())
}
Commit count: 28

cargo fmt