-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
|
||
## [Unreleased] - 07-03-2024 | ||
|
||
### Added | ||
|
||
- v0.1.1 CHANGELOG.md added | ||
- v0.1.1 versioning started | ||
- v0.1.1 gRPC added for other services to notify their status | ||
- v0.1.1 proto file(s) introduced for gRPC. its a simple for now but will be extended | ||
- v0.1.1 build.rs added to compile proto files | ||
|
||
### Changed | ||
|
||
- v0.1.1 tokio crate updated to latest version | ||
- v0.1.1 Duration::seconds() is now deprecated, changed to try_seconds() | ||
|
||
## [0.1.0] | ||
|
||
### Added | ||
|
||
- v0.1.0 initial | ||
|
||
### Fixed | ||
|
||
### Changed | ||
|
||
### Removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::{env, error::Error, path::PathBuf}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let out_dir = PathBuf::from(env::var("OUT_DIR")?); | ||
|
||
tonic_build::configure() | ||
.file_descriptor_set_path(out_dir.join("remonproto_descriptor.bin")) | ||
.compile(&[r".\proto\notification.proto"], &["proto"])?; | ||
|
||
tonic_build::compile_protos(r".\proto\notification.proto")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package remonproto; | ||
|
||
service NotificationService { | ||
rpc SendNotification(NotificationRequest) returns (NotificationResponse) {} | ||
} | ||
|
||
message NotificationRequest { | ||
string title = 1; | ||
string body = 2; | ||
string token = 3; | ||
} | ||
|
||
message NotificationResponse { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod grpc_service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use log::{info}; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
|
||
pub mod remonproto { | ||
tonic::include_proto!("remonproto"); | ||
|
||
pub(super) const FILE_DESCRIPTOR_SET: &[u8] = | ||
tonic::include_file_descriptor_set!("remonproto_descriptor"); | ||
} | ||
|
||
use remonproto::{ | ||
notification_service_server::{NotificationService as NotificationServiceImpl, NotificationServiceServer}, | ||
NotificationRequest, NotificationResponse, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub struct NotificationService; | ||
|
||
#[tonic::async_trait] | ||
impl NotificationServiceImpl for NotificationService { | ||
async fn send_notification( | ||
&self, | ||
request: Request<NotificationRequest>, | ||
) -> Result<Response<NotificationResponse>, Status> { | ||
let request = request.into_inner(); | ||
|
||
info!( | ||
"Received notification: {} - {}", | ||
request.title, request.body | ||
); | ||
|
||
// TODO(isaidsari): send notification here | ||
|
||
let response = remonproto::NotificationResponse { | ||
message: "Notification received".into(), | ||
}; | ||
|
||
// return the response | ||
Ok(Response::new(response)) | ||
} | ||
} | ||
|
||
pub async fn init() -> Result<(), Box<dyn std::error::Error>> { | ||
let addr = "[::1]:50051".parse()?; | ||
let notification_service = NotificationService::default(); | ||
|
||
// use reflection to expose the service | ||
let reflection_service = tonic_reflection::server::Builder::configure() | ||
.register_encoded_file_descriptor_set(remonproto::FILE_DESCRIPTOR_SET) | ||
.build() | ||
.unwrap(); | ||
|
||
info!("gRPC service listening on {}", addr); | ||
|
||
Server::builder() | ||
.add_service(NotificationServiceServer::new(notification_service)) | ||
.add_service(reflection_service) | ||
.serve(addr) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters