-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.py
24 lines (18 loc) · 825 Bytes
/
consumer.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
from catalog_microservice.infra.messaging.repositories.kafka_repository import KafkaRepository
from catalog_microservice.infra.messaging.entities.topics import Topics
def apresentationMessage(message):
print (f"Key: {message.key} - Value: {message.value}")
def consumer_update_stock():
kafkaRepository = KafkaRepository()
consumer = kafkaRepository.get_consumer()
consumer.subscribe([Topics.PRODUCT_STOCK_UPDATED.value])
while True:
message = kafkaRepository.consume_message(
consumer = consumer,
topic= Topics.PRODUCT_STOCK_UPDATED.value)
if message is not None:
apresentationMessage(message)
else:
print ("No message")
if __name__ == "__main__":
consumer_update_stock()