Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/actix-web-example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 38 additions & 5 deletions shenyu-client-rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -389,19 +394,47 @@ 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,
"handler": "{}",
"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.
Expand Down
Loading