Class: Tracker::KafkaTracker

Inherits:
Base
  • Object
show all
Defined in:
lib/liquid/tracker/kafka_tracker.rb

Instance Attribute Summary

Attributes inherited from Base

#dimensions

Instance Method Summary collapse

Methods inherited from Base

#with_topic

Constructor Details

#initialize(properties, dimensions = {}) ⇒ KafkaTracker

Returns a new instance of KafkaTracker.



10
11
12
13
# File 'lib/liquid/tracker/kafka_tracker.rb', line 10

def initialize(properties, dimensions = {})
  super(dimensions)
  @producer = Producer.new(ProducerConfig.new(properties))
end

Instance Method Details

#down?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/liquid/tracker/kafka_tracker.rb', line 15

def down?
  # TODO: async is fire and forget. we might want to handle
  # QueueFullExceptions later
  false
end

#event(topic, data) ⇒ Object



21
22
23
24
25
26
# File 'lib/liquid/tracker/kafka_tracker.rb', line 21

def event(topic, data)
  @producer.send(KeyedMessage.new(topic, data))
rescue => e
  # TODO: maybe fall back to FileTracker here
  $log.exception(e, "failed to log #{topic}=#{data.inspect}")
end

#shutdownObject



28
29
30
31
32
# File 'lib/liquid/tracker/kafka_tracker.rb', line 28

def shutdown
  @producer.close if @producer
rescue Java::KafkaProducer::ProducerClosedException
  # pass
end