Kameo is a lightweight Rust library for building fault-tolerant, distributed, and asynchronous actors. It allows seamless communication between actors across nodes, providing scalability, backpressure, and panic recovery for robust distributed systems.
- Async Rust: Each actor runs as a separate Tokio task, making concurrency easy and efficient.
- Supervision: Link actors to create a fault-tolerant, self-healing actor hierarchy.
- Remote Messaging: Send messages to actors on different nodes seamlessly.
- Panic Safety: Panics are gracefully handled, allowing the system to recover and continue running.
- Backpressure Management: Supports both bounded and unbounded mpsc messaging for handling load effectively.
Kameo is versatile and can be applied in various domains, such as:
- Distributed Microservices: Build resilient microservices that communicate reliably over a distributed network.
- Real-Time Systems: Ideal for building chat systems, multiplayer games, or real-time monitoring dashboards where low-latency communication is essential.
- IoT Devices: Deploy lightweight actors on low-resource IoT devices for seamless networked communication.
- Rust installed (check rustup for installation instructions)
- A basic understanding of asynchronous programming in Rust
Add kameo as a dependency in your Cargo.toml
file:
cargo add kameo
use kameo::Actor;
use kameo::message::{Context, Message};
use kameo::request::MessageSend;
// Define an actor that will keep a count
#[derive(Actor)]
struct Counter {
count: i64,
}
// Define the message for incrementing the count
struct Inc { amount: i64 }
// Implement how the actor will handle incoming messages
impl Message<Inc> for Counter {
type Reply = i64;
async fn handle(&mut self, msg: Inc, _ctx: Context<'_, Self, Self::Reply>) -> Self::Reply {
self.count += msg.amount;
self.count
}
}
Spawn and message the actor.
// Spawn the actor and get a reference to it
let actor_ref = kameo::spawn(Counter { count: 0 });
// Use the actor reference to send a message and receive a reply
let count = actor_ref.ask(Inc { amount: 42 }).send().await?;
assert_eq!(count, 42);
Contributions are welcome! Whether you are a beginner or an experienced Rust developer, there are many ways to contribute:
- Report issues or bugs
- Improve documentation
- Submit pull requests for new features or bug fixes
- Suggest new ideas in discussions
Join our community on Discord to connect with fellow contributors!
If you find Kameo useful and would like to support its development, please consider sponsoring me on GitHub. Your support helps me maintain and improve the project!
Thank you for your support! 💖
kameo
is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Home | Features | Use Cases | Get Started | Additional Resources | Contributing | License