Skip to content

Commit d403771

Browse files
committed
refactor(dubbo): add services to save related protocol_urls and registry_urls
1 parent a6c9a70 commit d403771

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

dubbo/src/common/consts.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
pub const REGISTRY_PROTOCOL: &str = "registry";
18+
pub const REGISTRY_PROTOCOL: &str = "registry_protocol";
19+
pub const PROTOCOL: &str = "protocol";
20+
pub const REGISTRY: &str = "registry";

dubbo/src/framework.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::pin::Pin;
2121
use futures::future;
2222
use futures::Future;
2323

24+
use crate::common::consts;
2425
use crate::common::url::Url;
2526
use crate::protocol::{BoxExporter, Protocol};
2627
use crate::registry::protocol::RegistryProtocol;
@@ -32,6 +33,7 @@ use dubbo_config::{get_global_config, RootConfig};
3233
pub struct Dubbo {
3334
protocols: HashMap<String, Vec<Url>>,
3435
registries: HashMap<String, Url>,
36+
services: HashMap<String, Vec<Url>>, // protocol: Url; registry: Url
3537
config: Option<RootConfig>,
3638
}
3739

@@ -41,6 +43,7 @@ impl Dubbo {
4143
Self {
4244
protocols: HashMap::new(),
4345
registries: HashMap::new(),
46+
services: HashMap::new(),
4447
config: None,
4548
}
4649
}
@@ -63,7 +66,7 @@ impl Dubbo {
6366
.insert(name.to_string(), Url::from_url(url).unwrap());
6467
}
6568

66-
for (_, c) in conf.service.iter() {
69+
for (_, c) in conf.provider.services.iter() {
6770
let u = if c.protocol_configs.is_empty() {
6871
let protocol = match conf.protocols.get(&c.protocol) {
6972
Some(v) => v.to_owned(),
@@ -91,6 +94,26 @@ impl Dubbo {
9194
}
9295

9396
let u = u.unwrap();
97+
if self.services.get(consts::PROTOCOL).is_some() {
98+
self.services
99+
.get_mut(consts::PROTOCOL)
100+
.unwrap()
101+
.push(u.clone());
102+
} else {
103+
self.services
104+
.insert(consts::PROTOCOL.to_string(), vec![u.clone()]);
105+
}
106+
107+
if self.services.get(consts::REGISTRY).is_some() {
108+
self.services
109+
.get_mut(consts::REGISTRY)
110+
.unwrap()
111+
.push(u.clone());
112+
} else {
113+
self.services
114+
.insert(consts::REGISTRY.to_string(), vec![u.clone()]);
115+
}
116+
94117
if self.protocols.get(&c.protocol).is_some() {
95118
self.protocols.get_mut(&c.protocol).unwrap().push(u);
96119
} else {

dubbo/src/registry/protocol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl Protocol for RegistryProtocol {
9797
}
9898

9999
fn get_registry_url(mut url: Url) -> Url {
100+
// registry_url need storage some places
100101
if url.protocol == consts::REGISTRY_PROTOCOL {
101102
url.protocol = url.get_param("registry".to_string()).unwrap();
102103
}

0 commit comments

Comments
 (0)