-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfaststream.py
More file actions
28 lines (21 loc) · 782 Bytes
/
Copy pathfaststream.py
File metadata and controls
28 lines (21 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Dict, Union
import structlog
from domains.events import get_topic_registry
from faststream.redis import RedisBroker
from faststream.redis.publisher.asyncapi import AsyncAPIPublisher
from opentelemetry.instrumentation.faststream import RedisOtelMiddleware
from .config import AppConfig
def init_broker(config: AppConfig) -> RedisBroker:
broker = RedisBroker(
config.EVENTS.REDIS_BROKER_URL,
middlewares=(RedisOtelMiddleware,),
logger=structlog.getLogger("faststream.broker"),
)
return broker
def init_publishers(
broker: RedisBroker,
) -> Dict[str, AsyncAPIPublisher]:
return {
topic: broker.publisher(topic, schema=Union[event_types])
for topic, event_types in get_topic_registry().items()
}