- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 actix-web
解析器中创建 super 发布请求时,会抛出以下错误 - 如何通过将请求生成到现有执行程序来发送一个 http 请求?
thread 'actix-rt:worker:1' panicked at 'Multiple executors at once: EnterError { reason: "attempted to run an executor while another executor is already running" }', src/libcore/result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Panic in Arbiter thread, shutting down system.
主要.rs
extern crate actix_web;
extern crate serde_json;
extern crate actix_rt;
extern crate hyper;
use serde_json::{Value, json};
use hyper::{Client, Uri, Body, Request};
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
use actix_rt::System;
use actix_web::client;
use futures::future::{Future, lazy};
fn main() {
println!("Start server...");
listen();
}
pub fn listen() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(middleware::Logger::default())
.data(web::JsonConfig::default().limit(4096))
.service(web::resource("/push").route(web::post().to(index)))
.service(web::resource("/test").route(web::post().to(test)))
})
.bind("127.0.0.1:8080")?
.run()
}
fn index(item: web::Json<Value>) -> HttpResponse {
println!("model: {:?}", &item);
send(json!({
"hello": "world"
}));
HttpResponse::Ok().json(item.0) // <- send response
}
fn test(item: web::Json<Value>) -> HttpResponse {
println!("recevied test call!");
println!("{:?}", &item);
HttpResponse::Ok().json(item.0) // <- send response
}
pub fn send(mut data: serde_json::Value) {
println!("# Start running log post future...");
// if the following line is removed, the call is not received by the test function above
System::new("test").block_on(lazy(|| {
let req = Request::builder()
.method("POST")
.uri("http://localhost:8080/test")
.body(Body::from(data.to_string()))
.expect("request builder");
let client = Client::new();
let future = client.request(req)
.and_then(|res| {
println!("status: {}", res.status());
Ok(())
})
.map_err(|err| {
println!("error: {}", err);
});
return future;
}));
println!("# Finish running log post future")
}
cargo .toml
[package]
name = "rust-tokio-event-loop-madness"
version = "0.1.0"
authors = [""]
edition = "2018"
[dependencies]
serde_json = "1.0.39"
actix-web = "1.0.0"
serde_derive = "1.0.92"
actix-rt = "*"
hyper = "0.12.30"
futures = "*"
curl 命令触发错误:
curl -X POST -H 'Content-Type: application/json' -d '{"test":1}' http://localhost:8080/push
repo 示例:https://github.com/fabifrank/rust-tokio-event-loop-madness
最佳答案
通过使用 tokio
函数 spawn
将 future 添加到正在运行的 tokio 执行器中使其工作。
所以代替:
System::new("test").block_on(lazy(|| {
使用:
spawn(lazy(move || {
当然,在 cargo.toml
中添加 tokio
作为依赖项并包含 crate。
关于rust - actix-web 处理程序中的 HTTP 请求 -> 多个执行程序一次 : EnterError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56634370/
因此,我正在尝试创建一个基本的actix-web应用程序,该应用程序将允许我创建一个非常基本的博客系统。它正在处理我的GET请求,但没有处理我的POST请求。 main.rs: use actix_w
我对Rust还是很陌生,并且愿意为Actix-web中的Orange Pi Zero提供一些Linux服务,该服务将充当其他网络设备的“网关”(一些愚蠢的中文网络中继,具有4个输入和4个输出,这是受控
您好,我想传递以下 AppState。 pub struct AppState { clients: Vec, } 这就是我的服务器: async fn launch_server(app_c
我正在尝试为我的 Actix 应用程序编写身份验证中间件。在中间件中验证请求时,我调用数据库以检索必要的用户数据以验证传入的请求。一旦请求获得授权,我希望能够将此用户数据传递给处理程序,因为这将允许我
我只是在玩一些Actix网络和Actix Actor ,而我在构建一个简单的应用程序却花了毫秒的时间,所以我观察到Actix正在创建多个 Actor 。我只想限制它一个,但我做不到。 我在这里做错了什
主要功能是: #[actix_rt::main] async fn main() -> std::io::Result { std::env::set_var( "RUST_L
我想为 actix 中的查询值设置默认值。 我知道有一个Default Rust 标准库中结构的特征,但老实说,我不知道如何在这种情况下应用它。 在我的情况下,请求查询可能会也可能不会提供分页值页面和
我正在尝试运行两个应用程序(一个在端口 3006 上进行管理,另一个在端口 8080 上提供数据)。 他们共享数据库池、缓存... 对于actix 1.0,我有这个工作(我不知道这是否是最好的方法):
这是我第一次尝试使用 actix-web 编写带有 Rust 的小型 Web 服务。 下面的代码是一个请求处理程序,旨在做三件事,在数据库中插入一个条目,如果数据库调用成功则发送一封电子邮件,然后返回
我正在尝试使用 SyncArbiter 实现一个包含 10 个 Redis 连接的池,供不同的参与者使用。假设我们有一个名为 Bob 的 actor,它必须使用 Redis actor 来完成它的任务
我正在尝试创建具有 PyO3 Python 解释器和 Py 对象的 Actix Actor。 问题是创建 python 解释器 actor 的正确方法是什么? 我认为错误是由静态定义的 Actor 特
我正在使用 Actix-web 实现中间件,但遇到了一个我无法弄清楚的生命周期问题。 extern crate actix_web; use actix_web::actix::{Actor, Add
我正在尝试使用 actix-web 1.0 编写 HTTP 端点。我已经缩减了函数,使其只返回传递给它的用户,但编译器仍然给出错误。 extern crate actix_web; extern cr
问题 - 如果您只有一个系统但其中有多个仲裁器在运行,它仍然是一个单线程事件循环吗? 通读 Actix 书 - https://actix.rs/book/actix/sec-6-sync-arbit
我现在有以下服务器声明 let server = HttpServer::new(move || { App::new() .app_data(actix_web::web::
我在使用波纹管代码在actix-web上使用Stream时遇到问题: fn format_csv_row(row: tiberius::Row) -> Result { ... } #[get("/s
我试过 example of actix-multipart与 actix-web v3.3.2和 actix-multipart v0.3.0 . 举一个最小的例子, use actix_multi
在actix-web documentation is only an example如何接收唯一命名的查询参数。 但是我如何接收同名的多个查询参数呢?例如: http://localhost:808
我正在使用 sqlx 访问数据库的 actix-web 2.0.0 中实现身份验证提取器。我有这个代码: use actix_web::{dev, web, Error, HttpRequest, F
我有一个正在实现的 API,其中有一个需要调用的昂贵函数。我想记住这个函数或使用键值缓存来查找以前的结果。我也会考虑 Mutex或类似的结构,但我想避免诸如 Redis 或 Memcached 之类的
我是一名优秀的程序员,十分优秀!