// Port of /tutorial-one-python.html. Run this // in one shell, and run the hello_world_publish example in another. use bnuuy::{Connection, ConsumerMessage, ConsumerOptions, QueueDeclareOptions, Result}; fn main() -> Result<()> { tracing_subscriber::fmt::init(); // Open connection. let mut connection = Connection::insecure_open("amqp://guest:guest@localhost:5672")?; // Open a channel - None says let the library choose the channel ID. let channel = connection.open_channel(None)?; // Declare the "hello" queue. let queue = channel.queue_declare("hello", QueueDeclareOptions::default())?; // Start a consumer. let consumer = queue.consume(ConsumerOptions::default())?; println!("Waiting for messages. Press Ctrl-C to exit."); for (i, message) in consumer.receiver().iter().enumerate() { match message { ConsumerMessage::Delivery(delivery) => { let body = String::from_utf8_lossy(&delivery.body); tracing::info!("({:>3}) Received [{}]", i, body); consumer.ack(delivery)?; } other => { println!("Consumer ended: {:?}", other); break; } } } connection.close() }