Packages

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. (Simpli.fi fork)

Current section

Files

Jump to
elsa_fi lib elsa partitioner md5.ex
Raw

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