rabbitmq-tutorials/rust/src/bin/receive.rs
Michal Malek 8cc00b1f3f Rust: add tutorial 6; use async; consistent file layout
* Update all tutorials to use async-await syntax
* Add tutorial 6
* Use new async lapin library
* Use file naming and layout consistent with other languages
* Update tokio dependency to 0.3
2020-11-20 11:44:30 +01:00

38 lines
998 B
Rust

use lapin::{options::*, types::FieldTable, Connection, ConnectionProperties};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "amqp://127.0.0.1:5672";
let conn = Connection::connect(addr, ConnectionProperties::default()).await?;
let channel = conn.create_channel().await?;
channel
.queue_declare(
"hello",
QueueDeclareOptions::default(),
FieldTable::default(),
)
.await?;
let consumer = channel
.basic_consume(
"hello",
"consumer",
BasicConsumeOptions {
no_ack: true,
..Default::default()
},
FieldTable::default(),
)
.await?;
println!(" [*] Waiting for messages. To exit press CTRL+C");
for delivery in consumer {
let (_, delivery) = delivery?;
println!(" [x] Received {:?}", std::str::from_utf8(&delivery.data)?);
}
Ok(())
}