14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
- use std:: { collections:: HashMap , error:: Error , sync:: Arc } ;
17
+ use std:: { collections:: HashMap , error:: Error , sync:: Arc , time :: Duration } ;
18
18
19
19
use rocketmq_common:: TokioExecutorService ;
20
+ use tokio:: { runtime:: Handle , time, time:: timeout} ;
20
21
use tracing:: info;
21
22
22
23
use crate :: {
23
24
clients:: { Client , RemotingClient } ,
24
25
protocol:: remoting_command:: RemotingCommand ,
25
26
remoting:: { InvokeCallback , RemotingService } ,
26
- runtime:: {
27
- config:: client_config:: TokioClientConfig , processor:: RequestProcessor , RPCHook ,
28
- ServiceBridge ,
29
- } ,
27
+ runtime:: { config:: client_config:: TokioClientConfig , processor:: RequestProcessor , RPCHook } ,
30
28
} ;
31
29
32
30
pub struct RocketmqDefaultClient {
33
- service_bridge : ServiceBridge ,
34
31
tokio_client_config : TokioClientConfig ,
35
32
//cache connection
36
33
connection_tables :
@@ -42,7 +39,6 @@ pub struct RocketmqDefaultClient {
42
39
impl RocketmqDefaultClient {
43
40
pub fn new ( tokio_client_config : TokioClientConfig ) -> Self {
44
41
Self {
45
- service_bridge : ServiceBridge :: new ( ) ,
46
42
tokio_client_config,
47
43
connection_tables : Default :: default ( ) ,
48
44
namesrv_addr_list : Arc :: new ( Default :: default ( ) ) ,
@@ -133,7 +129,8 @@ impl RemotingClient for RocketmqDefaultClient {
133
129
}
134
130
135
131
fn get_name_server_address_list ( & self ) -> Vec < String > {
136
- todo ! ( )
132
+ let cloned = self . namesrv_addr_list . clone ( ) ;
133
+ Handle :: current ( ) . block_on ( async move { cloned. lock ( ) . await . clone ( ) } )
137
134
}
138
135
139
136
fn get_available_name_srv_list ( & self ) -> Vec < String > {
@@ -147,10 +144,15 @@ impl RemotingClient for RocketmqDefaultClient {
147
144
timeout_millis : u64 ,
148
145
) -> RemotingCommand {
149
146
let client = self . get_and_create_client ( addr. clone ( ) ) . await ;
150
- let client_ref = & mut * client. lock ( ) . await ;
151
- ServiceBridge :: invoke_sync ( client_ref, request, timeout_millis)
152
- . await
153
- . unwrap ( )
147
+ if let Ok ( result) = timeout ( Duration :: from_millis ( timeout_millis) , async {
148
+ client. lock ( ) . await . send_read ( request) . await . unwrap ( )
149
+ } )
150
+ . await
151
+ {
152
+ result
153
+ } else {
154
+ RemotingCommand :: create_response_command ( )
155
+ }
154
156
}
155
157
156
158
async fn invoke_async (
@@ -161,18 +163,29 @@ impl RemotingClient for RocketmqDefaultClient {
161
163
invoke_callback : impl InvokeCallback ,
162
164
) -> Result < ( ) , Box < dyn Error > > {
163
165
let client = self . get_and_create_client ( addr. clone ( ) ) . await ;
164
- let client_ref = & mut * client. lock ( ) . await ;
165
- ServiceBridge :: invoke_async ( client_ref, request, timeout_millis, invoke_callback) . await ;
166
+ if let Ok ( resp) = time:: timeout ( Duration :: from_millis ( timeout_millis) , async {
167
+ client. lock ( ) . await . send_read ( request) . await . unwrap ( )
168
+ } )
169
+ . await
170
+ {
171
+ invoke_callback. operation_succeed ( resp)
172
+ }
173
+
166
174
Ok ( ( ) )
167
175
}
168
176
169
- fn invoke_oneway (
177
+ async fn invoke_oneway (
170
178
& self ,
171
179
addr : String ,
172
180
request : RemotingCommand ,
173
181
timeout_millis : u64 ,
174
182
) -> Result < ( ) , Box < dyn Error > > {
175
- todo ! ( )
183
+ let client = self . get_and_create_client ( addr. clone ( ) ) . await ;
184
+ let _ = time:: timeout ( Duration :: from_millis ( timeout_millis) , async move {
185
+ client. lock ( ) . await . send ( request) . await . unwrap ( )
186
+ } )
187
+ . await ;
188
+ Ok ( ( ) )
176
189
}
177
190
178
191
fn register_processor (
0 commit comments