Arifa
Arifa is a lightweight, Redis-based realtime pub/sub engine designed for WebSocket applications in Rust.
It provides a simple abstraction over Redis Pub/Sub and WebSocket sessions, enabling scalable real-time messaging across multiple nodes.
✨ Features
- Redis Pub/Sub integration
- Multi-node support via
node_id - WebSocket session abstraction (
WsSession) - Channel-based message routing
- Online user tracking
- Built on Tokio async runtime
- Easy integration with Actix Web or custom WS frameworks
Installation
Add Arifa to your Cargo.toml:
= "0.1.0"
Quick Start
1. Create Arifa instance
use *;
async
2. Define a WebSocket session
Implement the WsSession trait:
use *;
use async_trait;
;
3. Subscribe to channels
let session = MySession;
let handle = arifa.subscribe;
4. Publish messages
use *;
use json;
let msg = WsMessage ;
arifa.publish.await?;
5. Unsubscribe (stop subscription)
arifa.unsubscribe;
🌍 Message Model
Scopes
Broadcast→ sent to all subscribersPrivate→ targeted messages
Kinds
FeedsDirectMessageEvent
🧠 Architecture
Arifa works as follows:
WebSocket Client
↓
WsSession trait
↓
Arifa subscription task (Tokio)
↓
Redis Pub/Sub
↓
Multi-node routing (node_id filtering)
Each WebSocket connection runs in its own lightweight async task.
🧩 Example Use Cases
- Real-time chat systems
- Live location tracking
- Notifications system
- Multiplayer game events
- Social feed updates
⚠️ Notes
unsubscribe()usesJoinHandle::abort()(hard stop)- Each subscription spawns a Tokio task
- Redis Pub/Sub connection is per subscription
📦 License
Apache-2.0