feat: context kafka
This commit is contained in:
3
external/kafka/consumer.py
vendored
3
external/kafka/consumer.py
vendored
@@ -3,11 +3,14 @@ from aiokafka.errors import KafkaConnectionError
|
||||
|
||||
from backend.config import KAFKA_URL, KAFKA_CONSUMER_TOPIC
|
||||
from backend.session import session_maker
|
||||
from external.kafka.context import context
|
||||
from external.kafka.services.consumer_service import ConsumerService
|
||||
|
||||
consumer = AIOKafkaConsumer(
|
||||
KAFKA_CONSUMER_TOPIC,
|
||||
bootstrap_servers=KAFKA_URL,
|
||||
security_protocol='SSL',
|
||||
ssl_context=context,
|
||||
)
|
||||
|
||||
|
||||
|
||||
11
external/kafka/context.py
vendored
Normal file
11
external/kafka/context.py
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
from pathlib import Path
|
||||
|
||||
from aiokafka.helpers import create_ssl_context
|
||||
|
||||
from constants import KAFKA_CERTS_PATH
|
||||
|
||||
context = create_ssl_context(
|
||||
cafile=KAFKA_CERTS_PATH / Path('ca-cert'),
|
||||
certfile=KAFKA_CERTS_PATH / Path('cert-signed'),
|
||||
keyfile=KAFKA_CERTS_PATH / Path('cert-key'),
|
||||
)
|
||||
7
external/kafka/producer.py
vendored
7
external/kafka/producer.py
vendored
@@ -1,5 +1,10 @@
|
||||
from aiokafka import AIOKafkaProducer
|
||||
|
||||
from backend.config import KAFKA_URL
|
||||
from external.kafka.context import context
|
||||
|
||||
producer = AIOKafkaProducer(bootstrap_servers=KAFKA_URL)
|
||||
producer = AIOKafkaProducer(
|
||||
bootstrap_servers=KAFKA_URL,
|
||||
security_protocol='SSL',
|
||||
ssl_context=context,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user