Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Kafka: Replay messages in a topic

I'm considering using Apache Kafka as an event store for storing events within a microservice.

One thing that I read through various blogs is that Kafka can be considered to be a single source of truth, where Kafka log will store all the events for a given topic.

I was wondering if Kafka has the ability to replay messages since the beginning of time (in case there is a hard drive/network crash that occurs for example)?

(note that i see that there are some logs stored in the /tmp folder under a topic directory). Does anyone know of any command (if any) that can be invoked to replay the messages in the topic?

like image 737
rm12345 Avatar asked Jan 28 '18 01:01

rm12345


People also ask

How do you replay messages on Kafka?

Create a new consumer group (with a new, unique group ID) of consumers. Bring up this consumer group and attach it to the topic that contains the messages to be replayed. The consumers in the consumer group will start consuming messages from the earliest offsets in the partitions, effective replaying the messages.

How can I see Kafka messages in topic?

You can use the Kafka-console-consumer to view your messages. It provides a command line utility, bin/kafka-console-consumer.sh, that sends messages from a topic to an output file. To display a maximum number of messages by using: --from-beginning and --max-messages ${NUM_MESSAGES}.

How do you retry in Kafka?

Retries happen within the consumer poll for the batch. Consumer poll must complete before poll timeout, containing all retries, and total processing time (including REST calls & DB calls), retry delay and backoff, for all records in the batch. Default poll time is 5 minutes for 500 records in the batch.

Can Kafka deliver same message twice?

Initially, Kafka only supported at-most-once and at-least-once message delivery. However, the introduction of Transactions between Kafka brokers and client applications ensures exactly-once delivery in Kafka.


2 Answers

Yes, you can seek to a specific offset, but

beginning of time

depends on the topic or broker configuration. IIRC, the default retention is 7 days.

Refer to the the Kafka documentation.

like image 53
Gary Russell Avatar answered Nov 09 '22 20:11

Gary Russell


Yes, You can replay message. As Consumer have a control over resetting the offset. You can start reading messages from the beginning or if you know any existing offset value you can read it from there as well. Once the message is committed it will be in there in topic until its retention period is over. Default retention period is 7 days, however you can change it any time.

like image 36
Vishal Akkalkote Avatar answered Nov 09 '22 22:11

Vishal Akkalkote