Class: Fluent::Plugin::MysqlReplicatorSolrOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_mysql_replicator_solr.rb

Constant Summary collapse

DEFAULT_BUFFER_TYPE =
"memory"
DEFAULT_TAG_FORMAT =
/(?<core_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$/

Instance Method Summary collapse

Constructor Details

#initializeMysqlReplicatorSolrOutput

Returns a new instance of MysqlReplicatorSolrOutput.



22
23
24
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 22

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



26
27
28
29
30
31
32
33
34
# 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) ⇒ Object



40
41
42
# 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?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 52

def formatted_to_msgpack_binary?
  true
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 48

def multi_workers_ready?
  true
end

#shutdownObject



44
45
46
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 44

def shutdown
  super
end

#startObject



36
37
38
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 36

def start
  super
end

#write(chunk) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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