Class: Fluent::ZmqPubOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::ZmqPubOutput
- Defined in:
- lib/fluent/plugin/out_zmq_pub.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ ZmqPubOutput
constructor
A new instance of ZmqPubOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ ZmqPubOutput
Returns a new instance of ZmqPubOutput.
13 14 15 16 17 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 13 def initialize super require 'ffi-rzmq' @mutex = Mutex.new end |
Instance Method Details
#configure(conf) ⇒ Object
19 20 21 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 19 def configure(conf) super end |
#format(tag, time, record) ⇒ Object
31 32 33 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 31 def format(tag, time, record) [tag,time,record].to_msgpack end |
#shutdown ⇒ Object
66 67 68 69 70 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 66 def shutdown @publisher.close @context.terminate super end |
#start ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 23 def start super @context = ZMQ::Context.new() @publisher = @context.socket(ZMQ::PUB) @publisher.setsockopt(ZMQ::SNDHWM, @highwatermark) @publisher.bind(@bindaddr) end |
#write(chunk) ⇒ Object
35 36 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 |
# File 'lib/fluent/plugin/out_zmq_pub.rb', line 35 def write(chunk) records = { } # to_msgpack in format, unpack in write, then to_msgpack again... better way? chunk.msgpack_each{ |record| pubkey_replaced = @pubkey.gsub(/\${(.*?)}/){ |s| case $1 when 'tag' record[0] else record[2][$1] end } if @bulk_send records[pubkey_replaced] ||= [] records[pubkey_replaced] << record else @mutex.synchronize { @publisher.send_string(pubkey_replaced + " " + record.to_msgpack,ZMQ::DONTWAIT) } end } if @bulk_send @mutex.synchronize { records.each{ |k,v| @publisher.send_string(k + " " + v.to_msgpack,ZMQ::DONTWAIT) } } end end |