use anyhow::Context; use async_trait::async_trait; use grpc::PingResponse; mod grpc { include!("gen/nodata.v1.rs"); } #[derive(Default)] pub struct NoData { transformers: Option>, } impl NoData { pub fn new() -> Self { Self { transformers: Option::default(), } } pub fn with_transformer( &mut self, transformer: T, ) -> &mut Self { self.transformers = Some(Box::new(transformer)); self } pub async fn serve(&mut self) -> anyhow::Result<()> { tracing::info!("starting no data component"); let grpc_server = grpc::no_data_component_server::NoDataComponentServer::new(NoDataGrpc {}); tracing::info!("component grpc listening on: 127.0.0.1:7900"); tonic::transport::Server::builder() .add_service(grpc_server) .serve("127.0.0.1:7900".parse()?) .await .context("nodata component grpc server failed")?; Ok(()) } } struct NoDataGrpc {} #[async_trait] impl grpc::no_data_component_server::NoDataComponent for NoDataGrpc { async fn transform_msg( &self, request: tonic::Request, ) -> std::result::Result, tonic::Status> { todo!() } async fn ping( &self, _request: tonic::Request, ) -> std::result::Result, tonic::Status> { Ok(tonic::Response::new(PingResponse {})) } } #[async_trait] pub trait NoDataTransformers { async fn transform_msg(&self) -> anyhow::Result<()>; }