问题标签 [rust-actix]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
rust - Actix SyncArbiter 注册表
SyncArbiter
我正在尝试使用一个供不同参与者使用的 10 个 Redis 连接池。假设我们有一个名叫 Bob 的演员,他必须使用 Redis 演员来完成它的任务。
虽然这可以通过以下方式实现:
从 Bob 中的上述句柄实现,我们不清楚 Bob 是如何获得 Redis Actor 的地址的。或将任何消息发送给任何Actor
运行在SyncArbiter
.
Arbiter
使用常规和 a也可以实现相同的目的,Registry
但据我所知,Actix 不允许多个相同的演员(例如,我们不能使用常规启动 10 个 Redis 演员Arbiter
)。
正式化我的问题:
- 有没有
Registry
适合SyncArbiter
演员的 - 我可以在常规中启动多个相同类型的演员吗
Arbiter
- 是否有更好/更规范的方式来实现连接池
编辑
版本:
- 行动 0.7.9
- actix_web 0.7.19
- 期货=“0.1.26”
- 生锈 1.33.0
rust - Rust - 将特征对象传递给线程
我已经为此苦苦挣扎了一段时间,只是在兜圈子,所以我希望有人能指出我哪里出错了。
我正在玩 Actix Web,并设置我的第一个处理程序 - 这是系统的简单健康检查。所以我得到的是:
Healthcheck
定义健康检查的特征- 一个
HealthcheckHandler
实现Handler
特征的结构(这是一个 Actix Web 概念)并包含一个 HashMap - 一个为健康检查路由构建
App
实例的函数(这是一个 Actix Web 概念),通过HashMap<String, &Healthcheck>
当我尝试构建它时,我得到了特征“无法安全地在线程之间发送”的错误。
我已经尝试过&Healthcheck
, Box<Healthcheck>
,Box<Healthcheck + Send>
基于此处的另一个答案,甚至Mutex<&Healthcheck>
都没有运气,但都有细微的不同错误。这一切似乎都需要实现一些同步、发送和/或克隆的组合,但我不知道如何在这里解决这个问题。
任何指向我应该解决这个问题的方法?
实际示例代码:
干杯
rust - 如何在 actix-web 中将查询字符串传递给 HttpRequest.url_for()?
关于 url_for 的文档。
代码:
如何将查询字符串添加到生成的 URL 中?name=Alex
?是否有一种很好的内置方式来使用HttpRequest.url_for()
(不仅仅是附加 like url += query_str
)
rust - 需要 IP 地址作为速率限制字符串 - Rust Actix
我正在尝试在 websocket 应用程序中实现基于 IP 地址的速率限制器,但我不知道如何将 IP 地址作为字符串获取。我一直在搜索文档,没有提到 IP 地址。
我有一个addr: Recipient<WSMessage>
和一个上下文。
到目前为止,我已经尝试过ctx.address()
- 无法转换为字符串
msg.addr.tx.0
- 无法将其拆箱。
rust - Actix-Web 在处理文件上传时报告“未配置应用程序数据”
我正在使用 Actix 框架来创建一个简单的服务器,并且我已经使用一个简单的 HTML 前端实现了文件上传。
运行服务器工作正常,但是当我提交文件上传时,它说:
应用数据未配置,配置使用 App::data()
我不知道该怎么办。
file-upload - 使用 actix-web-Framework 在 Rust 中的网络服务器上上传文件时使用原始文件名保存文件
我正在使用 actix-web 框架在 Rust 中创建一个网络服务器。目前我正在处理 Fileupload,为此我正在使用 actix-multipart。
在官方 Actix-Documentation 中有一个例子:
这将是它的最小工作实现,并且到目前为止运行良好。但正如您所见,filepathstring 是一个自定义字符串,它将服务器上的文件重命名为 upload.png ( let file_path_string = "upload.png"
)
那么有没有一种简单的方法来检索原始文件名并将其用作服务器上上传文件的文件名?
rust - How do I determine the type annotation while calling MyActor::from_registry() from another actor's handler that doesn't define T?
I have two Actix actors. MyActor1
defines a generic trait that one of its fields implements. MyActor2
doesn't need to define T
and I can't figure out how to call MyActor1::from_registry()
from MyActor2
message handlers without knowing what type T
maps to.
I've tried variations of this:
This doesn't work because I don't know where/how to define T
unless it's also defined on struct MyActor2<T: Thing>
and then added to the impl<T> Handler<Msg> for MyActor2<T> where T:...
.
I also tried this but it doesn't work because Thing
doesn't implement Default
(because it's a trait):
Here's an example I'm using:
Cargo.toml
main.rs
When running the code, I get this error:
I know this solves this example:
What would I do if I didn't know what MyActor1<T>
was at runtime? For example, maybe I had some code to initialize MyActor1
as MyActor1<Two>
at runtime based on some command line argument.
rust - Rust actix-web 线程不安全移动
我正在尝试使用 actix-web 1.0 编写一个 HTTP 端点。我已经减少了函数,使它只返回传递给它的用户,但编译器仍然给出错误。
这是我的 cargo.toml。
我收到编译错误
我认为这与login_user
in 中的使用有关web::block
,但很难从错误中分辨出来。在 Rust 或 actix 中安全地异步使用请求参数的首选方法是什么?
php - 使用 Redis 作为会话存储时,如何在 actix-session 和 PHP 应用程序之间共享会话?
我想将使用 Redis 作为会话存储的 PHP 网站切换到 actix-web。我遇到的唯一问题是在我的子域之间共享会话。我有很多服务,只有其中一些会切换到 Rust。
一个板条箱已经存在会话:
我的目标是能够从我的 PHP 脚本中读取 Rust 会话。
这是我尝试过的:
最后,我更改了默认 cookie:
我不知道 Rust 中使用的会话格式以及如何与 PHP 共享它。