This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
out_amqp.rb
57 lines (49 loc) · 1.62 KB
/
out_amqp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Fluent
class AMQPOutput < BufferedOutput
Plugin.register_output("amqp", self)
config_param :host, :string, :default => nil
config_param :user, :string, :default => "guest"
config_param :pass, :string, :default => "guest"
config_param :vhost, :string, :default => "/"
config_param :port, :integer, :default => 5672
config_param :exchange, :string, :default => ""
config_param :exchange_type, :string, :default => "direct"
config_param :passive, :bool, :default => false
config_param :durable, :bool, :default => false
config_param :auto_delete, :bool, :default => false
config_param :key, :string, :default => nil
config_param :persistent, :bool, :default => false
def initialize
super
require "bunny"
end
def configure(conf)
super
@conf = conf
unless @host && @exchange && @key
raise ConfigError, "'host', 'exchange' and 'key' must be all specified."
end
@bunny = Bunny.new(:host => @host, :port => @port, :vhost => @vhost,
:pass => @pass, :user => @user)
end
def start
super
@bunny.start
@exch = @bunny.exchange(@exchange, :type => @exchange_type.intern,
:passive => @passive, :durable => @durable,
:auto_delete => @auto_delete)
end
def shutdown
super
@bunny.stop
end
def format(tag, time, record)
record.to_msgpack
end
def write(chunk)
chunk.msgpack_each do |data|
@exch.publish(data, :key => @key, :persistent => @persistent)
end
end
end
end