fluent-plugin-amqp 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fluent/plugin/in_amqp.rb +25 -2
- data/lib/fluent/plugin/out_amqp.rb +28 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eef8bc33986f21193cd21ba5c24fc4dbee37acf6
|
4
|
+
data.tar.gz: 64e2b306228f5e9c0bb01c02f8e6c69bd116b3e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82b65b1bb57b83f7ed42e87a6d1ce09c9677899f7bf0f8e16788ec95da5127f60361825dfe1210f7b0c16f083e4c3c49c6d2588cd23223c2cd178d6bfa2f64c0
|
7
|
+
data.tar.gz: f90d37341d01a3e9ec2de90b44f1c916e89d981ca09ebfc7dbbf9a4c8ea72618a2d9ad65794de90e47dd93e5e4735a44c24d84f391bb3986c25871ad18a32f90
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
module Fluent
|
2
4
|
class AMQPInput < Input
|
3
5
|
Fluent::Plugin.register_input('amqp', self)
|
@@ -23,6 +25,9 @@ module Fluent
|
|
23
25
|
config_param :auto_delete, :bool, :default => false
|
24
26
|
config_param :passive, :bool, :default => false
|
25
27
|
config_param :payload_format, :string, :default => "json"
|
28
|
+
config_param :tag_key, :bool, :default => false
|
29
|
+
config_param :tag_header, :string, :default => nil
|
30
|
+
config_param :time_header, :string, :default => nil
|
26
31
|
|
27
32
|
def initialize
|
28
33
|
require 'bunny'
|
@@ -63,9 +68,9 @@ module Fluent
|
|
63
68
|
@bunny.start
|
64
69
|
q = @bunny.queue(@queue, :passive => @passive, :durable => @durable,
|
65
70
|
:exclusive => @exclusive, :auto_delete => @auto_delete)
|
66
|
-
q.subscribe do |
|
71
|
+
q.subscribe do |delivery, meta, msg|
|
67
72
|
payload = parse_payload(msg)
|
68
|
-
router.emit(
|
73
|
+
router.emit(parse_tag(delivery, meta), parse_time(meta), payload)
|
69
74
|
end
|
70
75
|
end # AMQPInput#run
|
71
76
|
|
@@ -86,6 +91,24 @@ module Fluent
|
|
86
91
|
{ "message" => msg }
|
87
92
|
end
|
88
93
|
end
|
94
|
+
|
95
|
+
def parse_tag( delivery, meta )
|
96
|
+
if @tag_key && delivery.routing_key != ''
|
97
|
+
delivery.routing_key
|
98
|
+
elsif @tag_header && meta[:headers][@tag_header]
|
99
|
+
meta[:headers][@tag_header]
|
100
|
+
else
|
101
|
+
@tag
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_time( meta )
|
106
|
+
if @time_header && meta[:headers][@time_header]
|
107
|
+
Time.parse( meta[:headers][@time_header] ).to_i
|
108
|
+
else
|
109
|
+
Time.new.to_i
|
110
|
+
end
|
111
|
+
end
|
89
112
|
end # class AMQPInput
|
90
113
|
|
91
114
|
end # module Fluent
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
module Fluent
|
2
3
|
class AMQPOutput < BufferedOutput
|
3
4
|
Plugin.register_output("amqp", self)
|
@@ -16,6 +17,9 @@ module Fluent
|
|
16
17
|
config_param :auto_delete, :bool, :default => false
|
17
18
|
config_param :key, :string, :default => nil
|
18
19
|
config_param :persistent, :bool, :default => false
|
20
|
+
config_param :tag_key, :bool, :default => false
|
21
|
+
config_param :tag_header, :string, :default => nil
|
22
|
+
config_param :time_header, :string, :default => nil
|
19
23
|
|
20
24
|
def initialize
|
21
25
|
super
|
@@ -25,8 +29,11 @@ module Fluent
|
|
25
29
|
def configure(conf)
|
26
30
|
super
|
27
31
|
@conf = conf
|
28
|
-
unless @host && @exchange
|
29
|
-
raise ConfigError, "'host'
|
32
|
+
unless @host && @exchange
|
33
|
+
raise ConfigError, "'host' and 'exchange' must be all specified."
|
34
|
+
end
|
35
|
+
unless @key || @tag_key
|
36
|
+
raise ConfigError, "Either 'key' or 'tag_key' must be set."
|
30
37
|
end
|
31
38
|
@bunny = Bunny.new(:host => @host, :port => @port, :vhost => @vhost,
|
32
39
|
:pass => @pass, :user => @user, :ssl => @ssl, :verify_ssl => @verify_ssl)
|
@@ -46,12 +53,28 @@ module Fluent
|
|
46
53
|
end
|
47
54
|
|
48
55
|
def format(tag, time, record)
|
49
|
-
record.to_msgpack
|
56
|
+
[tag, time, record].to_msgpack
|
50
57
|
end
|
51
58
|
|
52
59
|
def write(chunk)
|
53
|
-
chunk.msgpack_each do |data|
|
54
|
-
|
60
|
+
chunk.msgpack_each do |(tag, time, data)|
|
61
|
+
data = JSON.dump( data ) unless data.is_a?( String )
|
62
|
+
@exch.publish(data, :key => routing_key( tag ), :persistent => @persistent, :headers => headers( tag, time ))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def routing_key( tag )
|
67
|
+
if @tag_key
|
68
|
+
tag
|
69
|
+
else
|
70
|
+
@key
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def headers( tag, time )
|
75
|
+
{}.tap do |h|
|
76
|
+
h[@tag_header] = tag if @tag_header
|
77
|
+
h[@time_header] = Time.at(time).utc.to_s if @time_header
|
55
78
|
end
|
56
79
|
end
|
57
80
|
|