Crates.io | rmq-rpc |
lib.rs | rmq-rpc |
version | 0.1.2 |
source | src |
created_at | 2021-05-22 14:11:33.130726 |
updated_at | 2021-05-23 15:36:42.699388 |
description | Client server for RPC via RabbitMQ |
homepage | |
repository | https://github.com/sivakov512/rmq-rpc |
max_upload_size | |
id | 400831 |
size | 53,724 |
Early release, not stable enough!
Client\server for RPC via RabbitMQ
Please look at examples
directory for complete examples.
use rmq_rpc::RmqRpcServer;
use std::io::Error;
const URL: &str = "amqp://127.0.0.1:5672";
const QUEUE_NAME: &str = "examples";
async fn handler(data: Vec<u8>) -> Result<Vec<u8>, Error> {
let mut res = data.to_owned();
res.reverse();
Ok(res)
}
#[tokio::main]
async fn main() {
let server = RmqRpcServer::connect(URL).await.unwrap();
server.declare_queue(QUEUE_NAME).await.unwrap();
server.drain(QUEUE_NAME, handler).await.unwrap();
}
use rmq_rpc::RmqRpcClient;
use std::env;
const URL: &str = "amqp://127.0.0.1:5672";
const QUEUE_NAME: &str = "examples";
#[tokio::main]
async fn main() {
let msg = match env::args().skip(1).next().unwrap();
let client = RmqRpcClient::connect(URL).await.unwrap();
client.declare_queue(QUEUE_NAME).await.unwrap();
let _ = client
.send_message(QUEUE_NAME, msg.as_bytes().to_vec())
.await
.unwrap();
}