23 lines
483 B
Python
23 lines
483 B
Python
from typing import Optional
|
|
|
|
from aiokafka import AIOKafkaProducer
|
|
|
|
from backend.config import KAFKA_URL
|
|
from external.kafka.context import context
|
|
|
|
_producer: Optional[AIOKafkaProducer] = None
|
|
|
|
|
|
async def init_producer():
|
|
global _producer
|
|
_producer = AIOKafkaProducer(
|
|
bootstrap_servers=KAFKA_URL,
|
|
security_protocol='SSL',
|
|
ssl_context=context,
|
|
)
|
|
|
|
|
|
async def get_producer() -> Optional[AIOKafkaProducer]:
|
|
global _producer
|
|
return _producer
|