@@ -21,7 +21,6 @@ use std::sync::{Arc, RwLock};
21
21
use super :: memory_registry:: MemoryRegistry ;
22
22
use super :: BoxRegistry ;
23
23
use crate :: codegen:: TripleInvoker ;
24
- use crate :: common:: consts;
25
24
use crate :: common:: url:: Url ;
26
25
use crate :: protocol:: triple:: triple_exporter:: TripleExporter ;
27
26
use crate :: protocol:: triple:: triple_protocol:: TripleProtocol ;
@@ -35,16 +34,24 @@ pub struct RegistryProtocol {
35
34
registries : Arc < RwLock < HashMap < String , BoxRegistry > > > ,
36
35
// providerUrl: Exporter
37
36
exporters : Arc < RwLock < HashMap < String , BoxExporter > > > ,
37
+ // serviceName: registryUrls
38
+ services : HashMap < String , Vec < Url > > ,
38
39
}
39
40
40
41
impl RegistryProtocol {
41
42
pub fn new ( ) -> Self {
42
43
RegistryProtocol {
43
44
registries : Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ,
44
45
exporters : Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ,
46
+ services : HashMap :: new ( ) ,
45
47
}
46
48
}
47
49
50
+ pub fn with_services ( mut self , services : HashMap < String , Vec < Url > > ) -> Self {
51
+ self . services . extend ( services) ;
52
+ self
53
+ }
54
+
48
55
pub fn get_registry ( & mut self , url : Url ) -> BoxRegistry {
49
56
let mem = MemoryRegistry :: default ( ) ;
50
57
self . registries
@@ -70,10 +77,14 @@ impl Protocol for RegistryProtocol {
70
77
// init Exporter based on provider_url
71
78
// server registry based on register_url
72
79
// start server health check
73
- let registry_url = get_registry_url ( url. clone ( ) ) ;
74
- if !registry_url. protocol . is_empty ( ) {
75
- let mut reg = self . get_registry ( registry_url. clone ( ) ) ;
76
- reg. register ( registry_url. clone ( ) ) . unwrap ( ) ;
80
+ let registry_url = self . services . get ( url. get_service_name ( ) . join ( "," ) . as_str ( ) ) ;
81
+ if let Some ( urls) = registry_url {
82
+ for url in urls. clone ( ) . iter ( ) {
83
+ if !url. protocol . is_empty ( ) {
84
+ let mut reg = self . get_registry ( url. clone ( ) ) ;
85
+ reg. register ( url. clone ( ) ) . unwrap ( ) ;
86
+ }
87
+ }
77
88
}
78
89
79
90
match url. clone ( ) . protocol . as_str ( ) {
@@ -83,10 +94,11 @@ impl Protocol for RegistryProtocol {
83
94
}
84
95
_ => {
85
96
tracing:: error!( "protocol {:?} not implemented" , url. protocol) ;
97
+ Box :: new ( TripleExporter :: new ( ) )
86
98
}
87
99
}
88
- Box :: new ( TripleExporter :: new ( ) )
89
100
}
101
+
90
102
async fn refer ( self , url : Url ) -> Self :: Invoker {
91
103
// getRegisterUrl
92
104
// get Registry from registry_url
@@ -95,16 +107,3 @@ impl Protocol for RegistryProtocol {
95
107
Box :: new ( TripleInvoker :: new ( url) )
96
108
}
97
109
}
98
-
99
- fn get_registry_url ( mut url : Url ) -> Url {
100
- // registry_url need storage some places
101
- if url. protocol == consts:: REGISTRY_PROTOCOL {
102
- url. protocol = url. get_param ( "registry" . to_string ( ) ) . unwrap ( ) ;
103
- }
104
-
105
- url
106
- }
107
-
108
- fn get_provider_url ( url : Url ) -> Url {
109
- url
110
- }
0 commit comments