Home

Awesome

Kameo 🎬

Discord Book Sponsor Crates.io Version docs.rs Crates.io Total Downloads Crates.io License GitHub Contributors GitHub Stars

Kameo banner image

Introduction

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.

Key Features

Why Kameo?

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.

Use Cases

Getting Started

Prerequisites

Installation

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

Basic Example

Defining an Actor

use kameo::Actor;
use kameo::message::{Context, Message};

// 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
    }
}

Spawning and Interacting with the Actor

// 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 }).await?;
assert_eq!(count, 42);

Distributed Actor Communication

Kameo provides built-in support for distributed actors, allowing you to send messages across network boundaries as if they were local.

Registering an Actor

// Spawn and register the actor
let actor_ref = kameo::spawn(MyActor::default());
actor_ref.register("my_actor").await?;

Looking Up and Messaging a Remote Actor

// 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 }).await?;
    println!("Incremented! Count is {count}");
}

Under the Hood

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.

Documentation and Resources

Examples

Explore more examples in the examples directory of the repository.

Contributing

We welcome contributions from the community! Here are ways you can contribute:

Support

Sponsor

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! 💖

License

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