Skip to content

Commit

Permalink
namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
damonxue committed Oct 11, 2024
1 parent f428e36 commit b346ca3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/actix-web-example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ shenyu:
register:
register_type: "http"
servers: "http://127.0.0.1:9095"
namespace_id: "testNamespaceId"
props:
username: "admin"
password: "123456"
Expand Down
1 change: 1 addition & 0 deletions examples/axum-example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ shenyu:
register:
register_type: "http"
servers: "http://127.0.0.1:9095"
namespace_id: "testNamespaceId"
props:
username: "admin"
password: "123456"
Expand Down
1 change: 1 addition & 0 deletions shenyu-client-rust/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ shenyu:
register:
register_type: "http"
servers: "http://127.0.0.1:9095"
namespace_id: "testNamespaceId"
props:
username: "admin"
password: "123456"
Expand Down
1 change: 1 addition & 0 deletions shenyu-client-rust/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl ShenYuConfig {
pub struct RegisterConfig {
pub register_type: String,
pub servers: String,
pub namespace_id: Option<String>,
pub props: HashMap<String, String>,
}

Expand Down
17 changes: 17 additions & 0 deletions shenyu-client-rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub const REGISTER_OFFLINE_SUFFIX: &str = "/shenyu-client/offline";
/// Shenyu admin http interface path.
pub const PLATFORM_LOGIN_SUFFIX: &str = "/platform/login";

/// Shenyu admin default namespace id.
pub const SYS_DEFAULT_NAMESPACE_ID: &str = "649330b6-c2d7-4edc-be8e-8a54df9eb385";

/// The shenyu client.
#[derive(Debug)]
#[warn(dead_code)]
Expand All @@ -49,6 +52,7 @@ pub struct ShenyuClient {
env: ShenYuConfig,
host: Option<String>,
port: u16,
namespace_id: String,
gateway_base_urls: Vec<String>,
register_meta_data_path_list: Vec<String>,
register_uri_list: Vec<String>,
Expand Down Expand Up @@ -90,12 +94,19 @@ impl ShenyuClient {
"Content-Type".to_string(),
"application/json;charset=UTF-8".to_string(),
);
let namespace_id = config
.register
.namespace_id
.clone()
.unwrap_or(SYS_DEFAULT_NAMESPACE_ID.to_string());

let mut client = ShenyuClient {
headers,
app_name: app_name.to_string(),
env: config,
host: None,
port,
namespace_id,
gateway_base_urls: vec![],
register_meta_data_path_list: vec![],
register_uri_list: vec![],
Expand Down Expand Up @@ -234,6 +245,7 @@ impl ShenyuClient {
let app_name = &self.app_name.clone();
let rpc_type = &self.env.uri.rpc_type.clone();
let context_path = &self.env.uri.context_path.clone();
let namespace_id = &self.namespace_id.clone();

let port = &self.port;
let host = &self.host;
Expand All @@ -245,6 +257,7 @@ impl ShenyuClient {
"rpcType": rpc_type,
"host": host.clone().unwrap(),
"port": port,
"namespaceId": namespace_id,
"eventType": EventType::REGISTER.to_string(),
});

Expand Down Expand Up @@ -290,6 +303,7 @@ impl ShenyuClient {
) {
let context_path = &self.env.uri.context_path.clone();
let app_name = &self.app_name.clone();
let namespace_id = &self.namespace_id.clone();
let rpc_type = &self.env.uri.rpc_type.clone();
let path = if register_all {
format!("{context_path}**")
Expand All @@ -311,6 +325,7 @@ impl ShenyuClient {
"rpcExt": "",
"host": self.host.clone().unwrap(),
"port": self.port,
"namespaceId": namespace_id,
"enabled": enabled,
"registerMetaData": "",
"pluginNames": []
Expand Down Expand Up @@ -373,6 +388,7 @@ impl ShenyuClient {
/// Offline from shenyu.
pub fn offline_register(&self) {
let app_name = &self.app_name.clone();
let namespace_id = &self.namespace_id.clone();
let rpc_type = &self.env.uri.rpc_type.clone();
let context_path = &self.env.uri.context_path.clone();

Expand All @@ -385,6 +401,7 @@ impl ShenyuClient {
"protocol": rpc_type,
"host": host.clone().unwrap(),
"port": port,
"namespaceId": namespace_id,
"eventType": EventType::REGISTER.to_string(),
});

Expand Down

0 comments on commit b346ca3

Please sign in to comment.