Struct sqs_worker::SQSListener
source · pub struct SQSListener<F: Fn(&Message)> { /* private fields */ }
Expand description
Listener for a queue_url
with a handler function to be run on each received message
The handler function should take a Message and return a unit ()
Implementations§
source§impl<F: Fn(&Message)> SQSListener<F>
impl<F: Fn(&Message)> SQSListener<F>
sourcepub fn new(queue_url: String, handler: F) -> Self
pub fn new(queue_url: String, handler: F) -> Self
Examples found in repository?
examples/simple.rs (lines 13-15)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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(())
}
More examples
examples/with_creds.rs (lines 16-18)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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();
// move region provider
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(())
}
Trait Implementations§
Auto Trait Implementations§
impl<F> RefUnwindSafe for SQSListener<F>where F: RefUnwindSafe,
impl<F> Send for SQSListener<F>where F: Send,
impl<F> Sync for SQSListener<F>where F: Sync,
impl<F> Unpin for SQSListener<F>where F: Unpin,
impl<F> UnwindSafe for SQSListener<F>where F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more