File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 11mod pubsub;
2+ mod reqrep;
23
34fn main ( ) { }
Original file line number Diff line number Diff line change 1+ use bytes:: Bytes ;
2+ use msg_socket:: { RepSocket , ReqSocket } ;
3+ use msg_transport:: tcp:: Tcp ;
4+ use tokio_stream:: StreamExt ;
5+
6+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
7+ async fn test_reqrep ( ) {
8+ let _ = tracing_subscriber:: fmt:: try_init ( ) ;
9+
10+ let mut rep = RepSocket :: new ( Tcp :: default ( ) ) ;
11+ let mut req = ReqSocket :: new ( Tcp :: default ( ) ) ;
12+
13+ rep. bind ( "0.0.0.0:0" ) . await . unwrap ( ) ;
14+
15+ req. connect ( rep. local_addr ( ) . unwrap ( ) ) . await . unwrap ( ) ;
16+
17+ tokio:: spawn ( async move {
18+ while let Some ( request) = rep. next ( ) . await {
19+ let msg = request. msg ( ) . clone ( ) ;
20+ request. respond ( msg) . unwrap ( ) ;
21+ }
22+ } ) ;
23+
24+ let response = req. request ( Bytes :: from_static ( b"hello" ) ) . await . unwrap ( ) ;
25+ tracing:: info!( "Response: {:?}" , response) ;
26+ }
You can’t perform that action at this time.
0 commit comments