class Fluent::Plugin::MysqlReplicatorSolrOutput

Constants

DEFAULT_BUFFER_TYPE
DEFAULT_TAG_FORMAT

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 22
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 26
def configure(conf)
  super

  if @tag_format.nil? || @tag_format == DEFAULT_TAG_FORMAT
    @tag_format = DEFAULT_TAG_FORMAT
  else
    @tag_format = Regexp.new(conf['tag_format'])
  end
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 40
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
formatted_to_msgpack_binary?() click to toggle source
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 52
def formatted_to_msgpack_binary?
  true
end
multi_workers_ready?() click to toggle source
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 48
def multi_workers_ready?
  true
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 44
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 36
def start
  super
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_mysql_replicator_solr.rb, line 56
def write(chunk)
  solr_connection = {}

  chunk.msgpack_each do |tag, time, record|
    tag_parts = tag.match(@tag_format)
    id_key = tag_parts['primary_key']
    core_name = tag_parts['core_name'].nil? ? '' : tag_parts['core_name']
    url = "http://#{@host}:#{@port}/solr/#{URI.escape(core_name)}"
    solr_connection[url] = RSolr.connect(:url => url) if solr_connection[url].nil?
    if tag_parts['event'] == 'delete'
      solr_connection[url].delete_by_id record[id_key]
    else
      message = Hash[record.map{ |k, v| [k.to_sym, v] }]
      message[:id] = record[id_key] if id_key && record[id_key]
      solr_connection[url].add message
    end
  end
  solr_connection.each {|solr| solr.commit }
end