Crates.io | kameo_macros |
lib.rs | kameo_macros |
version | 0.12.2 |
source | src |
created_at | 2024-03-30 13:22:05.158546 |
updated_at | 2024-10-17 06:45:08.189096 |
description | Fault-tolerant Async Actors Built on Tokio macros |
homepage | |
repository | https://github.com/tqwewe/kameo |
max_upload_size | |
id | 1191054 |
size | 53,159 |
Kameo is a high-performance, lightweight Rust library for building fault-tolerant, asynchronous actor-based systems. Designed to scale from small, local applications to large, distributed systems, Kameo simplifies concurrent programming by providing a robust actor model that seamlessly integrates with Rust's async ecosystem.
Whether you're building a microservice, a real-time application, or an embedded system, Kameo offers the tools you need to manage concurrency, recover from failures, and scale efficiently.
Kameo is designed to make concurrent programming in Rust approachable and efficient. By abstracting the complexities of async and concurrent execution, Kameo lets you focus on writing the business logic of your actors without worrying about the underlying mechanics.
Kameo is not just for distributed applications; it's equally powerful for local concurrent systems. Its flexible design allows you to start with a simple, single-node application and scale up to a distributed architecture when needed.
Add kameo as a dependency in your Cargo.toml
file:
[dependencies]
kameo = "0.12"
Alternatively, you can add it via command line:
cargo add kameo
use kameo::Actor;
use kameo::message::{Context, Message};
use kameo::request::MessageSend;
// Implement the actor
#[derive(Actor)]
struct Counter {
count: i64,
}
// Define message
struct Inc { amount: i64 }
// Implement message handler
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 the actor and obtain its reference
let actor_ref = kameo::spawn(Counter { count: 0 });
// Send messages to the actor
let count = actor_ref.ask(Inc { amount: 42 }).send().await?;
assert_eq!(count, 42);
Kameo provides built-in support for distributed actors, allowing you to send messages across network boundaries as if they were local.
// Spawn and register the actor
let actor_ref = kameo::spawn(MyActor::default());
actor_ref.register("my_actor").await?;
// Lookup the remote actor
if let Some(remote_actor_ref) = RemoteActorRef::<MyActor>::lookup("my_actor").await? {
let count = remote_actor_ref.ask(&Inc { amount: 10 }).send().await?;
println!("Incremented! Count is {count}");
}
Kameo uses libp2p for peer-to-peer networking, enabling actors to communicate over various protocols (TCP/IP, WebSockets, QUIC, etc.) using multiaddresses. This abstraction allows you to focus on your application's logic without worrying about the complexities of network programming.
Explore more examples in the examples directory of the repository.
ActorPool
actor.PubSub
actor.We welcome contributions from the community! Here are ways you can contribute:
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:
You may choose either license to use this software.
Introduction | Key Features | Why Kameo? | Use Cases | Getting Started | Basic Example | Distributed Actor Communication | Examples | Documentation | Contributing | Support | License