fluent-plugin-rabbitmq-typed 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 81153af2837d8a7d043daf68644be2fc878c082cbaddffadac5de43d2d623ae3
4
+ data.tar.gz: 6f7180eed8a343e396241567d2b9f2a54bcca8b1dd94edbf8246f1172f80bcbc
5
+ SHA512:
6
+ metadata.gz: 684d3bd150e4171d696800b248d3fd7df14777629a7f6931c63f18d3957da5d4205cf09e281326869d3c19cae2a107c58219a7984aa8547ac274da0d2a4f6bf3
7
+ data.tar.gz: 75ffc7873f54872f62a06432a3b865463920a74ffeaf8d36e9ffda2ef8dc8d281471b9fc1c32f9d9abb04519bbb3bde95e4d6b61c0d5d8fd1d59c7b7d9dcd4e4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .gem
11
+ *.gem
12
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ cache: bundler
5
+ dist: xenial
6
+ sudo: true
7
+ services:
8
+ - rabbitmq
9
+ addons:
10
+ apt:
11
+ packages:
12
+ - rabbitmq-server
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2017 NTT Communications
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,176 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # fluent-plugin-rabbitmq
2
+
3
+ [![Build Status](https://travis-ci.org/nttcom/fluent-plugin-rabbitmq.svg?branch=master)](https://travis-ci.org/nttcom/fluent-plugin-rabbitmq)
4
+
5
+ ## Overview
6
+
7
+ This repository includes input/output plugins for RabbitMQ.
8
+
9
+ ## Requirements
10
+
11
+ fluentd >= 0.14.0
12
+
13
+ ## Installation
14
+
15
+ $ fluent-gem install fluent-plugin-rabbitmq
16
+
17
+ ## Configuration
18
+
19
+ ### Input
20
+
21
+ ```
22
+ <source>
23
+ @type rabbitmq
24
+ tag foo
25
+ host 127.0.0.1
26
+ # or hosts ["192.168.1.1", "192.168.1.2"]
27
+ user guest
28
+ pass guest
29
+ vhost /
30
+ exchange foo # not required. if specified, the queue will be bound to the exchange
31
+ queue bar
32
+ routing_key hoge # if not specified, the tag is used
33
+ heartbeat 10 # integer as seconds or :server (interval specified by server)
34
+ <parse>
35
+ @type json # or msgpack, ltsv, none
36
+ </parse>
37
+ </source>
38
+ ```
39
+
40
+ #### Other Configurations for Input
41
+
42
+ |key|example|default value|description|
43
+ |:--|---|---|---|
44
+ |durable|true|false|set durable flag of the queue|
45
+ |exclusive|true|false|set exclusive flag of the queue|
46
+ |auto_delete|true|false|set auto_delete flag of the queue|
47
+ |ttl|60000|nil|queue ttl in ms|
48
+ |prefetch_count|10|nil||
49
+ |consumer_pool_size|5|nil||
50
+ |include_headers|true|false|include headers in events|
51
+ |headers_key|string|header|key name of headers|
52
+ |create_exchange|true|false|create exchange or not|
53
+ |exchange_to_bind|string|nil|exchange to bind created exchange|
54
+ |exchange_type|direct|topic|type of created exchange|
55
+ |exchange_routing_key|hoge|nil|created exchange routing key|
56
+ |exchange_durable|true|false|durability of create exchange|
57
+
58
+ ### Output
59
+
60
+ ```
61
+ <match pattern>
62
+ @type rabbitmq
63
+ host 127.0.0.1
64
+ # or hosts ["192.168.1.1", "192.168.1.2"]
65
+ user guest
66
+ pass guest
67
+ vhost /
68
+ format json # or msgpack, ltsv, none
69
+ exchange foo # required: name of exchange
70
+ exchange_type fanout # required: type of exchange e.g. topic, direct
71
+ exchange_durable false
72
+ routing_key hoge # if not specified, the tag is used
73
+ heartbeat 10 # integer as seconds or :server (interval specified by server)
74
+ <format>
75
+ @type json # or msgpack, ltsv, none
76
+ </format>
77
+ <buffer> # to use in buffered mode
78
+ </buffer>
79
+ </match>
80
+ ```
81
+
82
+ #### Other Configurations for Output
83
+
84
+ |key|example|default value|description|
85
+ |:--|---|---|---|
86
+ |persistent|true|false|messages is persistent to disk|
87
+ |timestamp|true|false|if true, time of record is used as timestamp in AMQP message|
88
+ |content_type|application/json|nil|message content type|
89
+ |frame_max|131072|nil|maximum permissible size of a frame|
90
+ |mandatory||true|nil||
91
+ |expiration|3600|nil|message time-to-live|
92
+ |message_type||nil||
93
+ |priority||nil||
94
+ |app_id||nil||
95
+ |id_key|message_id|nil|id to specify message_id|
96
+
97
+ ### TLS related configurations
98
+
99
+ ```
100
+ tls false # enable TLS or not
101
+ tls_cert /path/to/cert
102
+ tls_key /path/to/key
103
+ tls_ca_certificates ["/path/to/ca_certificate"]
104
+ verify_peer true
105
+ ```
106
+
107
+ ### Other Configurations for Input/Output
108
+
109
+ |key|example|default value|description|
110
+ |:--|---|---|---|
111
+ |automatically_recover|true|nil|automatic network failure recovery|
112
+ |network_recovery_interval|30|nil|interval between reconnection attempts|
113
+ |recovery_attempts|3|nil|limits the number of connection recovery|
114
+ |connection_timeout|30|nil||
115
+ |continuation_timeout|600|nil||
116
+
117
+ ## License
118
+
119
+ The gem is available as open source under the terms of the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt).
120
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << "test"
6
+ test.pattern = "test/**/test_*.rb"
7
+ test.verbose = false
8
+ test.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-rabbitmq-typed"
6
+ spec.version = "0.0.8"
7
+ spec.authors = ["NTT Communications"]
8
+ spec.email = ["masaki.matsushita@ntt.com"]
9
+
10
+ spec.summary = %q{fluent plugin for rabbitmq (AMQP)}
11
+ spec.description = %q{fluent plugin for rabbitmq (AMQP)}
12
+ spec.homepage = "https://github.com/nttcom/fluent-plugin-rabbitmq"
13
+ spec.license = "Apache-2.0"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "test-unit"
21
+ spec.add_development_dependency "ltsv"
22
+ spec.add_development_dependency "msgpack"
23
+
24
+ spec.add_runtime_dependency "fluentd", ">= 0.14.0"
25
+
26
+ spec.add_dependency "bunny", "~> 2.14.4"
27
+ end
@@ -0,0 +1,168 @@
1
+ #
2
+ # fluent-plugin-rabbitmq
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ require "fluent/plugin/input"
18
+
19
+ module Fluent::Plugin
20
+ class RabbitMQInput < Input
21
+ Fluent::Plugin.register_input("rabbitmq", self)
22
+
23
+ helpers :parser, :compat_parameters
24
+
25
+ config_param :tag, :string
26
+
27
+ config_section :parse do
28
+ config_set_default :@type, "json"
29
+ end
30
+
31
+ config_param :host, :string, default: nil
32
+ config_param :hosts, :array, default: nil
33
+ config_param :port, :integer, default: nil
34
+ config_param :user, :string, default: nil
35
+ config_param :pass, :string, default: nil, secret: true
36
+ config_param :vhost, :string, default: nil
37
+
38
+ config_param :routing_key, :string, default: nil
39
+ config_param :connection_timeout, :time, default: nil
40
+ config_param :continuation_timeout, :integer, default: nil
41
+ config_param :automatically_recover, :bool, default: nil
42
+ config_param :network_recovery_interval, :time, default: nil
43
+ config_param :recovery_attempts, :integer, default: nil
44
+ config_param :auth_mechanism, :string, default: nil
45
+ config_param :heartbeat, default: nil do |param|
46
+ param == "server" ? :server : Integer(param)
47
+ end
48
+ config_param :consumer_pool_size, :integer, default: nil
49
+
50
+ config_param :exchange, :string, default: nil
51
+ config_param :create_exchange, :bool, default: false
52
+ config_param :exchange_to_bind, :string, default: nil
53
+ config_param :exchange_type, :string, default: "topic"
54
+ config_param :exchange_routing_key, :string, default: nil
55
+ config_param :exchange_durable, :bool, default: false
56
+
57
+ config_param :tls, :bool, default: false
58
+ config_param :tls_cert, :string, default: nil
59
+ config_param :tls_key, :string, default: nil
60
+ config_param :tls_ca_certificates, :array, default: nil
61
+ config_param :verify_peer, :bool, default: true
62
+
63
+ config_param :queue, :string
64
+ config_param :durable, :bool, default: false
65
+ config_param :exclusive, :bool, default: false
66
+ config_param :auto_delete, :bool, default: false
67
+ config_param :prefetch_count, :integer, default: nil
68
+ config_param :ttl, :integer, default: nil
69
+ config_param :x_type, :string, default: "default"
70
+
71
+ config_param :include_headers, :bool, default: false
72
+ config_param :include_delivery_info, :bool, default: false
73
+ config_param :headers_key, :string, default: "headers"
74
+ config_param :delivery_info_key, :string, default: "delivery_info"
75
+
76
+ def initialize
77
+ super
78
+ require "bunny"
79
+ end
80
+
81
+ def configure(conf)
82
+ compat_parameters_convert(conf, :parser)
83
+
84
+ super
85
+
86
+ bunny_options = {}
87
+ bunny_options[:host] = @host if @host
88
+ bunny_options[:hosts] = @hosts if @hosts
89
+ bunny_options[:port] = @port if @port
90
+ bunny_options[:user] = @user if @user
91
+ bunny_options[:pass] = @pass if @pass
92
+ bunny_options[:vhost] = @vhost if @vhost
93
+ bunny_options[:connection_timeout] = @connection_timeout if @connection_timeout
94
+ bunny_options[:continuation_timeout] = @continuation_timeout if @continuation_timeout
95
+ bunny_options[:automatically_recover] = @automatically_recover if @automatically_recover
96
+ bunny_options[:network_recovery_interval] = @network_recovery_interval if @network_recovery_interval
97
+ bunny_options[:recovery_attempts] = @recovery_attempts
98
+ bunny_options[:auth_mechanism] = @auth_mechanism if @auth_mechanism
99
+ bunny_options[:heartbeat] = @heartbeat if @heartbeat
100
+
101
+ bunny_options[:tls] = @tls
102
+ bunny_options[:tls_cert] = @tls_cert if @tls_cert
103
+ bunny_options[:tls_key] = @tls_key if @tls_key
104
+ bunny_options[:tls_ca_certificates] = @tls_ca_certificates if @tls_ca_certificates
105
+ bunny_options[:verify_peer] = @verify_peer
106
+
107
+ @parser = parser_create
108
+
109
+ @routing_key ||= @tag
110
+ @bunny = Bunny.new(bunny_options)
111
+ end
112
+
113
+ def start
114
+ super
115
+ @bunny.start
116
+ channel = @bunny.create_channel(nil, @consumer_pool_size)
117
+ channel.prefetch(@prefetch_count) if @prefetch_count
118
+ if @create_exchange
119
+ exchange_options = {
120
+ durable: @exchange_durable,
121
+ auto_delete: @auto_delete
122
+ }
123
+ @bunny_exchange = Bunny::Exchange.new(channel, @exchange_type, @exchange, exchange_options)
124
+ if @exchange_to_bind
125
+ @bunny_exchange.bind(@exchange_to_bind, routing_key: @exchange_routing_key)
126
+ end
127
+ end
128
+ queue_arguments = Hash.new
129
+ queue_arguments["x-message-ttl"] = @ttl if @ttl
130
+ queue_arguments["x-queue-type"] = @x_type if @x_type
131
+ queue = channel.queue(
132
+ @queue,
133
+ durable: @durable,
134
+ exclusive: @exclusive,
135
+ auto_delete: @auto_delete,
136
+ arguments: queue_arguments
137
+ )
138
+ if @exchange
139
+ queue.bind(@exchange, routing_key: @routing_key)
140
+ end
141
+ queue.subscribe do |delivery_info, properties, payload|
142
+ @parser.parse(payload) do |time, record|
143
+ time = if properties[:timestamp]
144
+ Fluent::EventTime.from_time(properties[:timestamp])
145
+ else
146
+ time
147
+ end
148
+ if @include_headers
149
+ record[@headers_key] = properties.headers
150
+ end
151
+ if @include_delivery_info
152
+ record[@delivery_info_key] = delivery_info
153
+ end
154
+ router.emit(@tag, time, record)
155
+ end
156
+ end
157
+ end
158
+
159
+ def multi_workers_ready?
160
+ true
161
+ end
162
+
163
+ def shutdown
164
+ @bunny.close
165
+ super
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,172 @@
1
+ #
2
+ # fluent-plugin-rabbitmq
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ require "fluent/plugin/output"
18
+
19
+ module Fluent::Plugin
20
+ class RabbitMQOutput < Output
21
+ Fluent::Plugin.register_output("rabbitmq", self)
22
+
23
+ helpers :formatter, :inject, :compat_parameters
24
+
25
+ config_section :format do
26
+ config_set_default :@type, "json"
27
+ end
28
+
29
+ config_param :host, :string, default: nil
30
+ config_param :hosts, :array, default: nil
31
+ config_param :port, :integer, default: nil
32
+ config_param :user, :string, default: nil
33
+ config_param :pass, :string, default: nil, secret: true
34
+ config_param :vhost, :string, default: nil
35
+ config_param :connection_timeout, :time, default: nil
36
+ config_param :continuation_timeout, :integer, default: nil
37
+ config_param :automatically_recover, :bool, default: nil
38
+ config_param :network_recovery_interval, :time, default: nil
39
+ config_param :recovery_attempts, :integer, default: nil
40
+ config_param :auth_mechanism, :string, default: nil
41
+ config_param :heartbeat, default: nil do |param|
42
+ param == "server" ? :server : Integer(param)
43
+ end
44
+ config_param :threaded, :bool, default: true
45
+ config_param :frame_max, :integer, default: nil
46
+
47
+ config_param :tls, :bool, default: false
48
+ config_param :tls_cert, :string, default: nil
49
+ config_param :tls_key, :string, default: nil
50
+ config_param :tls_ca_certificates, :array, default: nil
51
+ config_param :verify_peer, :bool, default: true
52
+
53
+ config_param :exchange, :string
54
+ config_param :exchange_type, :string
55
+ config_param :exchange_durable, :bool, default: false
56
+
57
+ config_param :persistent, :bool, default: false
58
+ config_param :routing_key, :string, default: nil
59
+ config_param :id_key, :string, default: nil
60
+ config_param :timestamp, :bool, default: false
61
+ config_param :content_type, :string, default: nil
62
+ config_param :content_encoding, :string, default: nil
63
+ config_param :expiration, :integer, default: nil
64
+ config_param :message_type, :integer, default: nil
65
+ config_param :priority, :integer, default: nil
66
+ config_param :app_id, :string, default: nil
67
+
68
+ def initialize
69
+ super
70
+ require "bunny"
71
+ end
72
+
73
+ def configure(conf)
74
+ compat_parameters_convert(conf, :inject, :formatter, default_chunk_key: "time")
75
+
76
+ super
77
+
78
+ bunny_options = {}
79
+ bunny_options[:host] = @host if @host
80
+ bunny_options[:hosts] = @hosts if @hosts
81
+ bunny_options[:port] = @port if @port
82
+ bunny_options[:user] = @user if @user
83
+ bunny_options[:pass] = @pass if @pass
84
+ bunny_options[:vhost] = @vhost if @vhost
85
+ bunny_options[:connection_timeout] = @connection_timeout if @connection_timeout
86
+ bunny_options[:continuation_timeout] = @continuation_timeout if @continuation_timeout
87
+ bunny_options[:automatically_recover] = @automatically_recover if @automatically_recover
88
+ bunny_options[:network_recovery_interval] = @network_recovery_interval if @network_recovery_interval
89
+ bunny_options[:recovery_attempts] = @recovery_attempts
90
+ bunny_options[:auth_mechanism] = @auth_mechanism if @auth_mechanism
91
+ bunny_options[:heartbeat] = @heartbeat if @heartbeat
92
+ bunny_options[:frame_max] = @frame_max if @frame_max
93
+
94
+ bunny_options[:tls] = @tls
95
+ bunny_options[:tls_cert] = @tls_cert if @tls_cert
96
+ bunny_options[:tls_key] = @tls_key if @tls_key
97
+ bunny_options[:tls_ca_certificates] = @tls_ca_certificates if @tls_ca_certificates
98
+ bunny_options[:verify_peer] = @verify_peer
99
+
100
+ @bunny = Bunny.new(bunny_options)
101
+
102
+ @publish_options = {}
103
+ @publish_options[:content_type] = @content_type if @content_type
104
+ @publish_options[:content_encoding] = @content_encoding if @content_encoding
105
+ @publish_options[:persistent] = @persistent if @persistent
106
+ @publish_options[:mandatory] = @mandatory if @mandatory
107
+ @publish_options[:expiration] = @expiration if @expiration
108
+ @publish_options[:message_type] = @message_type if @message_type
109
+ @publish_options[:priority] = @priority if @priority
110
+ @publish_options[:app_id] = @app_id if @app_id
111
+
112
+ @formatter = formatter_create(default_type: @type)
113
+ end
114
+
115
+ def multi_workers_ready?
116
+ true
117
+ end
118
+
119
+ def prefer_buffered_processing
120
+ false
121
+ end
122
+
123
+ def start
124
+ super
125
+ @bunny.start
126
+ @channel = @bunny.create_channel
127
+ exchange_options = {
128
+ durable: @exchange_durable,
129
+ auto_delete: @exchange_auto_delete
130
+ }
131
+ @bunny_exchange = Bunny::Exchange.new(@channel, @exchange_type, @exchange, exchange_options)
132
+ end
133
+
134
+ def shutdown
135
+ @bunny.close
136
+ super
137
+ end
138
+
139
+ def set_publish_options(tag, time, record)
140
+ @publish_options[:timestamp] = time.to_i if @timestamp
141
+
142
+ if @exchange_type != "fanout"
143
+ @publish_options[:routing_key] = @routing_key ? @routing_key : tag
144
+ end
145
+
146
+ if @id_key
147
+ id = record[@id_key]
148
+ @publish_options[:message_id] = id if id
149
+ end
150
+ end
151
+
152
+ def process(tag, es)
153
+ es.each do |time, record|
154
+ set_publish_options(tag, time, record)
155
+ record = inject_values_to_record(tag, time, record)
156
+ buf = @formatter.format(tag, time, record)
157
+ @bunny_exchange.publish(buf, @publish_options)
158
+ end
159
+ end
160
+
161
+ def write(chunk)
162
+ tag = chunk.metadata.tag
163
+
164
+ chunk.each do |time, record|
165
+ set_publish_options(tag, time, record)
166
+ record = inject_values_to_record(tag, time, record)
167
+ buf = @formatter.format(tag, time, record)
168
+ @bunny_exchange.publish(buf, @publish_options)
169
+ end
170
+ end
171
+ end
172
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-rabbitmq-typed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - NTT Communications
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ltsv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: msgpack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fluentd
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.14.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.14.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: bunny
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.14.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.14.4
111
+ description: fluent plugin for rabbitmq (AMQP)
112
+ email:
113
+ - masaki.matsushita@ntt.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - COPYING
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - fluent-plugin-rabbitmq-typed.gemspec
126
+ - lib/fluent/plugin/in_rabbitmq.rb
127
+ - lib/fluent/plugin/out_rabbitmq.rb
128
+ homepage: https://github.com/nttcom/fluent-plugin-rabbitmq
129
+ licenses:
130
+ - Apache-2.0
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: fluent plugin for rabbitmq (AMQP)
151
+ test_files: []