Class: Fluent::ZmqSubInput
- Inherits:
-
Input
- Object
- Input
- Fluent::ZmqSubInput
- Defined in:
- lib/fluent/plugin/in_zmq_sub.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.
14 15 16 17 |
# File 'lib/fluent/plugin/in_zmq_sub.rb', line 14 def initialize super require 'ffi-rzmq' end |
Instance Attribute Details
#subkeys ⇒ Object (readonly)
Returns the value of attribute subkeys.
12 13 14 |
# File 'lib/fluent/plugin/in_zmq_sub.rb', line 12 def subkeys @subkeys end |
Instance Method Details
#configure(conf) ⇒ Object
19 20 21 22 |
# File 'lib/fluent/plugin/in_zmq_sub.rb', line 19 def configure(conf) super @subkeys = @subkey.split(",") end |
#run ⇒ Object
37 38 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_zmq_sub.rb', line 37 def run begin @subscriber = @context.socket(ZMQ::SUB) @subscriber.connect(@publisher) 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 (key, records) = msg.split(" ",2) records = MessagePack.unpack(records) if @bulk_send && records[0].class == Array es = MultiEventStream.new prev_tag = nil records.each do |tag, time, record| if prev_tag && prev_tag != tag Engine.emit_stream(prev_tag, es) es = MultiEventStream.new end es.add(time, record) prev_tag = tag end Engine.emit_stream(prev_tag, es) if es.to_a.size > 0 else Engine.emit(*records) end 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
30 31 32 33 34 35 |
# File 'lib/fluent/plugin/in_zmq_sub.rb', line 30 def shutdown Thread.kill(@thread) @thread.join @context.terminate super end |
#start ⇒ Object
24 25 26 27 28 |
# File 'lib/fluent/plugin/in_zmq_sub.rb', line 24 def start super @context =ZMQ::Context.new() @thread = Thread.new(&method(:run)) end |