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

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

#10 in #listener

43 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

~29–40MB
~586K SLoC