| Crates.io | rucent |
| lib.rs | rucent |
| version | 0.1.4 |
| created_at | 2024-12-29 18:31:32.610322+00 |
| updated_at | 2024-12-30 19:36:15.628843+00 |
| description | Centrifugo HTTP API client |
| homepage | |
| repository | https://github.com/Cyberguru1/rucent |
| max_upload_size | |
| id | 1498379 |
| size | 96,709 |
Rucent is a Rust library designed to facilitate communication with Centrifugo's HTTP API. It provides seamless interaction with Centrifugo's server for managing real-time messaging and client interactions. With Rucent, you can issue API commands such as publishing messages, managing subscriptions, and retrieving history data.
Before using Rucent, ensure you have:
Add the Rucent library to your Cargo.toml dependencies:
[dependencies]
rucent = "0.1.4"
Enable optional features as needed:
[features]
with_local_server = []
use rucent::client::{Client, Config};
#[tokio::main]
async fn main() {
let config = Config {
addr: Some("http://127.0.0.1:8000/api".to_string()),
key: Some("your_api_key".to_string()),
http_client: None,
};
let client = Client::new(config);
let channel = "test_channel";
let payload = serde_json::json!({ "input": "Hello, Rucent!" });
match client.publish(channel.to_string(), payload, &[]).await {
Ok(response) => println!("Publish successful: {:?}", response),
Err(err) => eprintln!("Error: {:?}", err),
}
}
--snip--
let mut channels = Vec::new();
for i in 0..10 {
channels.push(format!("test_channel_{}", i));
}
let broadcast_result = client
.broadcast(channels, r#"{"date": "2024-12-28"}"#, &[])
.await;
log::info!("Broadcasted to {} channels successfully", broadcast_result.unwrap().responses.len());
#[tokio::main]
async fn main() {
let config = Config {
addr: Some("http://127.0.0.1:8000/api".to_string()),
key: Some("your_api_key".to_string()),
http_client: None,
};
let client = Client::new(config);
let pipe = client.pipe();
let channel = Rc::new("chan3".to_string());
let count = 10;
for _ in 0..count {
let _ = pipe.add_publish(channel.to_string(), r#"{"input": "test1"}"#, &[]);
}
let replies = match client.send_pipe(&pipe).await {
Ok(reply) => reply,
Err(err) => {
println!("an error occurred while sending pipe {err}");
Vec::new()
}
};
let reply_len = replies.len();
for reply in replies {
if let Some(err) = reply.error {
println!("An error occured with {err}");
}
}
println!("Sent {reply_len} commands in one http request");
}
To run tests using a local Centrifugo instance, provide the required environment variables:
API_URL=http://127.0.0.1:8000/api API_KEY=fa7ce149-b279-4870-af59-ad7ce78ef11a cargo test --test client --features with_local_server -- --nocapture
To run tests without a local Centrifugo instance:
cargo test --test client -- --nocapture
We welcome contributions! Feel free to open issues, submit pull requests, or suggest new features.
git checkout -b feature-branch-name.git commit -m "Description of changes".git push origin feature-branch-name.Rucent is licensed under either of the following licenses, at your option:
See LICENSE-MIT or LICENSE-APACHE for details.