View Source brod_group_member behaviour (brod v3.18.0)

Implement brod_group_member behaviour callbacks to allow a process to act as a group member without having to deal with Kafka group protocol details. A typical workflow:

1. Spawn a group coordinator by calling brod_group_coordinator:start_link/6.

2. Subscribe to partitions received in the assignments from assignments_received/4 callback.

3. Receive messages from the assigned partitions (delivered by the partition workers (the pollers) implemented in brod_consumer).

4. Unsubscribe from all previously subscribed partitions when assignments_revoked/1 is called.

For group members that commit offsets to Kafka, do:

1. Call brod_group_coordinator:ack/5. to acknowledge successful consumption of the messages. Group coordinator will commit the acknowledged offsets at configured interval.

2. Call brod_group_coordinator:commit_offsets/2 to force an immediate offset commit if necessary.

For group members that manage offsets locally, do:

1. Implement the get_committed_offsets/2 callback. This callback is evaluated every time when new assignments are received.

Link to this section Summary

Link to this section Callbacks

Link to this callback

assign_partitions/3

View Source (optional)
-callback assign_partitions(pid(), [brod:group_member()], [{brod:topic(), brod:partition()}]) ->
                     [{brod:group_member_id(), [brod:partition_assignment()]}].
-callback assignments_received(pid(),
                     brod:group_member_id(),
                     brod:group_generation_id(),
                     brod:received_assignments()) ->
                        ok.
-callback assignments_revoked(pid()) -> ok.
-callback get_committed_offsets(pid(), [{brod:topic(), brod:partition()}]) ->
                         {ok, [{{brod:topic(), brod:partition()}, brod:offset()}]}.
-callback user_data(pid()) -> binary().