Actix Rust 的 actors 框架开源项目

我要开发同款
匿名用户2018年05月31日
99阅读
开发技术Rust
所属分类Web应用开发
授权协议MIT

作品详情

Actix-Rust的Actor异步并发框架

Actix基于Tokio和Future,开箱具有异步非阻塞事件驱动并发能力,其实现低层级Actor模型来提供无锁并发模型,而且同时提供同步Actor,具有快速、可靠,易可扩展。

Actix之上是高性能Actix-web框架,很容易上手。使用Actix-web开发的应用程序将在本机可执行文件中包含HTTP服务器。你可以把它放在另一个像nginx这样的HTTP服务器上。但即使完全不存在另一个HTTP服务器(像nginx)的情况下,Actix-web也足以提供HTTP1和HTTP2支持以及SSL/TLS。这对于构建微服务分发非常有用。

特性:

异步/同步actors

Actor在本地/线程上下文中通信

使用 Futures 进行异步消息处理

支持HTTP1/HTTP2(actix-web)

Actor监控

类型化消息(No Any type)

示例 

extern crate actix;extern crate futures;extern crate tokio;use actix::prelude::*;use futures::Future;/// Define `Ping` messagestruct Ping(usize);impl Message for Ping {    type Result = usize;}/// Actorstruct MyActor {    count: usize,}/// Declare actor and its contextimpl Actor for MyActor {    type Context = Context;}/// Handler for `Ping` messageimpl Handlerfor MyActor {    type Result = usize;    fn handle(&mut self, msg: Ping, _: &mut Context) -> Self::Result {        self.count += msg.0;        self.count    }}fn main() {    // start system, this is required step    System::run(|| {        // start new actor        let addr = MyActor { count: 10 }.start();        // send message and get future for result        let res = addr.send(Ping(10));        // handle() returns tokio handle        tokio::spawn(            res.map(|res| {                println!("RESULT: {}", res == 20);                // stop system and exit                System::current().stop();            }).map_err(|_| ()),        );    });}

 

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论