Commands | Kafka Consumer Groups

A consumer group lets multiple consumers share the work of reading a topic. The broker tracks the committed offsets per GroupId and assigns the topic partitions to the members of the group, so each partition is read by only one member at a time. Set the group with KafkaOptions.Consumer.GroupId.

For a new group with no committed offsets, KafkaOptions.Consumer.OffsetReset decides where to start: kafkaOffsetEarliest reads from the beginning of the partition, kafkaOffsetLatest reads only new records. Once offsets are committed, consumption resumes from the last committed position.

Call CommitSync to commit the offsets of the records returned by the last Poll, so the group resumes after them on the next session. If you leave GroupId empty, the client consumes all partitions directly without joining a group and without committing offsets to the broker.

Basic Usage


oKafka.KafkaOptions.Consumer.GroupId := 'orders-group';
oKafka.KafkaOptions.Consumer.OffsetReset := kafkaOffsetEarliest;
oKafka.Subscribe(['orders']);

var
  oMessages: TsgcKafkaMessages;
begin
  oMessages := oKafka.Poll(1000);
  if oMessages.Count > 0 then
    oKafka.CommitSync;
end;