Class: Fluent::ZmqSubInput
- Inherits:
-
Input
- Object
- Input
- Fluent::ZmqSubInput
- Defined in:
- lib/fluent/plugin/in_fedmsg.rb
Instance Attribute Summary collapse
-
#subkeys ⇒ Object
readonly
Returns the value of attribute subkeys.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ ZmqSubInput
constructor
A new instance of ZmqSubInput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ ZmqSubInput
Returns a new instance of ZmqSubInput.
15 16 17 18 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 15 def initialize super require 'ffi-rzmq' end |
Instance Attribute Details
#subkeys ⇒ Object (readonly)
Returns the value of attribute subkeys.
13 14 15 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 13 def subkeys @subkeys end |
Instance Method Details
#configure(conf) ⇒ Object
20 21 22 23 24 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 20 def configure(conf) super @subkeys = @subkey.split(",") @drop_fields_arr = @drop_fields.split(",") end |
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 39 def run begin @subscriber = @context.socket(ZMQ::SUB) @subscriber.connect(@publisher) @subscriber.setsockopt(ZMQ::SNDHWM, 100) @subscriber.setsockopt(ZMQ::RCVHWM, 100) if @subkeys.size > 0 @subkeys.each do |k| @subscriber.setsockopt(ZMQ::SUBSCRIBE,k) end else @subscriber.setsockopt(ZMQ::SUBSCRIBE,'') end loop do msg = '' while @subscriber.recv_string(msg,ZMQ::DONTWAIT) && msg.size > 0 begin record = JSON.parse(msg) rescue JSON::ParserError => e log.trace "Ignoring non-JSON message '#{msg}'" next rescue => e log.warn "Unknown error parsing JSON message.",:error_class => e.class, :error => e log.warn_backtrace end begin tag = @tag_prefix + "." + record['topic'] time = record['timestamp'] record.delete_if { |key, value| @drop_fields_arr.include? key} Engine.emit(tag, time, record) rescue => e log.warn "Error in processing message.",:error_class => e.class, :error => e log.warn_backtrace end msg = '' end sleep(0.1) end rescue => e log.error "error occurred while executing plugin.", :error_class => e.class, :error => e log.warn_backtrace ensure if @subscriber @subscriber.close end end end |
#shutdown ⇒ Object
32 33 34 35 36 37 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 32 def shutdown Thread.kill(@thread) @thread.join @context.terminate super end |
#start ⇒ Object
26 27 28 29 30 |
# File 'lib/fluent/plugin/in_fedmsg.rb', line 26 def start super @context =ZMQ::Context.new() @thread = Thread.new(&method(:run)) end |