Coverage for docs/docs_src/getting_started/cli/nats/worker_id.py: 92%

10 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-17 21:20 +0000

1from faststream import FastStream 

2from faststream.nats import NatsBroker 

3 

4broker = NatsBroker() 

5app = FastStream(broker) 

6 

7 

8@broker.subscriber("my-subject") 

9async def handler(msg: dict) -> None: 

10 print(f"Received: {msg}") 

11 

12 

13@app.on_startup 

14async def startup(worker_id: int | None) -> None: 

15 if worker_id is None: 

16 print("Started in a single process") 

17 else: 

18 print(f"Worker {worker_id} started")