View Source KafkaEx.Messages.Header (kafka_ex v1.0.0-rc.1)
Kafka message header (key-value pair).
Headers were introduced in Kafka 0.11 (Produce API V3+) and allow attaching additional metadata to messages without modifying the message payload. Common uses include tracing information, content types, and routing metadata.
Java equivalent: org.apache.kafka.common.header.Header
Summary
Functions
Builds a Header from keyword options.
Creates a Header from a tuple {key, value}.
Returns the header key.
Converts a list of tuples to Headers.
Converts a list of Headers to tuple format.
Creates a new Header with the given key and value.
Converts the Header to a tuple {key, value}.
Returns the header value.
Types
Functions
Builds a Header from keyword options.
Options
:key- (required) The header key:value- (required) The header value
Examples
iex> Header.build(key: "x-custom", value: "data")
%Header{key: "x-custom", value: "data"}
Creates a Header from a tuple {key, value}.
This is useful for converting from the common tuple format used in many APIs.
Examples
iex> Header.from_tuple({"content-type", "text/plain"})
%Header{key: "content-type", value: "text/plain"}
Returns the header key.
This is provided for API compatibility with Java's Header.key().
Converts a list of tuples to Headers.
Examples
iex> tuples = [{"a", "1"}, {"b", "2"}]
iex> Header.list_from_tuples(tuples)
[%Header{key: "a", value: "1"}, %Header{key: "b", value: "2"}]
Converts a list of Headers to tuple format.
Examples
iex> headers = [Header.new("a", "1"), Header.new("b", "2")]
iex> Header.list_to_tuples(headers)
[{"a", "1"}, {"b", "2"}]
Creates a new Header with the given key and value.
Parameters
key- The header key (must be a string)value- The header value (binary data)
Examples
iex> Header.new("content-type", "application/json")
%Header{key: "content-type", value: "application/json"}
iex> Header.new("trace-id", <<1, 2, 3>>)
%Header{key: "trace-id", value: <<1, 2, 3>>}
Converts the Header to a tuple {key, value}.
This is useful for interoperability with APIs that expect tuple format.
Examples
iex> header = Header.new("x-custom", "value")
iex> Header.to_tuple(header)
{"x-custom", "value"}
Returns the header value.
This is provided for API compatibility with Java's Header.value().