Crates.io | amqprs |
lib.rs | amqprs |
version | 2.1.0 |
source | src |
created_at | 2022-12-03 12:46:42.485053 |
updated_at | 2024-10-14 16:47:19.441551 |
description | AMQP 0-9-1 client implementation for RabbitMQ |
homepage | |
repository | https://github.com/gftea/amqprs |
max_upload_size | |
id | 729063 |
size | 394,804 |
v2.0.0
, it has breaking changes due to rustls upgrade, and the msrv is 1.64
.v2.0.0
: the msrv is 1.56
Yet another RabbitMQ client implementation in rust with different design goals.
The library is accepted to list in RabbitMQ official website.
It's probably the best performance among existing Rust clients. See Benchmarks.
// open a connection to RabbitMQ server
let connection = Connection::open(&OpenConnectionArguments::new(
"localhost",
5672,
"user",
"bitnami",
))
.await
.unwrap();
connection
.register_callback(DefaultConnectionCallback)
.await
.unwrap();
// open a channel on the connection
let channel = connection.open_channel(None).await.unwrap();
channel
.register_callback(DefaultChannelCallback)
.await
.unwrap();
// declare a queue
let (queue_name, _, _) = channel
.queue_declare(QueueDeclareArguments::default())
.await
.unwrap()
.unwrap();
// bind the queue to exchange
let routing_key = "amqprs.example";
let exchange_name = "amq.topic";
channel
.queue_bind(QueueBindArguments::new(
&queue_name,
exchange_name,
routing_key,
))
.await
.unwrap();
//////////////////////////////////////////////////////////////////
// start consumer with given name
let args = BasicConsumeArguments::new(
&queue_name,
"example_basic_pub_sub"
);
channel
.basic_consume(DefaultConsumer::new(args.no_ack), args)
.await
.unwrap();
//////////////////////////////////////////////////////////////////
// publish message
let content = String::from(
r#"
{
"publisher": "example"
"data": "Hello, amqprs!"
}
"#,
)
.into_bytes();
// create arguments for basic_publish
let args = BasicPublishArguments::new(exchange_name, routing_key);
channel
.basic_publish(BasicProperties::default(), content, args)
.await
.unwrap();
// channel/connection will be closed when drop.
// keep the `channel` and `connection` object from dropping
// before pub/sub is done.
time::sleep(time::Duration::from_secs(1)).await;
// explicitly close
channel.close().await.unwrap();
connection.close().await.unwrap();
"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
Testing depends on RabbitMQ docker container.
# start rabbitmq server
./start_rabbitmq.sh
# run tests
./regression_test.sh
# enable traces in test.
# Note that it only takes effect if "traces" feature is enabled
RUST_LOG=debug ./regression_test.sh
I've put amqprs in production and it's working very nicely so far! I've had spikes of publish and delivery over 10k msg/sec without breaking a sweat
We usually add new clients after they get some traction in the community. But this client seems to be fairly well documented and I like the API (it is a bit complicated with some other Rust clients)