What is "amqprs"
Yet another RabbitMQ client implementation in rust with different design goals.
Accepted to list in RabbitMQ official website.
Design Philosophy
- API first: easy to use and understand. Keep the API similar as python client library so that it is easier for users to move from there.
- Minimum external dependencies: as few external crates as possible.
- lock free: no mutex/lock in client library itself.
Design Architecture
Quick Start: Consume and Publish
// open a connection to RabbitMQ server
let connection = open
.await
.unwrap;
connection
.register_callback
.await
.unwrap;
// open a channel on the connection
let channel = connection.open_channel.await.unwrap;
channel
.register_callback
.await
.unwrap;
// declare a queue
let = channel
.queue_declare
.await
.unwrap
.unwrap;
// bind the queue to exchange
let rounting_key = "amqprs.example";
let exchange_name = "amq.topic";
channel
.queue_bind
.await
.unwrap;
//////////////////////////////////////////////////////////////////
// start consumer with given name
let args = new;
channel
.basic_consume
.await
.unwrap;
//////////////////////////////////////////////////////////////////
// publish message
let content = String from
.into_bytes;
// create arguments for basic_publish
let args = new;
channel
.basic_publish
.await
.unwrap;
// channel/connection will be closed when drop.
// keep the `channel` and `connection` object from dropping
// before pub/sub is done.
sleep.await;
// explicitly close
channel.close.await.unwrap;
connection.close.await.unwrap;
Typical Examples
Example - Publish and Subscribe
Example - SSL/TLS
Optional Features
- "traces": enable
tracing
in the library. - "compliance_assert": enable compliance assertion according to AMQP spec.
If enabled, library always check user inputs and
panic
if any non-compliance. If disabled, then it relies on server to reject. - "tls": enable SSL/TLS.
- "urispec": enable support of RabbitMQ URI Specification
Run Test Locally
Testing depends on RabbitMQ docker container.
# start rabbitmq server
# run tests
# enable traces in test.
# Note that it only takes effect if "traces" feature is enabled
RUST_LOG=debug