diff --git a/examples/actix-web-example/config.yml b/examples/actix-web-example/config.yml index ad79a2e..94d22f0 100644 --- a/examples/actix-web-example/config.yml +++ b/examples/actix-web-example/config.yml @@ -2,7 +2,7 @@ shenyu: register: register_type: "http" servers: "http://127.0.0.1:9095" - namespace_id: "testNamespaceId" + namespace_id: "649330b6-c2d7-4edc-be8e-8a54df9eb385" props: username: "admin" password: "123456" diff --git a/examples/axum-example/config.yml b/examples/axum-example/config.yml index ad79a2e..29dab92 100644 --- a/examples/axum-example/config.yml +++ b/examples/axum-example/config.yml @@ -2,7 +2,7 @@ shenyu: register: register_type: "http" servers: "http://127.0.0.1:9095" - namespace_id: "testNamespaceId" + namespace_id: "" props: username: "admin" password: "123456" diff --git a/shenyu-client-rust/src/core.rs b/shenyu-client-rust/src/core.rs index 182465b..0ba9ce9 100644 --- a/shenyu-client-rust/src/core.rs +++ b/shenyu-client-rust/src/core.rs @@ -20,6 +20,7 @@ use crate::error::ShenYuError; use crate::model::{EventType, UriInfo}; use dashmap::DashMap; use serde_json::Value; +use std::collections::HashMap; use std::io::{Error, ErrorKind}; use std::net::IpAddr; use tracing::{error, info, warn}; @@ -94,10 +95,14 @@ impl ShenyuClient { "Content-Type".to_string(), "application/json;charset=UTF-8".to_string(), ); - let namespace_ids: Vec = config.register.namespace_id.clone().map_or( - vec![SYS_DEFAULT_NAMESPACE_ID.to_string()], - |x| -> Vec { x.split(';').map(ToString::to_string).collect() }, - ); + let namespace_ids: Vec = config + .register + .namespace_id + .clone() + .filter(|x| !x.is_empty()) + .map_or(vec![SYS_DEFAULT_NAMESPACE_ID.to_string()], |x| { + x.split(';').map(ToString::to_string).collect() + }); let mut client = ShenyuClient { headers, @@ -389,10 +394,37 @@ impl ShenyuClient { let props = &self.env.discovery.props.clone(); let plugin_name = &self.env.discovery.plugin_name.clone(); let context_path = &self.env.uri.context_path.clone(); + let namespace_ids = &self.namespace_ids.clone(); let port = &self.port; let host = &self.host; + namespace_ids.iter().for_each(|namespace_id| { + self._register_discovery_config( + discovery_type, + register_path, + server_lists, + props, + plugin_name, + context_path, + namespace_id, + host, + port, + ); + }); + } + fn _register_discovery_config( + &self, + discovery_type: &str, + register_path: &str, + server_lists: &str, + props: &HashMap, + plugin_name: &str, + context_path: &str, + namespace_id: &str, + host: &Option, + port: &u16, + ) { let json_data = serde_json::json!({ "name": "default".to_string() + discovery_type, "selectorName": context_path, @@ -400,8 +432,9 @@ impl ShenyuClient { "listenerNode":register_path, "serverList": server_lists, "props": props, - "discoveryType": discovery_type.clone(), + "discoveryType": discovery_type, "pluginName": plugin_name, + "namespaceId": namespace_id, }); // Broadcast to all shenyu admin.