kaffeine v0.2.0 Kaffeine

Documentation for Kaffeine.

Summary

Functions

Receives a topic name to consume, and the module, function, and additional arguments of the handler

Produce a message to a given topic. A Producer must already be setup for the topic you wish to write to

Build the configuration for a produce worker for a specific topic

Functions

consumer(topic, mfa, opts \\ [])

Receives a topic name to consume, and the module, function, and additional arguments of the handler.

Returns a Kaffeine.Consumer struct of the consumer defintion.

produce(message, topic, key \\ nil)
produce(any, String.t, String.t | nil) :: :ok

Produce a message to a given topic. A Producer must already be setup for the topic you wish to write to.

Examples

iex> Kaffeine.produce("hello world", "test")
:ok

iex> Kaffeine.produce(%{id: 501, name: "Bob"}, "Users")
:ok
producer(topic, opts \\ [])

Build the configuration for a produce worker for a specific topic.

ex: producer("NewMessage", encoder: &Poison.encode/1, partitioner: fn message, max_partitions -> {:ok, rem(message.user_id, max_partitions)} end)

opts:

  • encoder (any -> {:ok, any} | {:error, String.t})

    An anonymous function that is used when producing messages to encode for Kafka.

    ex: fn message -> {:ok, Poison.encode(message)} end

  • partitioner (any -> {:ok, integer} | {:error, String.t})

    An anonymous function that is used to determine which partition to put the message in. Is passed the message and the max number of partitions for the topic.

    ex: fn message, max_partitions -> {:ok, rem(message.user_id, max_partitions)} end

  • required_acks

    Required acknowledgements by kafka brokers before considered successful.

  • timeout

    Request timeout in milliseconds.

start(consumers, opts \\ [])