I have a web server in actix-web and recently I built a different C++ server. I decided to implement gRPC as a communication bridge between the 2. But I don't know how to integrate actix web + tonic (invoke gRPC calls in http endpoints). My current solution is: RPCRepository holds all the rpc services and I pass it to app_data as a mutex (because the rpc functions are mutable for some unknown reason). But this approach seems counter intuitive, if I have 1k connections at the same time, why should they have to wait for the mutex to be unlocked? I want to know if my integration is not appropriate or thats the limitation of the actix-web+tonic grpc.
// grpc.rs pub struct RPCClientRepository { pub health_client: HealthCheckPingClient<Channel>, pub suggest_client: SuggesterClient<Channel>, } ... rest ... // main.rs let grpc_ctx = Data::new(Mutex::new(grpc_repo)); println!("[INFO] HTTP Server running at port {}", PORT); HttpServer::new(move || { App::new() .app_data(ctx.clone()) .app_data(grpc_ctx.clone()) .service(activities) }) .bind("0.0.0.0:".to_owned() + PORT)? .run() .await // activities.rs #[get("/activities")] pub async fn activities( req: HttpRequest, ctx: Data<Driver>, rpc_repo: Data<Mutex<RPCClientRepository>>, ) -> impl Responder { let mut unlock = rpc_repo .lock() .unwrap(); let suggestion = unlock .suggest_client .suggest_friends(tonic::Request::new(SuggestRequest { skip: 0, user_id: "".to_string(), })) .await; ... rest ...
Mutexaround the clients? Which versions of each key dependency are you using? Isrt-multi-threadenabled?trait "DerefMut" is required to modify through a dereferenceerror[E0596]. And I don't use multiple threads, so probably rt-multi-thread is disabled. As for the versions, it's set to latest or one of the latest:actix-web = "4.8.0", tonic = "0.11.0", tonic-build = "0.11.0"