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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e5ef78a2bf85bbc437eb8df64cdb638c0337044
4
- data.tar.gz: ee1114cb9e1da07cf4273cc4725fbdba30077f02
3
+ metadata.gz: eef8bc33986f21193cd21ba5c24fc4dbee37acf6
4
+ data.tar.gz: 64e2b306228f5e9c0bb01c02f8e6c69bd116b3e9
5
5
  SHA512:
6
- metadata.gz: de068f84be516289eb63ad457fd3b79694362638930821274f6aed006f5ccdbc989f549792d0c4c8ab2a867d2dec5149fd80cba276e7af32dac660e03e275b33
7
- data.tar.gz: 90c7ea3f6cb02d9690f426d2f1c81d09d9bb49f1374dc530addc279578f5720d4eed43fcc5ea6495fb243ac52c550164218180842d794b056d09ebe2612bbf1e
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 |_, _, msg|
71
+ q.subscribe do |delivery, meta, msg|
67
72
  payload = parse_payload(msg)
68
- router.emit(@tag, Time.new.to_i, payload)
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 && @key
29
- raise ConfigError, "'host', 'exchange' and 'key' must be all specified."
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
- @exch.publish(data, :key => @key, :persistent => @persistent)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiromi Ishii