Packages
elsa_kafka
2.0.0
Elsa is a full-featured Kafka library written in Elixir and extending the :brod library with additional support from the :kafka_protocol Erlang libraries to provide capabilities not available in :brod.
Current section
Files
Jump to
Current section
Files
lib/elsa/partitioner/md5.ex
defmodule Elsa.Partitioner.Md5 do
@moduledoc """
Chooses a topic partition based on an md5 hash of the
supplied value, typically the message content.
"""
@behaviour Elsa.Partitioner
def partition(count, key) do
:crypto.hash(:md5, key)
|> :binary.bin_to_list()
|> Enum.sum()
|> rem(count)
end
end