#message-queue #amazon-sqs #worker #listener #aws-sdk

sqs_worker

A simple listener for message in a queue using AWS-SDK for Rust

5 releases

0.1.5 Dec 19, 2023
0.1.3 Jun 6, 2023
0.1.2 Jun 6, 2023
0.1.1 Jun 6, 2023
0.1.0 May 12, 2023

#8 in #amazon-sqs

Download history 8/week @ 2024-07-05 29/week @ 2024-07-26 21/week @ 2024-08-02 2/week @ 2024-08-09 44/week @ 2024-09-20 22/week @ 2024-09-27 19/week @ 2024-10-04 6/week @ 2024-10-11 12/week @ 2024-10-18

63 downloads per month

Apache-2.0

22KB
262 lines

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

Dependencies

~28–39MB
~586K SLoC