class GlassOctopus::Configuration

Configuration for the application.

@!attribute [r] connection_adapter

The configured connection adapter.
@see #adapter

@!attribute [rw] logger

A standard library compatible logger for the application. By default it
logs to the STDOUT.

Attributes

connection_adapter[R]
logger[RW]

Public Class Methods

new() click to toggle source
# File lib/glass_octopus/configuration.rb, line 16
def initialize
  self.logger = Logger.new(STDOUT).tap { |l| l.level = Logger::INFO }
end

Public Instance Methods

adapter(type, &block) click to toggle source

Configures a new adapter.

When a class is passed as type the class will be instantiated.

@example Using a custom adapter class

config.adapter(MyAdapter) do |c|
  c.bootstrap_servers = %w[localhost:9092]
  c.group_id = "mygroup"
  c.topic = "mytopic"
end

class MyAdapter
  def initialize
    @options = OpenStruct.new
    yield @options
  end

  def fetch_message
    @consumer.each do |fetched_message|
      message = Message.new(
        fetched_message.topic,
       fetched_message.partition,
       fetched_message.offset,
       fetched_message.key,
       fetched_message.value
     )

      yield message
    end
  end

  def connect
    # Connect to Kafka...
    @consumer = ...
    self
  end

  def close
    @consumer.close
  end
end

@param type [:ruby_kafka, Class] type of the adapter to use @yield a block to conigure the adapter @yieldparam config configuration object

@see RubyKafkaAdapter

# File lib/glass_octopus/configuration.rb, line 67
def adapter(type, &block)
  @connection_adapter = build_adapter(type, &block)
end
build_adapter(type, &block) click to toggle source

@api private

# File lib/glass_octopus/configuration.rb, line 72
def build_adapter(type, &block)
  case type
  when :ruby_kafka
    require "glass_octopus/connection/ruby_kafka_adapter"
    RubyKafkaAdapter.new(logger, &block)
  when Class
    type.new(&block)
  else
    raise ArgumentError, "Unknown adapter: #{type}"
  end
end