module Kafka::Protocol

The protocol layer of the library.

The Kafka protocol (kafka.apache.org/protocol) defines a set of API requests, each with a well-known numeric API key, as well as a set of error codes with specific meanings.

This module, and the classes contained in it, implement the client side of the protocol.

Constants

ADD_OFFSETS_TO_TXN_API
ADD_PARTITIONS_TO_TXN_API
ALTER_CONFIGS_API
APIS

A mapping from numeric API keys to symbolic API names.

API_VERSIONS_API
COORDINATOR_TYPE_GROUP

Coordinator types. Since Kafka 0.11.0, there are types of coordinators: Group and Transaction

COORDINATOR_TYPE_TRANSACTION
CREATE_PARTITIONS_API
CREATE_TOPICS_API
DELETE_TOPICS_API
DESCRIBE_CONFIGS_API
DESCRIBE_GROUPS_API
END_TXN_API
ERRORS

A mapping from numeric error codes to exception classes.

FETCH_API
FIND_COORDINATOR_API
HEARTBEAT_API
INIT_PRODUCER_ID_API
JOIN_GROUP_API
LEAVE_GROUP_API
LIST_GROUPS_API
LIST_OFFSET_API
OFFSET_COMMIT_API
OFFSET_FETCH_API
PRODUCE_API
REPLICA_ID

The replica id of non-brokers is always -1.

RESOURCE_TYPES
RESOURCE_TYPE_ANY
RESOURCE_TYPE_CLUSTER
RESOURCE_TYPE_DELEGATION_TOKEN
RESOURCE_TYPE_GROUP
RESOURCE_TYPE_TOPIC
RESOURCE_TYPE_TRANSACTIONAL_ID
RESOURCE_TYPE_UNKNOWN

A mapping from int to corresponding resource type in symbol. github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/resource/ResourceType.java

SASL_HANDSHAKE_API
SYNC_GROUP_API
TOPIC_METADATA_API
TXN_OFFSET_COMMIT_API

Public Class Methods

api_name(api_key) click to toggle source

Returns the symbolic name for an API key.

@param api_key Integer @return [Symbol]

# File lib/kafka/protocol.rb, line 170
def self.api_name(api_key)
  APIS.fetch(api_key, :unknown)
end
handle_error(error_code, error_message = nil) click to toggle source

Handles an error code by either doing nothing (if there was no error) or by raising an appropriate exception.

@param error_code Integer @raise [ProtocolError] @return [nil]

# File lib/kafka/protocol.rb, line 156
def self.handle_error(error_code, error_message = nil)
  if error_code == 0
    # No errors, yay!
  elsif error = ERRORS[error_code]
    raise error, error_message
  else
    raise UnknownError, "Unknown error with code #{error_code} #{error_message}"
  end
end