68 lines
1.7 KiB
Rust
68 lines
1.7 KiB
Rust
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<Box<dyn NoDataTransformers + 'static>>,
|
|
}
|
|
|
|
impl NoData {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
transformers: Option::default(),
|
|
}
|
|
}
|
|
|
|
pub fn with_transformer<T: NoDataTransformers + 'static>(
|
|
&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<grpc::HandleMsgRequest>,
|
|
) -> std::result::Result<tonic::Response<grpc::HandleMsgResponse>, tonic::Status> {
|
|
todo!()
|
|
}
|
|
|
|
async fn ping(
|
|
&self,
|
|
_request: tonic::Request<grpc::PingRequest>,
|
|
) -> std::result::Result<tonic::Response<grpc::PingResponse>, tonic::Status> {
|
|
Ok(tonic::Response::new(PingResponse {}))
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait NoDataTransformers {
|
|
async fn transform_msg(&self) -> anyhow::Result<()>;
|
|
}
|