Actix - Rust 的Actor异步并发框架

krircc · · 3139 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

## Actix - Rust 的Actor异步并发框架 ### [actix](https://github.com/actix) ### [官网](https://actix.rs/) Actix 基于Tokio和Future,开箱具有异步非阻塞事件驱动并发能力,其实现低层级Actor模型来提供无锁并发模型,而且同时提供同步Actor,具有快速、可靠,易可扩展。 Actix之上是高性能Actix-web框架,很容易上手。使用Actix-web开发的应用程序将在本机可执行文件中包含HTTP服务器。你可以把它放在另一个像nginx这样的HTTP服务器上。但即使完全不存在另一个HTTP服务器(像nginx)的情况下,Actix-web也足以提供HTTP 1和HTTP 2支持以及SSL/TLS。这对于构建微服务分发非常有用。 ### 特性: - 异步/同步 actors - Actor 在本地/线程上下文中通信 - 使用 Futures 进行异步消息处理 - 支持 HTTP1/HTTP2(actix-web) - Actor 监控 - 类型化消息 (No Any type) ### 示例 ```go extern crate actix; extern crate futures; use futures::Future; use actix::prelude::*; struct MyActor { count: usize, } impl Actor for MyActor { type Context = Context<Self>; } struct Ping(usize); impl Message for Ping { type Result = usize; } impl Handler<Ping> for MyActor { type Result = usize; fn handle(&mut self, msg: Ping, ctx: &mut Context<Self>) -> Self::Result { self.count += msg.0; self.count } } fn main() { let system = System::new("test"); // start new actor let addr = MyActor{count: 10}.start(); // send message and get future for result let res = addr.send(Ping(10)); Arbiter::spawn( res.map(|res| { # System::current().stop(); println!("RESULT: {}", res == 20); }) .map_err(|_| ())); system.run(); } ```

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3139 次点击  
加入收藏 微博
4 回复  |  直到 2018-11-22 13:50:20
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传