Crates.io | rsub |
lib.rs | rsub |
version | 0.1.0 |
source | src |
created_at | 2024-11-22 06:37:06.319313 |
updated_at | 2024-11-22 06:37:06.319313 |
description | A high-performance message broker with QUIC transport and pub/sub messaging patterns |
homepage | |
repository | |
max_upload_size | |
id | 1457136 |
size | 121,241 |
RSPub is a high-performance publish/subscribe (pub/sub) messaging system built in Rust using the QUIC protocol. It provides secure, reliable, and efficient message delivery with support for multiple authentication methods.
🚀 High-performance QUIC Transport - Built on Quinn, a pure-rust QUIC implementation
🔒 Built-in Security - TLS 1.3 encryption by default
🔑 Flexible Authentication - Support for Basic and Bearer authentication
📨 Pub/Sub Messaging - Topic-based publish/subscribe patterns
🔄 Bi-directional Streaming - Full duplex communication
📦 Binary Message Support - Efficient binary message format
⚡ Async First - Built on Tokio for maximum performance
🛠️ YAML Configuration - Simple and flexible configuration
git clone https://github.com/samespace/rspub.git
cd rspub
cargo build --release
cargo install rspub
config.yaml
:server:
host: "127.0.0.1"
port: 4222
max_payload: 1048576 # 1 MB
max_connections: 1000
auth:
type: Basic
config:
username: admin
password: secret
tls:
enabled: true
cert_file: "cert.pem"
key_file: "key.pem"
rspub cert-gen --cert cert.pem --key key.pem
rspub start --config config.yaml
# Start the server
rspub start --config config.yaml
# Subscribe to a topic
rspub sub my-topic --server localhost:4222
# Publish to a topic
rspub pub my-topic "Hello World" --server localhost:4222
use rspub::client::client::RsubClient;
use rspub::common::auth::{AuthConfig, AuthType, BasicAuth};
#[tokio::main]
async fn main() {
// Connect to RSub server
let client = RsubClient::connect(
"127.0.0.1:4222".parse().unwrap(),
"cert.pem",
AuthConfig::new(AuthType::Basic(BasicAuth {
username: "admin".to_string(),
password: "secret".to_string(),
})),
).await.unwrap();
// Subscribe to topics
client.subscribe(vec!["my-topic".to_string()], |message| {
println!("Received: {:?}", message);
}).await.unwrap();
// Publish messages
client.publish(
vec!["my-topic".to_string()],
"Hello RSub!".into()
).await.unwrap();
}
RSub can be configured using a YAML file. Here are the available options:
Option | Description | Default |
---|---|---|
server.host | Server host address | "127.0.0.1" |
server.port | Server port | 4222 |
server.max_payload | Maximum message size in bytes | 1MB |
server.max_connections | Maximum concurrent connections | 1000 |
tls.enabled | Enable TLS encryption | false |
tls.cert_file | TLS certificate file path | - |
tls.key_file | TLS private key file path | - |
auth.type | Authentication type (Basic/Bearer) | None |
RSub is designed for high performance:
Low Latency: Sub-millisecond message delivery
High Throughput: Capable of handling millions of messages per second
Efficient Resource Usage: Low memory and CPU footprint
Connection Scaling: Supports thousands of concurrent connections
RSPub uses a binary message format (wire format) to achieve maximum performance.
The message format consists of the following fields:
+-------------------+-------------------+-------------------+-------------------+
| Message Type (1B) | Topics count (1B) | Topic 1 length(1B)| Topic 1 string |
+-------------------+-------------------+-------------------+-------------------+
| Topic 2 length(1B)| Topic 2 string | ... | Data length (4B) |
+-------------------+-------------------+-------------------+-------------------+
| Data |
+-------------------+
Example message with topic "sensors.temp" and payload "23.5":
00000000 01 01 0B 73 65 6E 73 6F 72 73 2E 74 65 6D 70 03 |...sensors.temp.|
00000010 32 33 2E 35 |23.5|
Breakdown:
01 -> Message Type = Message (1)
01 -> Topics Count = 1
0B -> Topic 1 Length = 11 bytes ("sensors/temp")
73...70 -> Topic 1 String = "sensors/temp"
00000003 -> Data Length = 3 bytes
32 33 35 -> Data = "23.5"
Message Type (1 byte):
Topics Count (1 byte):
Topic Fields (variable):
Data Length (4 bytes):
Data (variable):
Compact: Minimal overhead compared to text formats like JSON
Fast Parsing: Fixed-size headers enable efficient parsing
Zero Copy: Length-prefixed fields allow zero-copy operations
Flexible: Supports variable-length topics and payloads
Self-Describing: Includes all necessary length information
Forward Compatible: Reserved bits allow format evolution
Language Agnostic: Simple binary format works across platforms
RSub uses TLS 1.3 for transport security and supports multiple authentication methods. It's recommended to:
rspub cert-gen --cert cert.pem --key key.pem
Basic Auth: Username/password authentication
Bearer Token: JWT token-based authentication
Custom Auth: Implement your own authentication provider
Contributions are welcome! Please feel free to submit pull requests.
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)# Install development dependencies
cargo install cargo-watch cargo-tarpaulin
# Run tests
cargo test
# Run with hot reload
cargo watch -x run
# Generate code coverage
cargo tarpaulin
Common issues and solutions:
Connection Refused: Ensure the server is running and the port is accessible
Authentication Failed: Verify credentials in config.yaml
TLS Errors: Check certificate paths and validity
Performance Issues: Adjust max_payload and max_connections settings
This project is licensed under the MIT License - see the LICENSE file for details.
Clustering support
Message persistence
WebSocket bridge
Prometheus metrics
Admin dashboard
Plugin system