Class: Fluent::AmqpOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::AmqpOutput
- Defined in:
- lib/fluent/plugin/out_amqp.rb
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ AmqpOutput
constructor
A new instance of AmqpOutput.
-
#shutdown ⇒ Object
This method is called when shutting down.
-
#start ⇒ Object
This method is called when starting.
-
#write(chunk) ⇒ Object
This method is called every flush interval.
Constructor Details
#initialize ⇒ AmqpOutput
Returns a new instance of AmqpOutput.
20 21 22 23 24 |
# File 'lib/fluent/plugin/out_amqp.rb', line 20 def initialize(*) super require "bunny" require "yajl" end |
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting. ‘conf’ is a Hash that includes configuration parameters. If the configuration is invalid, raise Fluent::ConfigError.
29 30 31 32 33 34 35 36 |
# File 'lib/fluent/plugin/out_amqp.rb', line 29 def configure(conf) super raise Fluent::ConfigError, "missing host infromation" unless @host raise Fluent::ConfigError, "missing exchange" unless @exchange @exchange_name = @exchange end |
#format(tag, time, record) ⇒ Object
58 59 60 |
# File 'lib/fluent/plugin/out_amqp.rb', line 58 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
This method is called when shutting down. Shutdown the thread and close sockets or files here.
53 54 55 56 |
# File 'lib/fluent/plugin/out_amqp.rb', line 53 def shutdown super @amqp_conn && @amqp_conn.stop end |
#start ⇒ Object
This method is called when starting. Open sockets or files here.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fluent/plugin/out_amqp.rb', line 40 def start super begin get_or_create_exchange rescue => e $log.error "AMQP error", error: e.to_s $log.warn_backtrace e.backtrace end end |
#write(chunk) ⇒ Object
This method is called every flush interval. Write the buffer chunk to files or databases here. ‘chunk’ is a buffer chunk that includes multiple formatted events. You can use ‘data = chunk.read’ to get all events and ‘chunk.open {|io| … }’ to get IO objects.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fluent/plugin/out_amqp.rb', line 67 def write(chunk) chunk.msgpack_each do |(tag, time, record)| event = @payload_only ? record : { "key" => tag, "timestamp" => time, "payload" => record } = { routing_key: tag, content_type: @content_type } if @priority [:priority] = @priority end get_or_create_exchange.publish Yajl.dump(event), end end |