sqs_listener

Crates.iosqs_listener
lib.rssqs_listener
version0.2.0
sourcesrc
created_at2021-08-03 19:08:27.351407
updated_at2021-08-03 21:31:57.140579
descriptionAn easy to use listener, to listen for messages from SQS queues
homepagehttps://github.com/avencera/sqs_listener
repositoryhttps://github.com/avencera/sqs_listener
max_upload_size
id431146
size68,308
Praveen Perera (praveenperera)

documentation

https://docs.rs/sqs_listener

README

sqs_listener

Build Status Crates.io Documentation Rust 1.52+

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

cargo fmt