Skip to content

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
minghuaw committed Jul 22, 2022
1 parent add4556 commit aa3d38e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude = [
"examples/owned_txn_retirement",
"examples/protocol_test",
"examples/receiver",
"examples/receiver_auto_accept",
"examples/rustls_connection",
"examples/sasl_connection",
"examples/sasl_listener",
Expand Down
1 change: 1 addition & 0 deletions examples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The examples below are individual examples which you need to `cd` into the corre
|------|-------------|
|[sender](./sender/) | A simple sender with default configuration |
|[receiver](./receiver/) | A simple receiver with default configuration |
|[receiver_auto_accept](./receiver_auto_accept/) | A simple receiver that accepts incoming deliveries automatically |
|[batchable_send](./batchable_send/)| A simple sender that sends a message but doesn't require immediate disposition |
|[listener](./listener)| A simple listener that handles incoming connections, sessions, and links |

Expand Down
10 changes: 10 additions & 0 deletions examples/receiver_auto_accept/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "receiver_auto_accept"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1", features = ["net", "rt", "rt-multi-thread", "macros"] }
fe2o3-amqp = { path = "../../fe2o3-amqp" }
25 changes: 25 additions & 0 deletions examples/receiver_auto_accept/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use fe2o3_amqp::{
connection::Connection, link::Receiver, session::Session, types::primitives::Value, Delivery,
};

#[tokio::main]
async fn main() {
let mut connection = Connection::open("connection-1", "amqp://localhost:5672")
.await
.unwrap();
let mut session = Session::begin(&mut connection).await.unwrap();
let mut receiver = Receiver::builder()
.name("rust-receiver-link-1")
.source("q1")
.auto_accept(true) // default is `false`
.attach(&mut session)
.await
.unwrap();

// The delivery will be automatically accepted
let delivery: Delivery<Value> = receiver.recv().await.unwrap();

receiver.close().await.unwrap();
session.end().await.unwrap();
connection.close().await.unwrap();
}

0 comments on commit aa3d38e

Please sign in to comment.