View Source KafkaEx.Protocol.Kayrock.Produce.ResponseHelpers (kafka_ex v1.0.0-rc.1)
Shared utility functions for parsing Produce responses.
These are low-level utilities used by the version-specific response implementations. Each version implementation handles its own field extraction logic directly.
Summary
Functions
Builds a RecordMetadata struct from parsed response data.
Checks if the partition response has an error and returns the appropriate result.
Builds an error response for empty responses.
Extracts the first topic and partition response from a Produce response.
Common parsing logic for produce responses.
Functions
@spec build_record_metadata(Keyword.t()) :: KafkaEx.Messages.RecordMetadata.t()
Builds a RecordMetadata struct from parsed response data.
@spec check_error(String.t(), map()) :: {:ok, map()} | {:error, KafkaEx.Client.Error.t()}
Checks if the partition response has an error and returns the appropriate result.
Returns {:ok, partition_response} if no error, {:error, Error.t()} otherwise.
@spec empty_response_error() :: {:error, KafkaEx.Client.Error.t()}
Builds an error response for empty responses.
@spec extract_first_partition_response(map()) :: {:ok, String.t(), map()} | {:error, :empty_response}
Extracts the first topic and partition response from a Produce response.
Returns {:ok, topic, partition_response} or {:error, :empty_response}.
@spec parse_response(map(), (map(), map() -> Keyword.t())) :: {:ok, KafkaEx.Messages.RecordMetadata.t()} | {:error, KafkaEx.Client.Error.t()}
Common parsing logic for produce responses.
Extracts the first partition response, checks for errors, and builds the RecordMetadata using the provided field extractor function.
The field_extractor function receives {response, partition_resp} and
should return keyword options for build_record_metadata/1.