Class: KafkaEventHub::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka_event_hub/config.rb

Direct Known Subclasses

Producer

Constant Summary collapse

POLL_TIMEOUT =
ENV.fetch('KAFKA_POLL_TIMEOUT', 100).to_i

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kafka_event_hub/config.rb', line 8

def initialize(options = {})
  @topic = options['topic'] || ENV.fetch('DEFAULT_TOPIC', 'default')
  settings = {
    "bootstrap.servers" => ENV.fetch('EVENT_HUB_NAMESPACE'),
    "security.protocol"  => "SASL_SSL",
    "sasl.mechanism"     => "PLAIN",
    "sasl.username"      => "$ConnectionString",
    "sasl.password"      => ENV.fetch('EVENT_HUB_URL'),
    "client.id"          => ENV.fetch('APP_NAME'),
  }
  settings["group.id"] = "$#{ENV['EVENT_HUB_CONSUMER_GROUP']}" if options['consumer']
  @kafka = Rdkafka::Config.new(settings)
end

Instance Method Details

#consumerObject

Returns an Rdkafka Consumer



28
29
30
# File 'lib/kafka_event_hub/config.rb', line 28

def consumer
  @kafka.consumer
end

#producerObject

Returns an Rdkafka Producer



23
24
25
# File 'lib/kafka_event_hub/config.rb', line 23

def producer
  @kafka.producer
end

#topicObject

The default topic to use



33
34
35
# File 'lib/kafka_event_hub/config.rb', line 33

def topic
  @topic
end