v1.0.1 changes #11
@@ -45,9 +45,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(8080),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
Some("http"),
|
||||
Some(&health_check_url),
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
// Start health-check endpoint
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
|
||||
@@ -26,6 +26,7 @@ warp = "0.3.7"
|
||||
reqwest = { version = "0.12.9", features = ["json"] }
|
||||
utils = { path = "../utils" }
|
||||
uuid = "1.11.0"
|
||||
tonic-health = "0.12.3"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.12.3"
|
||||
|
||||
@@ -28,21 +28,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("AUTH_SERVICE_PORT").unwrap_or_else(|_| "50051".to_string());
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8081".to_string());
|
||||
|
||||
let consul_url = env::var("CONSUL_URL").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
|
||||
let service_name = env::var("SERVICE_NAME").unwrap_or_else(|_| "auth-service".to_string());
|
||||
let service_address = env::var("AUTH_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let service_port = port.clone();
|
||||
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
|
||||
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
|
||||
let db_nodes = get_service_address(&consul_url, "database-service").await?;
|
||||
let session_nodes = get_service_address(&consul_url, "session-service").await?;
|
||||
|
||||
// Register service with Consul
|
||||
let service_id = consul_registration::get_or_generate_service_id(env!("CARGO_PKG_NAME"));
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let tags = vec![version];
|
||||
let tags = vec![version, "grpc".to_string()];
|
||||
let meta = HashMap::new();
|
||||
consul_registration::register_service(
|
||||
&consul_url,
|
||||
@@ -52,12 +49,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50052),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Start health-check endpoint
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
.await?;
|
||||
|
||||
let db_address = db_nodes.get(0).unwrap();
|
||||
let db_url = format!(
|
||||
@@ -80,11 +75,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
session_client,
|
||||
};
|
||||
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<AuthServiceServer<MyAuthService>>().await;
|
||||
|
||||
println!("Authentication Service running on {}", addr);
|
||||
|
||||
// Start the gRPC server
|
||||
tokio::spawn(
|
||||
Server::builder()
|
||||
.add_service(health_service)
|
||||
.add_service(AuthServiceServer::new(auth_service))
|
||||
.serve(address),
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ prost = "0.13.4"
|
||||
warp = "0.3.7"
|
||||
async-trait = "0.1.83"
|
||||
serde_json = "1.0.133"
|
||||
tonic-health = "0.12.3"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.12.3"
|
||||
@@ -29,21 +29,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("CHARACTER_SERVICE_PORT").unwrap_or_else(|_| "50053".to_string());
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8083".to_string());
|
||||
|
||||
let consul_url = env::var("CONSUL_URL").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
|
||||
let service_name = env::var("SERVICE_NAME").unwrap_or_else(|_| "character-service".to_string());
|
||||
let service_address =
|
||||
env::var("CHARACTER_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let service_port = port.clone();
|
||||
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
|
||||
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
|
||||
let db_nodes = get_service_address(&consul_url, "database-service").await?;
|
||||
|
||||
// Register service with Consul
|
||||
let service_id = consul_registration::get_or_generate_service_id(env!("CARGO_PKG_NAME"));
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let tags = vec![version];
|
||||
let tags = vec![version, "grpc".to_string()];
|
||||
let mut meta = HashMap::new();
|
||||
meta.insert("name".to_string(), "Rose".to_string());
|
||||
consul_registration::register_service(
|
||||
@@ -54,12 +51,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50052),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Start health-check endpoint
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
.await?;
|
||||
|
||||
let full_addr = format!("{}:{}", &addr, port);
|
||||
let address = full_addr.parse().expect("Invalid address");
|
||||
@@ -72,8 +67,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let character_service = MyCharacterService {
|
||||
character_db_client,
|
||||
};
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<CharacterServiceServer<MyCharacterService>>().await;
|
||||
|
||||
tonic::transport::Server::builder()
|
||||
.add_service(health_service)
|
||||
.add_service(CharacterServiceServer::new(character_service))
|
||||
.serve(address)
|
||||
.await?;
|
||||
|
||||
@@ -20,6 +20,7 @@ prost = "0.13.3"
|
||||
serde_json = "1.0.133"
|
||||
async-trait = "0.1.83"
|
||||
utils = { path = "../utils" }
|
||||
tonic-health = "0.12.3"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.12.3"
|
||||
|
||||
@@ -26,7 +26,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("DATABASE_SERVICE_PORT").unwrap_or_else(|_| "50052".to_string());
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8080".to_string());
|
||||
|
||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
let redis_url =
|
||||
@@ -37,12 +36,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let service_address =
|
||||
env::var("DATABASE_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let service_port = port.clone();
|
||||
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
|
||||
|
||||
// Register service with Consul
|
||||
let service_id = consul_registration::get_or_generate_service_id(env!("CARGO_PKG_NAME"));
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let tags = vec![version];
|
||||
let tags = vec![version, "grpc".to_string()];
|
||||
let meta = HashMap::new();
|
||||
consul_registration::register_service(
|
||||
&consul_url,
|
||||
@@ -52,9 +50,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50052),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
|
||||
@@ -70,10 +69,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let db = Arc::new(Database::new(pool, redis_cache));
|
||||
let my_service = MyDatabaseService { db };
|
||||
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<UserServiceServer<MyDatabaseService>>().await;
|
||||
|
||||
// Pass `shared_cache` into services as needed
|
||||
info!("Database Service running on {}", address);
|
||||
tokio::spawn(
|
||||
Server::builder()
|
||||
.add_service(health_service)
|
||||
.add_service(UserServiceServer::new(my_service.clone()))
|
||||
.add_service(CharacterDbServiceServer::new(my_service))
|
||||
.serve(address),
|
||||
|
||||
@@ -77,7 +77,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
env::var("PACKET_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let service_port = port.clone();
|
||||
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
|
||||
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
|
||||
let auth_node = get_service_address(&consul_url, "auth-service").await?;
|
||||
let character_node = get_service_address(&consul_url, "character-service").await?;
|
||||
|
||||
@@ -94,7 +93,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50052),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
Some("http"),
|
||||
Some(&health_check_url),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ prost = "0.13.4"
|
||||
warp = "0.3.7"
|
||||
chrono = "0.4.39"
|
||||
serde_json = "1.0.133"
|
||||
tonic-health = "0.12.3"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.12.3"
|
||||
@@ -34,7 +34,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("SESSION_SERVICE_PORT").unwrap_or_else(|_| "50055".to_string());
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8084".to_string());
|
||||
|
||||
let redis_url =
|
||||
std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string());
|
||||
@@ -43,12 +42,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let service_address =
|
||||
env::var("SESSION_SERVICE_ADDR").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let service_port = port.clone();
|
||||
let health_check_url = format!("http://{}:{}/health", service_address, health_port);
|
||||
|
||||
// Register service with Consul
|
||||
let service_id = consul_registration::get_or_generate_service_id(env!("CARGO_PKG_NAME"));
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let tags = vec![version];
|
||||
let tags = vec![version, "grpc".to_string()];
|
||||
let meta = HashMap::new();
|
||||
consul_registration::register_service(
|
||||
&consul_url,
|
||||
@@ -58,20 +56,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50055),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Start health-check endpoint
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
.await?;
|
||||
|
||||
let full_addr = format!("{}:{}", &addr, port);
|
||||
let address = full_addr.parse().expect("Invalid address");
|
||||
let redis_cache = Arc::new(Mutex::new(RedisCache::new(&redis_url)));
|
||||
let session_service = SessionServiceImpl { redis: redis_cache };
|
||||
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<SessionServiceServer<SessionServiceImpl>>().await;
|
||||
|
||||
tokio::spawn(
|
||||
Server::builder()
|
||||
.add_service(health_service)
|
||||
.add_service(SessionServiceServer::new(session_service))
|
||||
.serve(address),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use reqwest::Client;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
@@ -10,23 +10,6 @@ use warp::Filter;
|
||||
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct ConsulRegistration {
|
||||
id: String,
|
||||
name: String,
|
||||
address: String,
|
||||
port: u16,
|
||||
tags: Vec<String>,
|
||||
meta: HashMap<String, String>,
|
||||
check: ConsulCheck,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct ConsulCheck {
|
||||
http: String,
|
||||
interval: String,
|
||||
}
|
||||
|
||||
pub fn generate_service_id() -> String {
|
||||
Uuid::new_v4().to_string()
|
||||
}
|
||||
@@ -60,21 +43,33 @@ pub async fn register_service(
|
||||
service_port: u16,
|
||||
tags: Vec<String>,
|
||||
mut meta: HashMap<String, String>,
|
||||
health_check_url: &str,
|
||||
health_check_protocol: Option<&str>,
|
||||
health_check_address: Option<&str>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
meta.insert("version".to_string(), VERSION.to_string());
|
||||
let registration = ConsulRegistration {
|
||||
id: service_id.to_string(),
|
||||
name: service_name.to_string(),
|
||||
address: service_address.to_string(),
|
||||
port: service_port,
|
||||
tags,
|
||||
meta,
|
||||
check: ConsulCheck {
|
||||
http: health_check_url.to_string(),
|
||||
interval: "10s".to_string(), // Health check interval
|
||||
},
|
||||
};
|
||||
|
||||
let mut check_protocol = "grpc".to_string();
|
||||
let mut check_address = format!("{}:{}", service_name, service_port);
|
||||
if health_check_protocol.is_some() {
|
||||
check_protocol = health_check_protocol.unwrap().to_string();
|
||||
}
|
||||
if health_check_address.is_some() {
|
||||
check_address = health_check_address.unwrap().to_string();
|
||||
}
|
||||
|
||||
let registration = json!({
|
||||
"id": format!("{}-{}", service_name, service_id),
|
||||
"name": service_name.to_string(),
|
||||
"address": service_address.to_string(),
|
||||
"port": service_port,
|
||||
"tags": tags,
|
||||
"meta": meta,
|
||||
"check": {
|
||||
check_protocol: check_address,
|
||||
"interval": "10s",
|
||||
"timeout": "2s"
|
||||
}
|
||||
});
|
||||
|
||||
let client = Client::new();
|
||||
let consul_register_url = format!("{}/v1/agent/service/register", consul_url);
|
||||
|
||||
@@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Register service with Consul
|
||||
let service_id = consul_registration::get_or_generate_service_id(env!("CARGO_PKG_NAME"));
|
||||
let version = env!("CARGO_PKG_VERSION").to_string();
|
||||
let tags = vec![version];
|
||||
let tags = vec![version, "grpc".to_string()];
|
||||
let mut meta = HashMap::new();
|
||||
meta.insert("name".to_string(), "Athena".to_string());
|
||||
consul_registration::register_service(
|
||||
@@ -44,7 +44,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
service_port.parse().unwrap_or(50054),
|
||||
tags,
|
||||
meta,
|
||||
&health_check_url,
|
||||
Some("http"),
|
||||
Some(&health_check_url),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user