66import abc
77from typing import Protocol , TypeVar
88
9- import grpc .aio
109from frequenz .channels import Broadcast , Receiver
1110from frequenz .client .dispatch import Client
1211
@@ -55,24 +54,18 @@ class Dispatcher:
5554 Example: Processing running state change dispatches
5655 ```python
5756 import os
58- import grpc.aio
5957 from frequenz.dispatch import Dispatcher, RunningState
6058 from unittest.mock import MagicMock
6159
6260 async def run():
63- host = os.getenv("DISPATCH_API_HOST", "localhost")
64- port = os.getenv("DISPATCH_API_PORT", "50051")
61+ url = os.getenv("DISPATCH_API_URL", "grpc://fz-0004.frequenz.io:50051")
6562 key = os.getenv("DISPATCH_API_KEY", "some-key")
6663
67- service_address = f"{host}:{port}"
68- grpc_channel = grpc.aio.secure_channel(
69- service_address,
70- credentials=grpc.ssl_channel_credentials()
71- )
64+ microgrid_id = 1
65+
7266 dispatcher = Dispatcher(
73- microgrid_id=1,
74- grpc_channel=grpc_channel,
75- svc_addr=service_address,
67+ microgrid_id=microgrid_id,
68+ server_url=url,
7669 key=key
7770 )
7871 await dispatcher.start()
@@ -112,23 +105,17 @@ async def run():
112105 import os
113106 from typing import assert_never
114107
115- import grpc.aio
116108 from frequenz.dispatch import Created, Deleted, Dispatcher, Updated
117109
118110 async def run():
119- host = os.getenv("DISPATCH_API_HOST", "localhost")
120- port = os.getenv("DISPATCH_API_PORT", "50051")
111+ url = os.getenv("DISPATCH_API_URL", "grpc://fz-0004.frequenz.io:50051")
121112 key = os.getenv("DISPATCH_API_KEY", "some-key")
122113
123- service_address = f"{host}:{port}"
124- grpc_channel = grpc.aio.secure_channel(
125- service_address,
126- credentials=grpc.ssl_channel_credentials()
127- )
114+ microgrid_id = 1
115+
128116 dispatcher = Dispatcher(
129- microgrid_id=1,
130- grpc_channel=grpc_channel,
131- svc_addr=service_address,
117+ microgrid_id=microgrid_id,
118+ server_url=url,
132119 key=key
133120 )
134121 await dispatcher.start() # this will start the actor
@@ -154,27 +141,19 @@ async def run():
154141 import os
155142 from datetime import datetime, timedelta, timezone
156143
157- import grpc.aio
158144 from frequenz.client.common.microgrid.components import ComponentCategory
159145
160146 from frequenz.dispatch import Dispatcher
161147
162148 async def run():
163- host = os.getenv("DISPATCH_API_HOST", "localhost")
164- port = os.getenv("DISPATCH_API_PORT", "50051")
149+ url = os.getenv("DISPATCH_API_URL", "grpc://fz-0004.frequenz.io:50051")
165150 key = os.getenv("DISPATCH_API_KEY", "some-key")
166151
167152 microgrid_id = 1
168153
169- service_address = f"{host}:{port}"
170- grpc_channel = grpc.aio.secure_channel(
171- service_address,
172- credentials=grpc.ssl_channel_credentials()
173- )
174154 dispatcher = Dispatcher(
175155 microgrid_id=microgrid_id,
176- grpc_channel=grpc_channel,
177- svc_addr=service_address,
156+ server_url=url,
178157 key=key
179158 )
180159 await dispatcher.start() # this will start the actor
@@ -208,23 +187,21 @@ def __init__(
208187 self ,
209188 * ,
210189 microgrid_id : int ,
211- grpc_channel : grpc .aio .Channel ,
212- svc_addr : str ,
190+ server_url : str ,
213191 key : str ,
214192 ):
215193 """Initialize the dispatcher.
216194
217195 Args:
218196 microgrid_id: The microgrid id.
219- grpc_channel: The gRPC channel.
220- svc_addr: The service address.
197+ server_url: The URL of the dispatch service.
221198 key: The key to access the service.
222199 """
223200 self ._running_state_channel = Broadcast [Dispatch ](name = "running_state_change" )
224201 self ._lifecycle_events_channel = Broadcast [DispatchEvent ](
225202 name = "lifecycle_events"
226203 )
227- self ._client = Client (grpc_channel = grpc_channel , svc_addr = svc_addr , key = key )
204+ self ._client = Client (server_url = server_url , key = key )
228205 self ._actor = DispatchingActor (
229206 microgrid_id ,
230207 self ._client ,
0 commit comments