@@ -26,13 +26,13 @@ from mesh_lib import Mesh
2626from mesh_lib.shared.types import MeshConfig, ServiceDiscoveryConfig, Message
2727
2828config = MeshConfig(
29+ redis = {" host" : " localhost" , " port" : 6379 }, # Shared Redis Config
2930 service_discovery = ServiceDiscoveryConfig(
30- redis_config = {" host" : " localhost" , " port" : 6379 },
3131 heartbeat_interval = 2 ,
3232 heartbeat_threshold = 3
3333 ),
34- host = " 127.0.0.1" , # Your local IP/Host
35- port = 0 # 0 for random available port
34+ # host="127.0.0.1", # Optional: Auto-detected if omitted
35+ port = 0
3636)
3737```
3838
@@ -60,14 +60,14 @@ Register a service name to handle incoming connections.
6060``` python
6161async def stream_handler (channel ):
6262 print (" Accepted connection" )
63- while True :
64- try :
65- msg = await channel.receive()
63+ print ( " Accepted connection " )
64+ try :
65+ async for msg in channel:
6666 print (f " Received: { msg.payload} " )
6767 response = Message(function_name = " reply" , payload = " Got it!" )
6868 await channel.send(response)
69- except Exception :
70- break
69+ except Exception :
70+ pass
7171
7272async def unary_handler (msg ):
7373 print (f " Received Unary: { msg.payload} " )
@@ -83,7 +83,7 @@ await mesh.register_service("my-service-name",
8383Discover and connect to another service.
8484
8585``` python
86- channel = await mesh.request_channel (" target-service-name" , " session-id-123" )
86+ channel = await mesh.service (" target-service-name" ).request_channel( " session-id-123" )
8787
8888out_msg = Message(function_name = " greet" , payload = " Hello World" )
8989await channel.send(out_msg)
0 commit comments