Skip to content

An easy to use listener, to listen for messages from SQS queues

License

Notifications You must be signed in to change notification settings

avencera/sqs_listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An easy to use listener, to listen for messages from SQS queues

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages