Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support callbacks for partitions assigned/revoked #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/kaffe/config/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Kaffe.Config.Consumer do
group_config: consumer_group_config(),
consumer_config: client_consumer_config(),
message_handler: message_handler(),
partitions_listener: partitions_listener(),
async_message_ack: async_message_ack(),
rebalance_delay_ms: rebalance_delay_ms(),
max_bytes: max_bytes(),
Expand All @@ -31,6 +32,8 @@ defmodule Kaffe.Config.Consumer do

def message_handler, do: config_get!(:message_handler)

def partitions_listener, do: config_get!(:partitions_listener)

def async_message_ack, do: config_get(:async_message_ack, false)

def endpoints do
Expand Down
14 changes: 10 additions & 4 deletions lib/kaffe/consumer_group/subscriber/group_member.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ defmodule Kaffe.GroupMember do
worker_manager_pid: nil,
topic: nil,
configured_offset: nil,
current_gen_id: nil
current_gen_id: nil,
partitions_listener: nil
end

## ==========================================================================
Expand Down Expand Up @@ -102,7 +103,8 @@ defmodule Kaffe.GroupMember do
group_coordinator_pid: pid,
consumer_group: consumer_group,
worker_manager_pid: worker_manager_pid,
topic: topic
topic: topic,
partitions_listener: Kaffe.Config.Consumer.configuration().partitions_listener
}}
end

Expand All @@ -111,14 +113,14 @@ defmodule Kaffe.GroupMember do
# configuration.
def handle_cast({:assignments_received, gen_id, assignments}, state) do
Logger.info("event#assignments_received=#{name(state.subscriber_name, state.topic)} generation_id=#{gen_id}")

state.partitions_listener.assigned(assignments)
Process.send_after(self(), {:allocate_subscribers, gen_id, assignments}, rebalance_delay())
{:noreply, %{state | current_gen_id: gen_id}}
end

def handle_cast({:assignments_revoked}, state) do
Logger.info("event#assignments_revoked=#{name(state.subscriber_name, state.topic)}")

state.partitions_listener.revoked()
stop_subscribers(state.subscribers)
{:noreply, %{state | :subscribers => []}}
end
Expand Down Expand Up @@ -207,6 +209,10 @@ defmodule Kaffe.GroupMember do
Application.get_env(:kaffe, :subscriber_mod, Kaffe.Subscriber)
end

defp partitions_listener do
Application.get_env(:kaffe, :partitions_listener)
end

defp name(subscriber_name, topic) do
:"#{__MODULE__}.#{subscriber_name}.#{topic}"
end
Expand Down