2 个不稳定版本
0.2.0 | 2021 年 8 月 3 日 |
---|---|
0.1.0 | 2021 年 8 月 3 日 |
#7 in #sqs
20KB
241 代码行,不包括注释
sqs_listener
入门指南
在 crates 中可用:crates.io/sqs_listener
文档可在:docs.rs/sqs_listener 找到
sqs_listener = "0.1.0"
简单示例
简单示例: /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(())
}
使用 AWS 凭据启动监听器
带凭据的示例: /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(())
}
依赖项
~11–22MB
~303K SLoC