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

Handle partition response format for newer brod #99

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 16 additions & 6 deletions lib/elsa/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,33 @@ defmodule Elsa.Util do
def partition_count(endpoints, topic) when is_list(endpoints) do
{:ok, metadata} = :brod.get_metadata(reformat_endpoints(endpoints), [topic])

metadata.topic_metadata
|> Enum.map(fn topic_metadata ->
Enum.count(topic_metadata.partition_metadata)
end)
|> hd()
count_partitions(metadata)
end

def partition_count(connection, topic) when is_atom(connection) or is_pid(connection) do
{:ok, metadata} = :brod_client.get_metadata(connection, topic)

metadata.topic_metadata
count_partitions(metadata)
end

# Handle brod < 3.16
defp count_partitions(%{topic_metadata: topic_metadata}) do
topic_metadata
|> Enum.map(fn topic_metadata ->
Enum.count(topic_metadata.partition_metadata)
end)
|> hd()
end

# Handle brod 3.16+
defp count_partitions(%{topics: topics}) do
topics
|> Enum.map(fn topic ->
Enum.count(topic.partitions)
end)
|> hd()
end

defp connect(endpoints, :controller), do: :kpro.connect_controller(endpoints, [])
defp connect(endpoints, _type), do: :kpro.connect_any(endpoints, [])

Expand Down