15个版本

0.1.13 2023年5月4日
0.1.12 2022年12月2日
0.1.10 2022年11月15日
0.1.9 2022年7月3日
0.0.0 2020年8月12日

#338 in 异步

30 每月下载量
用于 scylladb

自定义许可证

260KB
6K SLoC

构建数据驱动分布式系统的Actor框架

Apache 2.0 license


关于

超频是一个受Elixir启发的actor模型框架,强制执行监督树和互操作性。

特性

  • 异步
  • 基于Tokio
  • 多种通道类型
  • Actor本地存储,可通过目录路径接口访问
  • 用于RPC通信的WebSocket服务器
  • 内置配置支持
  • 动态拓扑
  • 可重用Actor
  • Prometheus支持
  • 通信

使用方法

将超频添加到您的Cargo.toml中

[dependencies]
overclock = "0.1"

实现Actor特质


use overclock::core::*;

// Define your actor struct
#[derive(Debug, Serialize, Deserialize, PartialEq, Default)]
struct HelloWorld;

#[async_trait::async_trait]
impl<S> Actor<S> for HelloWorld
where
    S: SupHandle<Self>,
{
    // Temporary state or resources during the actor lifecycle
    type Data = usize;
    // Interval channel which will yield Instant every 1000ms;
    type Channel = IntervalChannel<1000>;
    async fn init(&mut self, rt: &mut Rt<Self, S>) -> ActorResult<Self::Data> {
        log::info!("HelloWorld: {}", rt.service().status());
        let counter = 0;
        Ok(counter)
    }
    async fn run(&mut self, rt: &mut Rt<Self, S>, mut counter: Self::Data) -> ActorResult<()> {
        log::info!("HelloWorld: {}", rt.service().status());
        while let Some(event) = rt.inbox_mut().next().await {
            if counter == 3 {
                counter += 1;
                log::info!("HelloWorld: Received instant {:?}, counter: {}", event, counter);
            } else {
                break
            }
        }
        log::info!("HelloWorld: exited its event loop");
        Ok(())
    }
}


#[tokio::main]
async fn main() {
    let runtime = Runtime::from_config::<HelloWorld>().await.expect("Runtime to run");
    runtime.block_on().await.expect("Runtime to shutdown gracefully");
}

运行上述示例

cargo run --features="ron_config"

贡献

欢迎所有贡献!

许可证

此项目许可为以下之一

Copyright (C) 2022 Louay Kamel
Copyright (C) 2021 IOTA Stiftung

依赖项

~9–44MB
~703K SLoC