Class: Fluent::MysqlReplicatorSolrOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::MysqlReplicatorSolrOutput
- Defined in:
- lib/fluent/plugin/out_mysql_replicator_solr.rb
Constant Summary collapse
- DEFAULT_TAG_FORMAT =
/(?<core_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$/
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ MysqlReplicatorSolrOutput
constructor
A new instance of MysqlReplicatorSolrOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ MysqlReplicatorSolrOutput
12 13 14 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 12 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 16 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
30 31 32 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 30 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
34 35 36 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 34 def shutdown super end |
#start ⇒ Object
26 27 28 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 26 def start super end |
#write(chunk) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fluent/plugin/out_mysql_replicator_solr.rb', line 38 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/#{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 = Hash[record.map{ |k, v| [k.to_sym, v] }] [:id] = record[id_key] if id_key && record[id_key] solr_connection[url].add end end solr_connection.each {|solr| solr.commit } end |