Kaffe.Producer (Kaffe v1.25.0) View Source

The producer pulls in values from the Kaffe producer configuration:

  • heroku_kafka_env - endpoints and SSL configuration will be pulled from ENV
  • endpoints - plaintext Kafka endpoints
  • topics - a list of Kafka topics to prep for producing
  • partition_strategy - the strategy to use when selecting the next partition. Default :md5.
    • :md5: provides even and deterministic distrbution of the messages over the available partitions based on an MD5 hash of the key
    • :random - Select a random partition
    • function - Pass a function as an argument that accepts five arguments and returns the partition number to use for the message
      • topic, current_partition, partitions_count, key, value

Clients can also specify a partition directly when producing.

Currently only synchronous production is supported.

Link to this section Summary

Types

Headers represent a list of tuples containing key, value pairs of type binary()

A Kafka message can be represented as a tuple containing a key value pair of type binary()

A Kafka message can also be represented as a map, containing :key, :value, and :headers

Functions

Synchronously produce the messages_list to topic

Synchronously produce the given key/value to the first Kafka topic.

Synchronously produce the key/value to topic

Synchronously produce the given key/value to the topic/partition

Link to this section Types

Specs

headers() :: [{key :: binary(), value :: binary()}]

Headers represent a list of tuples containing key, value pairs of type binary()

Specs

message() :: {key :: binary(), value :: binary()}

A Kafka message can be represented as a tuple containing a key value pair of type binary()

Specs

message_object() :: %{
  key: key :: binary(),
  value: value :: binary(),
  headers: headers :: headers()
}

A Kafka message can also be represented as a map, containing :key, :value, and :headers

Link to this section Functions

Link to this function

produce(topic, message_list, opts \\ [])

View Source

Synchronously produce the messages_list to topic

  • messages_list must be a list of type message() or message_object()
  • opts may include the partition strategy to use, partition_strategy: :md5, or :random or a function.

Returns:

 * `:ok` on successfully producing each message
 * `{:error, reason}` for any error
Link to this function

produce_sync(topic, message_list)

View Source

Synchronously produce the given key/value to the first Kafka topic.

This is a simpler way to produce if you've only given Producer a single topic for production and don't want to specify the topic for each call.

Returns:

 * `:ok` on successfully producing the message
 * `{:error, reason}` for any error
Link to this function

produce_sync(topic, partition, message_list)

View Source

Synchronously produce the key/value to topic

See produce_sync/2 for returns.

Link to this function

produce_sync(topic, partition, key, value)

View Source

Synchronously produce the given key/value to the topic/partition

See produce_sync/2 for returns.