@@ -52,24 +52,22 @@ Register a service name to handle incoming connections.
5252
5353``` python
5454async def stream_handler (channel ):
55- print (" Accepted connection" )
5655 print (" Accepted connection" )
5756 try :
5857 async for msg in channel:
59- print (f " Received: { msg. payload} " )
60- response = Message( function_name = " reply" , payload = " Got it!" )
58+ print (f " Received: { msg[ ' payload' ] } " )
59+ response = { " function_name" : " reply" , " payload" : " Got it!" }
6160 await channel.send(response)
6261 except Exception :
6362 pass
6463
6564async def unary_handler (msg ):
66- print (f " Received Unary: { msg. payload} " )
67- return Message( function_name = " reply" , payload = " Got Unary!" )
65+ print (f " Received Unary: { msg[ ' payload' ] } " )
66+ return { " function_name" : " reply" , " payload" : " Got Unary!" }
6867
69- await mesh.register_service(" my-service-name" ,
70- on_request_channel = stream_handler,
71- on_request_reply = unary_handler
72- )
68+ mesh.register_service(" my-service-name" ) \
69+ .on_request_channel(stream_handler) \
70+ .on_request_reply(unary_handler)
7371```
7472
7573### 4. Connect to a Peer (Client)
@@ -78,13 +76,13 @@ Discover and connect to another service.
7876``` python
7977channel = await mesh.service(" target-service-name" ).request_channel(" session-id-123" )
8078
81- out_msg = Message( function_name = " greet" , payload = " Hello World" )
79+ out_msg = { " function_name" : " greet" , " payload" : " Hello World" }
8280await channel.send(out_msg)
8381
8482# Reading messages (Async Iterator handles backpressure)
8583async for msg in channel:
86- print (f " Reply: { msg. payload} " )
87- if msg. payload == " Hello World" : break # Exit loop to close
84+ print (f " Reply: { msg[ ' payload' ] } " )
85+ if msg[ ' payload' ] == " Hello World" : break # Exit loop to close
8886
8987await channel.close()
9088```
0 commit comments