@@ -101,7 +101,7 @@ async def run(self, count: int) -> None:
101101 start_to_close_timeout = timedelta (seconds = 30 ),
102102 heartbeat_timeout = timedelta (seconds = 10 ),
103103 )
104- self .stream .publish ("status" , b"activity_done" )
104+ self .stream .topic ("status" , type = bytes ). publish ( b"activity_done" )
105105 await workflow .wait_condition (lambda : self ._closed )
106106
107107
@@ -125,7 +125,9 @@ def close(self) -> None:
125125 @workflow .run
126126 async def run (self , count : int ) -> None :
127127 for i in range (count ):
128- self .stream .publish ("events" , AgentEvent (kind = "tick" , payload = {"i" : i }))
128+ self .stream .topic ("events" , type = AgentEvent ).publish (
129+ AgentEvent (kind = "tick" , payload = {"i" : i })
130+ )
129131 await workflow .wait_condition (lambda : self ._closed )
130132
131133
@@ -164,7 +166,7 @@ def close(self) -> None:
164166 @workflow .run
165167 async def run (self , count : int ) -> None :
166168 for i in range (count ):
167- self .stream .publish ("events" , f"item-{ i } " .encode ())
169+ self .stream .topic ("events" , type = bytes ). publish ( f"item-{ i } " .encode ())
168170 await workflow .wait_condition (lambda : self ._closed )
169171
170172
@@ -203,14 +205,14 @@ def close(self) -> None:
203205
204206 @workflow .run
205207 async def run (self , count : int ) -> None :
206- self .stream .publish ("status" , b"started" )
208+ self .stream .topic ("status" , type = bytes ). publish ( b"started" )
207209 await workflow .execute_activity (
208210 "publish_items" ,
209211 count ,
210212 start_to_close_timeout = timedelta (seconds = 30 ),
211213 heartbeat_timeout = timedelta (seconds = 10 ),
212214 )
213- self .stream .publish ("status" , b"done" )
215+ self .stream .topic ("status" , type = bytes ). publish ( b"done" )
214216 await workflow .wait_condition (lambda : self ._closed )
215217
216218
@@ -280,7 +282,7 @@ async def run(self, count: int) -> None:
280282 start_to_close_timeout = timedelta (seconds = 30 ),
281283 heartbeat_timeout = timedelta (seconds = 10 ),
282284 )
283- self .stream .publish ("status" , b"activity_done" )
285+ self .stream .topic ("status" , type = bytes ). publish ( b"activity_done" )
284286 await workflow .wait_condition (lambda : self ._closed )
285287
286288
@@ -349,7 +351,7 @@ async def publish_items(count: int) -> None:
349351 async with client :
350352 for i in range (count ):
351353 activity .heartbeat ()
352- client .publish ("events" , f"item-{ i } " .encode ())
354+ client .topic ("events" , type = bytes ). publish ( f"item-{ i } " .encode ())
353355
354356
355357@activity .defn (name = "publish_multi_topic" )
@@ -362,7 +364,7 @@ async def publish_multi_topic(count: int) -> None:
362364 for i in range (count ):
363365 activity .heartbeat ()
364366 topic = topics [i % len (topics )]
365- client .publish (topic , f"{ topic } -{ i } " .encode ())
367+ client .topic (topic , type = bytes ). publish ( f"{ topic } -{ i } " .encode ())
366368
367369
368370@activity .defn (name = "publish_with_priority" )
@@ -376,9 +378,9 @@ async def publish_with_priority() -> None:
376378 batch_interval = timedelta (seconds = 60 )
377379 )
378380 async with client :
379- client .publish ("events" , b"normal-0" )
380- client .publish ("events" , b"normal-1" )
381- client .publish ("events" , b"priority" , force_flush = True )
381+ client .topic ("events" , type = bytes ). publish ( b"normal-0" )
382+ client .topic ("events" , type = bytes ). publish ( b"normal-1" )
383+ client .topic ("events" , type = bytes ). publish ( b"priority" , force_flush = True )
382384 for _ in range (100 ):
383385 activity .heartbeat ()
384386 await asyncio .sleep (0.1 )
@@ -392,7 +394,7 @@ async def publish_batch_test(count: int) -> None:
392394 async with client :
393395 for i in range (count ):
394396 activity .heartbeat ()
395- client .publish ("events" , f"item-{ i } " .encode ())
397+ client .topic ("events" , type = bytes ). publish ( f"item-{ i } " .encode ())
396398
397399
398400@activity .defn (name = "publish_with_max_batch" )
@@ -403,7 +405,7 @@ async def publish_with_max_batch(count: int) -> None:
403405 async with client :
404406 for i in range (count ):
405407 activity .heartbeat ()
406- client .publish ("events" , f"item-{ i } " .encode ())
408+ client .topic ("events" , type = bytes ). publish ( f"item-{ i } " .encode ())
407409 # Yield so the flusher task can run when max_batch_size triggers
408410 # _flush_event. Real workloads (e.g. agents awaiting LLM streams)
409411 # yield constantly; a tight loop with no awaits would never let
@@ -1085,9 +1087,9 @@ async def test_explicit_flush_barrier(client: Client) -> None:
10851087
10861088 # 2. Flush makes prior publishes visible without waiting on
10871089 # the 60s batch timer.
1088- stream .publish ("events" , b"a" )
1089- stream .publish ("events" , b"b" )
1090- stream .publish ("events" , b"c" )
1090+ stream .topic ("events" , type = bytes ). publish ( b"a" )
1091+ stream .topic ("events" , type = bytes ). publish ( b"b" )
1092+ stream .topic ("events" , type = bytes ). publish ( b"c" )
10911093 await stream .flush ()
10921094 assert await stream .get_offset () == 3
10931095
@@ -1279,14 +1281,14 @@ async def maybe_failing_signal(*args: Any, **kwargs: Any) -> Any:
12791281 return await real_signal (* args , ** kwargs )
12801282
12811283 with patch .object (handle , "signal" , side_effect = maybe_failing_signal ):
1282- stream .publish ("events" , b"item-0" )
1283- stream .publish ("events" , b"item-1" )
1284+ stream .topic ("events" , type = bytes ). publish ( b"item-0" )
1285+ stream .topic ("events" , type = bytes ). publish ( b"item-1" )
12841286 with pytest .raises (RuntimeError ):
12851287 await stream ._flush ()
12861288
12871289 # Publish more during the failed state — must not overtake the
12881290 # pending retry on eventual delivery.
1289- stream .publish ("events" , b"item-2" )
1291+ stream .topic ("events" , type = bytes ). publish ( b"item-2" )
12901292 with pytest .raises (RuntimeError ):
12911293 await stream ._flush ()
12921294
@@ -1336,7 +1338,7 @@ async def maybe_failing_signal(*args: Any, **kwargs: Any) -> Any:
13361338 ),
13371339 patch .object (handle , "signal" , side_effect = maybe_failing_signal ),
13381340 ):
1339- stream .publish ("events" , b"lost" )
1341+ stream .topic ("events" , type = bytes ). publish ( b"lost" )
13401342
13411343 # First flush fails and enters the pending-retry state.
13421344 with pytest .raises (RuntimeError ):
@@ -1351,7 +1353,7 @@ async def maybe_failing_signal(*args: Any, **kwargs: Any) -> Any:
13511353
13521354 # Stop failing signals; subsequent publishes must succeed.
13531355 fail_signals = False
1354- stream .publish ("events" , b"kept" )
1356+ stream .topic ("events" , type = bytes ). publish ( b"kept" )
13551357 await stream ._flush ()
13561358
13571359 items = await collect_items (client , handle , None , 0 , 1 )
@@ -1586,7 +1588,7 @@ def __init__(self, prepub_count: int = 0) -> None:
15861588 self .stream = WorkflowStream ()
15871589 self ._closed = False
15881590 for i in range (prepub_count ):
1589- self .stream .publish ("events" , f"item-{ i } " .encode ())
1591+ self .stream .topic ("events" , type = bytes ). publish ( f"item-{ i } " .encode ())
15901592
15911593 @workflow .signal
15921594 def close (self ) -> None :
@@ -1890,7 +1892,7 @@ def close(self) -> None:
18901892 @workflow .run
18911893 async def run (self , count : int ) -> None :
18921894 for i in range (count ):
1893- self .stream .publish ("events" , f"broker-{ i } " .encode ())
1895+ self .stream .topic ("events" , type = bytes ). publish ( f"broker-{ i } " .encode ())
18941896 await workflow .wait_condition (lambda : self ._closed )
18951897
18961898
@@ -2001,7 +2003,7 @@ async def standalone_publish_to_broker(input: StandalonePublishInput) -> None:
20012003 async with client :
20022004 for i in range (input .count ):
20032005 activity .heartbeat ()
2004- client .publish ("events" , f"standalone-{ i } " .encode ())
2006+ client .topic ("events" , type = bytes ). publish ( f"standalone-{ i } " .encode ())
20052007
20062008
20072009@activity .defn (name = "standalone_subscribe_to_broker" )
@@ -2187,7 +2189,7 @@ def close(self) -> None:
21872189 @workflow .run
21882190 async def run (self , count : int ) -> str :
21892191 for i in range (count ):
2190- self .stream .publish ("events" , f"nexus-{ i } " .encode ())
2192+ self .stream .topic ("events" , type = bytes ). publish ( f"nexus-{ i } " .encode ())
21912193 await workflow .wait_condition (lambda : self ._closed )
21922194 return "done"
21932195
0 commit comments