- add: consul tags and metadata

- update: login reply now requests for the character services from consul to build the server list
This commit is contained in:
2024-12-10 15:45:35 -05:00
parent a7af7f1b9e
commit 9121b7f88b
6 changed files with 93 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::net::ToSocketAddrs;
@@ -85,12 +86,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Register service with Consul
let service_id = consul_registration::generate_service_id();
let tags = vec!["version-1.0".to_string()];
let mut meta = HashMap::new();
meta.insert("name".to_string(), "Athena".to_string());
consul_registration::register_service(
&consul_url,
service_id.as_str(),
service_name.as_str(),
service_address,
service_port.parse().unwrap_or(50052),
tags,
meta,
&health_check_url,
)
.await?;
@@ -102,7 +108,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::spawn(warp::serve(health_route).run(health_check_endpoint_addr.to_socket_addrs()?.next().unwrap()));
let auth_address = auth_node.get(0).unwrap();
let auth_url = format!("http://{}:{}", auth_address.0, auth_address.1);
let auth_url = format!("http://{}:{}", auth_address.ServiceAddress, auth_address.ServicePort);
let auth_client = Arc::new(Mutex::new(AuthClient::connect(&auth_url).await?));
let full_addr = format!("{}:{}", &addr, port);