I have created implemented Kafka Producer-Consumer messaging with Topic using python.How can I do the same with Queue so that the message will be only devilered to a single consumer .
This is my Producer code
# Import KafkaProducer from Kafka library
from kafka import KafkaProducer
# Define server with port
bootstrap_servers = ['localhost:9092']
# Define topic name where the message will publish
topicName = 'First_Topic'
# Initialize producer variable
producer = KafkaProducer(bootstrap_servers = bootstrap_servers)
i=1
for i in range(100):
# Publish text in defined topic
message_data = input("Enter message ")
producer.send(topicName,str.encode(message_data) )
# Print message
print("Message Sent")
i=i+1
And this is my consumer code.
from kafka import KafkaConsumer
consumer = KafkaConsumer(bootstrap_servers=['localhost:9092'], auto_offset_reset='earliest')
consumer.subscribe(['First_Topic'])
for msg in consumer:
print("Message from Producer on Topic - "+msg.topic+":"+ msg.value.decode())