This is an automated email from the ASF dual-hosted git repository.
xuehuilang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shenyu-client-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 9a870e0 support empty namespace id. (#9)
9a870e0 is described below
commit 9a870e0a0e3722e8883f952e6a4202b1842f18cf
Author: DamonXue <[email protected]>
AuthorDate: Thu Jan 2 21:54:43 2025 +0800
support empty namespace id. (#9)
* support empty namespace id.
* support empty namespace id +1
* compile error.
---
examples/actix-web-example/config.yml | 2 +-
examples/axum-example/config.yml | 2 +-
shenyu-client-rust/src/core.rs | 43 +++++++++++++++++++++++++++++++----
3 files changed, 40 insertions(+), 7 deletions(-)
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<String> =
config.register.namespace_id.clone().map_or(
- vec![SYS_DEFAULT_NAMESPACE_ID.to_string()],
- |x| -> Vec<String> {
x.split(';').map(ToString::to_string).collect() },
- );
+ let namespace_ids: Vec<String> = 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<String, String>,
+ plugin_name: &str,
+ context_path: &str,
+ namespace_id: &str,
+ host: &Option<String>,
+ 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.