-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- add PersistentInstanceRequest structure - add register and deregister persistent service method Close #210
- Loading branch information
Showing
5 changed files
with
364 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
mod batch_instance_request; | ||
mod instance_request; | ||
mod notify_subscriber_request; | ||
mod persistent_instance_request; | ||
mod service_list_request; | ||
mod service_query_request; | ||
mod subscribe_service_request; | ||
|
||
pub(crate) use batch_instance_request::*; | ||
pub(crate) use instance_request::*; | ||
pub(crate) use notify_subscriber_request::*; | ||
pub(crate) use persistent_instance_request::*; | ||
pub(crate) use service_list_request::*; | ||
pub(crate) use service_query_request::*; | ||
pub(crate) use subscribe_service_request::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use nacos_macro::request; | ||
|
||
use crate::{api::naming::ServiceInstance, common::remote::generate_request_id}; | ||
|
||
#[request(identity = "PersistentInstanceRequest", module = "naming")] | ||
pub(crate) struct PersistentInstanceRequest { | ||
#[serde(rename = "type")] | ||
pub(crate) r_type: String, | ||
pub(crate) instance: ServiceInstance, | ||
} | ||
|
||
impl PersistentInstanceRequest { | ||
pub(crate) fn register( | ||
instance: ServiceInstance, | ||
service_name: Option<String>, | ||
namespace: Option<String>, | ||
group_name: Option<String>, | ||
) -> Self { | ||
PersistentInstanceRequest::new( | ||
RequestType::Register, | ||
instance, | ||
service_name, | ||
namespace, | ||
group_name, | ||
) | ||
} | ||
|
||
pub(crate) fn deregister( | ||
instance: ServiceInstance, | ||
service_name: Option<String>, | ||
namespace: Option<String>, | ||
group_name: Option<String>, | ||
) -> Self { | ||
PersistentInstanceRequest::new( | ||
RequestType::Deregister, | ||
instance, | ||
service_name, | ||
namespace, | ||
group_name, | ||
) | ||
} | ||
|
||
fn new( | ||
request_type: RequestType, | ||
instance: ServiceInstance, | ||
service_name: Option<String>, | ||
namespace: Option<String>, | ||
group_name: Option<String>, | ||
) -> Self { | ||
let request_id = Some(generate_request_id()); | ||
Self { | ||
r_type: request_type.request_code(), | ||
instance, | ||
request_id, | ||
namespace, | ||
service_name, | ||
group_name, | ||
..Default::default() | ||
} | ||
} | ||
} | ||
|
||
pub(crate) enum RequestType { | ||
Register, | ||
Deregister, | ||
} | ||
|
||
impl RequestType { | ||
pub(crate) fn request_code(&self) -> String { | ||
match self { | ||
RequestType::Register => "registerInstance".to_string(), | ||
RequestType::Deregister => "deregisterInstance".to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<&str> for RequestType { | ||
fn from(code: &str) -> Self { | ||
match code { | ||
"registerInstance" => RequestType::Register, | ||
"deregisterInstance" => RequestType::Deregister, | ||
_ => RequestType::Register, | ||
} | ||
} | ||
} |
Oops, something went wrong.