Page MenuHomePhabricator

D5677.diff
No OneTemporary

D5677.diff

diff --git a/services/blob/src/constants.rs b/services/blob/src/constants.rs
new file mode 100644
--- /dev/null
+++ b/services/blob/src/constants.rs
@@ -0,0 +1 @@
+pub const GRPC_SERVER_DEFAULT_PORT: u64 = 50051;
diff --git a/services/blob/src/main.rs b/services/blob/src/main.rs
--- a/services/blob/src/main.rs
+++ b/services/blob/src/main.rs
@@ -1,8 +1,26 @@
+pub mod constants;
pub mod service;
use anyhow::Result;
+use service::{blob::blob_service_server::BlobServiceServer, MyBlobService};
+use std::net::SocketAddr;
+use tonic::transport::Server;
+
+async fn run_grpc_server() -> Result<()> {
+ let addr: SocketAddr =
+ format!("[::]:{}", constants::GRPC_SERVER_DEFAULT_PORT).parse()?;
+ let blob_service = MyBlobService::default();
+
+ println!("Starting gRPC server at port {}", addr.port());
+ Server::builder()
+ .add_service(BlobServiceServer::new(blob_service))
+ .serve(addr)
+ .await?;
-fn main() -> Result<()> {
- println!("Hello world");
Ok(())
}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ run_grpc_server().await
+}
diff --git a/services/blob/src/service.rs b/services/blob/src/service.rs
--- a/services/blob/src/service.rs
+++ b/services/blob/src/service.rs
@@ -1,3 +1,41 @@
+use anyhow::Result;
+use blob::blob_service_server::BlobService;
+use std::pin::Pin;
+use tokio_stream::Stream;
+use tonic::{Request, Response, Status};
+
pub mod blob {
tonic::include_proto!("blob");
}
+
+#[derive(Default)]
+pub struct MyBlobService {}
+
+// gRPC implementation
+#[tonic::async_trait]
+impl BlobService for MyBlobService {
+ type PutStream =
+ Pin<Box<dyn Stream<Item = Result<blob::PutResponse, Status>> + Send>>;
+ async fn put(
+ &self,
+ _request: Request<tonic::Streaming<blob::PutRequest>>,
+ ) -> Result<Response<Self::PutStream>, Status> {
+ Err(Status::unimplemented("Not implemented yet"))
+ }
+
+ type GetStream =
+ Pin<Box<dyn Stream<Item = Result<blob::GetResponse, Status>> + Send>>;
+ async fn get(
+ &self,
+ _request: Request<blob::GetRequest>,
+ ) -> Result<Response<Self::GetStream>, Status> {
+ Err(Status::unimplemented("Not implemented yet"))
+ }
+
+ async fn remove(
+ &self,
+ _request: Request<blob::RemoveRequest>,
+ ) -> Result<Response<()>, Status> {
+ Err(Status::unimplemented("Not implemented yet"))
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 7:47 PM (11 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2703031
Default Alt Text
D5677.diff (2 KB)

Event Timeline