-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
28 lines (25 loc) · 894 Bytes
/
init.py
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 kafka import KafkaConsumer
from kafka import KafkaProducer
import globals
import json
# Kafka initialize
consumer_obj = KafkaConsumer(
globals.RECEIVE_TOPIC,
bootstrap_servers=[globals.KAFKA_HOSTNAME + ':' + globals.KAFKA_PORT],
auto_offset_reset="earliest",
enable_auto_commit=True,
group_id="my-group",
value_deserializer=lambda x: json.loads(x.decode("utf-8")),
security_protocol="SASL_PLAINTEXT",
sasl_mechanism='PLAIN',
sasl_plain_username=globals.KAFKA_USERNAME,
sasl_plain_password=globals.KAFKA_PASSWORD
)
producer_obj = KafkaProducer(
bootstrap_servers=[globals.KAFKA_HOSTNAME + ':' + globals.KAFKA_PORT],
value_serializer=lambda x: json.dumps(x).encode("utf-8"),
security_protocol="SASL_PLAINTEXT",
sasl_mechanism='PLAIN',
sasl_plain_username=globals.KAFKA_USERNAME,
sasl_plain_password=globals.KAFKA_PASSWORD
)