- update: code update to use kube api instead of consul
This commit is contained in:
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{info, Level};
|
||||
use utils::consul_registration;
|
||||
use utils::service_discovery::get_service_address;
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
|
||||
|
||||
mod axum_gateway;
|
||||
|
||||
@@ -24,41 +24,13 @@ 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("API_SERVICE_PORT").unwrap_or_else(|_| "8080".to_string());
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8079".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(|_| "api-service".to_string());
|
||||
let service_address = env::var("API_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 meta = HashMap::new();
|
||||
consul_registration::register_service(
|
||||
&consul_url,
|
||||
service_id.as_str(),
|
||||
service_name.as_str(),
|
||||
service_address.as_str(),
|
||||
service_port.parse().unwrap_or(8080),
|
||||
tags,
|
||||
meta,
|
||||
Some("http"),
|
||||
Some(&health_check_url),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Start health-check endpoint
|
||||
consul_registration::start_health_check(addr.as_str()).await?;
|
||||
|
||||
let auth_node = get_service_address(&consul_url, "auth-service").await?;
|
||||
let auth_node = get_kube_service_endpoints_by_dns("auth-service","tcp","auth-service").await?;
|
||||
let auth_address = auth_node.get(0).unwrap();
|
||||
let auth_service_address = format!(
|
||||
"http://{}:{}",
|
||||
auth_address.ServiceAddress, auth_address.ServicePort
|
||||
);
|
||||
let auth_service_address = format!("http://{}", auth_address);
|
||||
|
||||
// Connect to the gRPC auth-service
|
||||
let grpc_client = AuthServiceClient::connect(auth_service_address.to_string()).await?;
|
||||
@@ -69,10 +41,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tokio::spawn(axum_gateway::serve_rest_api(grpc_client));
|
||||
|
||||
utils::signal_handler::wait_for_signal().await;
|
||||
|
||||
consul_registration::deregister_service(&consul_url, service_id.as_str())
|
||||
.await
|
||||
.expect("");
|
||||
info!("service {} deregistered", service_name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user