Class: ROM::Kafka::Brokers

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/kafka/brokers.rb,
lib/rom/kafka/brokers/broker.rb

Overview

Value object describing a collection of brokers (host:port)

Knows how to extract brokers from address lines and options

Examples:

brokers = Brokers.new(
  "localhost:9092",
  "127.0.0.1",
  hosts: ["127.0.0.2:9094"],
  port: 9093,
  unknown_key: :foo # will be ignored by the initializer
)

brokers.to_a
# => ["localhost:9092", "127.0.0.2:9093", "127.0.0.3:9094"]

Author:

Defined Under Namespace

Classes: Broker

Instance Method Summary collapse

Constructor Details

#initialize(lines, options) ⇒ Brokers

Initializes an immutable collection from address lines and/or options

The initializer is options-tolerant: it just ignores unknown options.

Parameters:

  • lines (#to_s, Array<#to_s>)
  • options (Hash)

Options Hash (options):

  • :hosts (#to_s, Array<#to_s>)
  • :port (#to_i)


36
37
38
39
# File 'lib/rom/kafka/brokers.rb', line 36

def initialize(*lines) # @todo: refactor using factories
  hosts, port = extract_hosts_and_port(lines)
  @brokers    = extract_brokers(hosts, port)
end

Instance Method Details

#to_aArray<String>

Returns array of string representations of brokers

Returns:

  • (Array<String>)


45
46
47
# File 'lib/rom/kafka/brokers.rb', line 45

def to_a
  @brokers.map(&:to_s)
end