View Source Klife.Record (Klife v0.1.0)

Kafka record representation.

It represents a Kafka record struct that will be used in the Klife.Client API's.

In general terms it can be used as an input or as an output data.

As an input the Klife.Record may have the following attributes:

  • value (required)
  • topic (required)
  • key (optional)
  • headers (optional)
  • partition (optional)

As an output the input record will be added with one or more the following attributes:

  • offset (if it was succesfully written)
  • partition (if it was not present in the input)
  • error_code (if something goes wrong on produce. See kafka protocol error code for context)

Summary

Functions

t()

Utility function to verify if all records in a produce_batch/3 were successfully written.

Same as verify_batch/1 but raises if any record fails and do not return ok/error tuple.

Types

@type t() :: %Klife.Record{
  __batch_index: term(),
  __estimated_size: term(),
  error_code: integer(),
  headers: [%{key: binary(), value: binary()}],
  key: binary(),
  offset: non_neg_integer(),
  partition: non_neg_integer(),
  topic: String.t(),
  value: binary()
}

Functions

Link to this function

verify_batch(produce_resps)

View Source

Utility function to verify if all records in a produce_batch/3 were successfully written.

Examples

iex> rec1 = %Klife.Record{value: "my_val_1", topic: "my_topic_1"}
iex> rec2 = %Klife.Record{value: "my_val_2", topic: "my_topic_2"}
iex> rec3 = %Klife.Record{value: "my_val_3", topic: "my_topic_3"}
iex> input = [rec1, rec2, rec3]
iex> {:ok, [_r1, _r2, _r3]} = MyClient.produce_batch(input) |> Klife.Record.verify_batch()

Partial error example. Notice that records 1 and 3 were successfully produced but only record 2 returns from this function.

iex> rec1 = %Klife.Record{value: "my_val_1", topic: "my_topic_1"}
iex> rec2 = %Klife.Record{value: :rand.bytes(2_000_000), topic: "my_topic_2"}
iex> rec3 = %Klife.Record{value: "my_val_3", topic: "my_topic_3"}
iex> input = [rec1, rec2, rec3]
iex> {:error, [%Klife.Record{error_code: 10}]} = MyClient.produce_batch(input) |> Klife.Record.verify_batch()
Link to this function

verify_batch!(produce_resps)

View Source

Same as verify_batch/1 but raises if any record fails and do not return ok/error tuple.

Examples

  iex> rec1 = %Klife.Record{value: "my_val_1", topic: "my_topic_1"}
  iex> rec2 = %Klife.Record{value: "my_val_2", topic: "my_topic_2"}
  iex> rec3 = %Klife.Record{value: "my_val_3", topic: "my_topic_3"}
  iex> input = [rec1, rec2, rec3]
  iex> [_r1, _r2, _r3] = MyClient.produce_batch(input) |> Klife.Record.verify_batch!()