#actor-model #actor #distributed

myriam

本地和远程actor模型的实现

19个版本

0.1.3 2024年8月1日
0.1.2 2024年7月27日
0.0.13 2024年7月22日
0.0.10 2023年2月12日
0.0.6 2022年6月26日

#156并发

Download history 109/week @ 2024-07-15 603/week @ 2024-07-22 161/week @ 2024-07-29

每月下载量 873

Apache-2.0 以及可能是 GPL-3.0-or-later

67KB
1.5K SLoC

myriam-rs

本地和远程actor模型实现,API深受(但不一定是等价于)Goblins 启发。

// LocalHandle allows for local, type-safe communication
// UntypedHandle tries to do the same, but requests and responses are
// bag of bytes and have to be {de}serialized
let (local_handle, untyped_handle)
    = remote::spawn_untyped::<_, _, _, BincodeDencoder>(Mult { a: 3 }).await?;

// create router with a TOR netlayer
let layer =
    TorNetLayer::new_for_service("127.0.0.1.9050", "127.0.0.1:8080", "/tmp/myriam/foo")
        .await?;

let router_handle = Router::with_netlayer(layer, Some(RouterOpts::default())).await?;

// routers handle external access to several attached actors
// we can think of this exposed actor as a capability
// "tor:0139aa9b4d523e1da515ce21a818e579acd005fbd0aea62ef094ac1b845f99e7@someaddress.onion"
let address = router_handle.attach(untyped_handle).await?;

let new_layer =
    TorNetLayer::new_for_service("127.0.0.1.9050", "127.0.0.1:8081", "/tmp/myriam/bar")
        .await?;

let remote_handle
    = RemoteHandle::<u32, u32, SomeError, BincodeDencoder, TorNetLayer>::new(&address, new_layer);
//                     type handle once ^

// use RemoteHandle just like a LocalHandle
let res = remote_handle.send(Message::Task(42)).await?;

// capabilities can be revoked anytime
router_handle.revoke(&address).await?;

tokio::time::sleep(Duration::from_millis(100));

// ...and thus we can't invoke this one anymore
remote_handle.send(Message::Ping).await.unwrap_err();

查看仓库示例以获得更全面的演示。

特性

  • remote (默认):支持远程消息
  • tcp (默认):仅用于测试的TCP网络层
  • tor (默认):Tor网络层 - 需要一个运行和正确配置的Tor路由器

许可证

版权所有 2024 Ariela Wenner

在Apache License, Version 2.0(“许可证”)下授权;除非遵守许可证,否则不得使用此文件。您可以在https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言,请参阅许可证。

依赖

~3–9.5MB
~78K SLoC