When can a Flink job consume from Kafka?

Viewed 29

We have a Flink job which has the following topology:

source -> filter -> map -> sink

We set a live(ready) status at the sink operator open-override function. After we get that status, we send events. Sometimes it can't consume the events sent early.

We want to know the exact time/step that we can send data which will not be missing.

1 Answers

It looks like you want to ensure that no message is missed for processing. Kafka will retain your messages, so there is no need to send messages only when the Flink consumer is ready. You can simplify your design by avoiding the status message.

Any Kafka Consumer (not just Flink Connector) will have an offset associated with it in Kafka Server to track the id of the last message that was consumed.

From kafka docs:

Kafka maintains a numerical offset for each record in a partition. This offset acts as a unique identifier of a record within that partition, and also denotes the position of the consumer in the partition. For example, a consumer which is at position 5 has consumed records with offsets 0 through 4 and will next receive the record with offset 5

In your Flink Kafka Connector, specify the offset as the committed offset.

 OffsetsInitializer.committedOffsets(OffsetResetStrategy.EARLIEST)

This will ensure that if your Flink Connector is restarted, it will consume from the last position that it left off, before the restart.

If for some reason, the offset is lost, this will read from the beginning (earliest message) in your Kafka topic. Note that this approach will cause you to reprocess the messages.

There are many more offset strategies you can explore to choose the right one for you.

Refer - https://nightlies.apache.org/flink/flink-docs-master/docs/connectors/datastream/kafka/#starting-offset

Related