mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:48:26 +02:00
Better connection management
This commit is contained in:
@@ -10,8 +10,8 @@ use crate::proto::{fill_pool, method_desc_to_path};
|
||||
|
||||
mod codec;
|
||||
mod json_schema;
|
||||
mod proto;
|
||||
pub mod manager;
|
||||
mod proto;
|
||||
|
||||
pub fn serialize_options() -> SerializeOptions {
|
||||
SerializeOptions::new().skip_default_fields(false)
|
||||
@@ -64,7 +64,7 @@ pub async fn client_streaming(
|
||||
DynamicMessage::deserialize(input_message, &mut deserializer).map_err(|e| e.to_string())?;
|
||||
deserializer.end().unwrap();
|
||||
|
||||
let mut client = tonic::client::Grpc::new(conn);
|
||||
let mut client = tonic::client::Grpc::with_origin(conn, uri.clone());
|
||||
|
||||
println!(
|
||||
"\n---------- SENDING -----------------\n{}",
|
||||
@@ -84,43 +84,6 @@ pub async fn client_streaming(
|
||||
Ok(response_json)
|
||||
}
|
||||
|
||||
pub async fn server_streaming(
|
||||
uri: &Uri,
|
||||
service: &str,
|
||||
method: &str,
|
||||
message_json: &str,
|
||||
) -> Result<Response<Streaming<DynamicMessage>>, String> {
|
||||
let (pool, conn) = fill_pool(uri).await;
|
||||
|
||||
let service = pool.get_service_by_name(service).unwrap();
|
||||
let method = &service.methods().find(|m| m.name() == method).unwrap();
|
||||
let input_message = method.input();
|
||||
|
||||
let mut deserializer = Deserializer::from_str(message_json);
|
||||
let req_message =
|
||||
DynamicMessage::deserialize(input_message, &mut deserializer).map_err(|e| e.to_string())?;
|
||||
deserializer.end().unwrap();
|
||||
|
||||
let mut client = tonic::client::Grpc::new(conn);
|
||||
|
||||
println!(
|
||||
"\n---------- SENDING -----------------\n{}",
|
||||
serde_json::to_string_pretty(&req_message).expect("json")
|
||||
);
|
||||
|
||||
let req = req_message.into_request();
|
||||
let path = method_desc_to_path(method);
|
||||
let codec = DynamicCodec::new(method.clone());
|
||||
client.ready().await.unwrap();
|
||||
|
||||
let resp = client.server_streaming(req, path, codec).await.unwrap();
|
||||
// let response_json = serde_json::to_string_pretty(&resp.into_inner()).expect("json to string");
|
||||
// println!("\n---------- RECEIVING ---------------\n{}", response_json,);
|
||||
|
||||
// Ok(response_json)
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
pub async fn callable(uri: &Uri) -> Vec<ServiceDefinition> {
|
||||
let (pool, _) = fill_pool(uri).await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user