class FFWD::Plugin::Kafka::AttributeRouter

Use a custom attribute for partitioning.

Constants

DEFAULT_ATTRIBUTE
DEFAULT_EVENT_PATTERN
DEFAULT_METRIC_PATTERN
OPTIONS

Public Class Methods

build(config) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 56
def self.build config
  metric_pattern = config[:metric_pattern] || DEFAULT_METRIC_PATTERN
  event_pattern = config[:event_pattern] || DEFAULT_EVENT_PATTERN
  attr = config[:attribute] || DEFAULT_ATTRIBUTE
  new(metric_pattern, event_pattern, attr)
end
new(config) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 63
def initialize config
  @metric_pattern = config[:metric_pattern]
  @event_pattern = config[:event_pattern]
  @attr = config[:attribute]
  @attr_s = @attr.to_s
end
prepare(config) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 49
def self.prepare config
  config[:metric_pattern] ||= DEFAULT_METRIC_PATTERN
  config[:event_pattern] ||= DEFAULT_EVENT_PATTERN
  config[:attribute] ||= DEFAULT_ATTRIBUTE
  config
end

Public Instance Methods

route_event(e) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 78
def route_event e
  return nil unless v = value(e)
  @event_pattern % [v]
end
route_metric(m) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 83
def route_metric m
  return nil unless v = value(m)
  @metric_pattern % [v]
end
value(d) click to toggle source
# File lib/ffwd/plugin/kafka/routers.rb, line 70
def value d
  if v = d.attributes[@attr]
    return v
  end

  d.attributes[@attr_s]
end