I am trying to read the earliest/oldest message which has not been read before in Kafka.
import json
from kafka import KafkaConsumer
from kafka import KafkaProducer
ORDER_KAFKA_TOPIC = "order_details"
ORDER_CONFIRMED_KAFKA_TOPIC = "order_confirmed"
consumer = KafkaConsumer(
ORDER_KAFKA_TOPIC,
bootstrap_servers="localhost:29092",
auto_offset_reset = "earliest",
enable_auto_commit=False,
)
print("Gonna start listening")
while True:
for message in consumer:
print("Ongoing transaction..")
consumed_message = json.loads(message.value.decode())
print(consumed_message)
I have set the parameters:
auto_offset_reset = "earliest",
enable_auto_commit=False,
As per the docs:
The enable_auto_commit option is set to False when creating the consumer. This means that the consumer will not automatically commit its offsets, so it will only receive messages that have not yet been committed by another consumer. This allows the consumer to read only unread messages from the topic.
However I am still getting messages that have been read.