Kameo is a Rust library to build fault-tolerant async actors in Rust.
- Async Rust: tokio task per actor
- Supervision: link actors together
- Remote messaging: message actors between nodes
- Panic safe: gracefully handled panics
- Back pressure: supports bounded & unbounded mpsc messaging
- Distributed Systems: Use Kameo when building distributed systems that require seamless communication between actors across multiple nodes, leveraging its built-in support for remote actor messaging and registration.
- Concurrency with Simplicity: Choose Kameo for projects that need efficient concurrency management without the complexity of manually handling threads, as it provides a straightforward API for spawning and managing actors with Tokio.
- Scalability: Kameo is ideal for applications that need to scale horizontally, thanks to its actor pools and remote actor support, making it easy to scale workloads across multiple machines.
Add kameo as a dependency to your crate.
cargo add kameo
Define an actor and some messages.
use kameo::Actor;
use kameo::message::{Context, Message};
use kameo::request::MessageSend;
#[derive(Actor)]
struct Counter {
count: i64,
}
struct Inc { amount: u32 }
impl Message<Inc> for Counter {
type Reply = i64;
async fn handle(&mut self, msg: Counter, _ctx: Context<'_, Self, Self::Reply>) -> Self::Reply {
self.count += msg.0 as i64;
self.count
}
}
Spawn and message the actor.
let actor_ref = kameo::spawn(Counter { count: 0 });
let count = actor_ref.ask(Inc { amount: 42 }).send().await?;
assert_eq!(count, 42);
13x higher throughput when compared with Actix
Above shows a basic benchmark for sending a message to an actor in Kameo and Actix. Always benchmark for yourself.
Contributions are welcome! Feel free to submit pull requests, create issues, or suggest improvements.
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.