fluent-plugin-rabbitmq-sklenar 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd868484b45aef9c35582be43241a5c126e43adab4e8bd901d856292b9289d45
4
+ data.tar.gz: b4463680eefb40f177983baae18c2b4e066acef363e3e975404d2fbfae30b737
5
+ SHA512:
6
+ metadata.gz: 871e0635a1da2dff080cc3326cc595d579fc893c60b6cba24b92175663b4986b5eda9f6713df2e4fe927b93510626d7bbe75f8d695d91075e64b39dff34657fe
7
+ data.tar.gz: c32c2edc7c3378b58891035ba9605d98fa1836225352a1d0ed6bf8f3b0d18c15aef18ea2b722afcd98d4c92372a21c299ab72b6e19daa7ed23b50c51bd532fba
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,127 @@
1
+ # fluent-plugin-rabbitmq
2
+
3
+ ## Overview
4
+
5
+ This repository includes input/output plugins for RabbitMQ.
6
+
7
+ ## Requirements
8
+
9
+ fluentd >= 0.14.0
10
+
11
+ ## Installation
12
+
13
+ $ fluent-gem install fluent-plugin-rabbitmq
14
+
15
+ ## Testing
16
+
17
+ $ rabbitmq-server
18
+ $ rake test
19
+
20
+ ## Configuration
21
+
22
+ ### Input
23
+
24
+ ```
25
+ <source>
26
+ @type rabbitmq
27
+ tag foo
28
+ host 127.0.0.1
29
+ # or hosts ["192.168.1.1", "192.168.1.2"]
30
+ user guest
31
+ pass guest
32
+ vhost /
33
+ exchange foo # not required. if specified, the queue will be bound to the exchange
34
+ queue bar
35
+ routing_key hoge # if not specified, the tag is used
36
+ heartbeat 10 # integer as seconds or :server (interval specified by server)
37
+ <parse>
38
+ @type json # or msgpack, ltsv, none
39
+ </parse>
40
+ </source>
41
+ ```
42
+
43
+ #### Other Configurations for Input
44
+
45
+ |key|example|default value|description|
46
+ |:--|---|---|---|
47
+ |durable|true|false|set durable flag of the queue|
48
+ |exclusive|true|false|set exclusive flag of the queue|
49
+ |auto_delete|true|false|set auto_delete flag of the queue|
50
+ |ttl|60000|nil|queue ttl in ms|
51
+ |prefetch_count|10|nil||
52
+ |consumer_pool_size|5|nil||
53
+ |include_headers|true|false|include headers in events|
54
+ |headers_key|string|header|key name of headers|
55
+ |create_exchange|true|false|create exchange or not|
56
+ |exchange_to_bind|string|nil|exchange to bind created exchange|
57
+ |exchange_type|direct|topic|type of created exchange|
58
+ |exchange_routing_key|hoge|nil|created exchange routing key|
59
+ |exchange_durable|true|false|durability of create exchange|
60
+ |manual_ack|true|false|manual ACK|
61
+ |queue_mode|"lazy"|nil|queue mode|
62
+ |queue_type|"quorum"|nil|queue type|
63
+
64
+
65
+ ### Output
66
+
67
+ ```
68
+ <match pattern>
69
+ @type rabbitmq
70
+ host 127.0.0.1
71
+ # or hosts ["192.168.1.1", "192.168.1.2"]
72
+ user guest
73
+ pass guest
74
+ vhost /
75
+ format json # or msgpack, ltsv, none
76
+ exchange foo # required: name of exchange
77
+ exchange_type fanout # required: type of exchange e.g. topic, direct
78
+ exchange_durable false
79
+ routing_key hoge # if not specified, the tag is used
80
+ heartbeat 10 # integer as seconds or :server (interval specified by server)
81
+ <format>
82
+ @type json # or msgpack, ltsv, none
83
+ </format>
84
+ <buffer> # to use in buffered mode
85
+ </buffer>
86
+ </match>
87
+ ```
88
+
89
+ #### Other Configurations for Output
90
+
91
+ |key|example|default value|description|
92
+ |:--|---|---|---|
93
+ |persistent|true|false|messages is persistent to disk|
94
+ |timestamp|true|false|if true, time of record is used as timestamp in AMQP message|
95
+ |content_type|application/json|nil|message content type|
96
+ |frame_max|131072|nil|maximum permissible size of a frame|
97
+ |mandatory||true|nil||
98
+ |expiration|3600|nil|message time-to-live|
99
+ |message_type||nil||
100
+ |priority||nil||
101
+ |app_id||nil||
102
+ |id_key|message_id|nil|id to specify message_id|
103
+
104
+ ### TLS related configurations
105
+
106
+ ```
107
+ tls false # enable TLS or not
108
+ tls_cert /path/to/cert
109
+ tls_key /path/to/key
110
+ tls_ca_certificates ["/path/to/ca_certificate"]
111
+ verify_peer true
112
+ ```
113
+
114
+ ### Other Configurations for Input/Output
115
+
116
+ |key|example|default value|description|
117
+ |:--|---|---|---|
118
+ |automatically_recover|true|nil|automatic network failure recovery|
119
+ |network_recovery_interval|30|nil|interval between reconnection attempts|
120
+ |recovery_attempts|3|nil|limits the number of connection recovery|
121
+ |connection_timeout|30|nil||
122
+ |continuation_timeout|600|nil||
123
+
124
+ ## License
125
+
126
+ 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).
127
+
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,29 @@
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-sklenar"
6
+ spec.version = "0.1.2"
7
+ spec.authors = ["NTT Communications", "Pavel Sklenar"]
8
+ spec.email = ["masaki.matsushita@ntt.com", "pajikos@gmail.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/pajikos/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.required_ruby_version = ">= 2.5"
19
+
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "test-unit"
23
+ spec.add_development_dependency "ltsv"
24
+ spec.add_development_dependency "msgpack"
25
+
26
+ spec.add_runtime_dependency "fluentd", ">= 1.0.0"
27
+
28
+ spec.add_dependency "bunny", "~> 2.14.4"
29
+ 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/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
+
70
+ config_param :include_headers, :bool, default: false
71
+ config_param :include_delivery_info, :bool, default: false
72
+ config_param :headers_key, :string, default: "headers"
73
+ config_param :delivery_info_key, :string, default: "delivery_info"
74
+ config_param :manual_ack, :bool, default: false
75
+ config_param :queue_mode, :string, default: nil
76
+ config_param :queue_type, :string, default: nil
77
+
78
+ def initialize
79
+ super
80
+ require "bunny"
81
+ end
82
+
83
+ def configure(conf)
84
+ compat_parameters_convert(conf, :parser)
85
+
86
+ super
87
+
88
+ bunny_options = {}
89
+ bunny_options[:host] = @host if @host
90
+ bunny_options[:hosts] = @hosts if @hosts
91
+ bunny_options[:port] = @port if @port
92
+ bunny_options[:user] = @user if @user
93
+ bunny_options[:pass] = @pass if @pass
94
+ bunny_options[:vhost] = @vhost if @vhost
95
+ bunny_options[:connection_timeout] = @connection_timeout if @connection_timeout
96
+ bunny_options[:continuation_timeout] = @continuation_timeout if @continuation_timeout
97
+ bunny_options[:automatically_recover] = @automatically_recover if @automatically_recover
98
+ bunny_options[:network_recovery_interval] = @network_recovery_interval if @network_recovery_interval
99
+ bunny_options[:recovery_attempts] = @recovery_attempts
100
+ bunny_options[:auth_mechanism] = @auth_mechanism if @auth_mechanism
101
+ bunny_options[:heartbeat] = @heartbeat if @heartbeat
102
+
103
+ bunny_options[:tls] = @tls
104
+ bunny_options[:tls_cert] = @tls_cert if @tls_cert
105
+ bunny_options[:tls_key] = @tls_key if @tls_key
106
+ bunny_options[:tls_ca_certificates] = @tls_ca_certificates if @tls_ca_certificates
107
+ bunny_options[:verify_peer] = @verify_peer
108
+
109
+ @parser = parser_create
110
+
111
+ @routing_key ||= @tag
112
+ @bunny = Bunny.new(bunny_options)
113
+ end
114
+
115
+ def start
116
+ super
117
+ @bunny.start
118
+ channel = @bunny.create_channel(nil, @consumer_pool_size)
119
+ channel.prefetch(@prefetch_count) if @prefetch_count
120
+ if @create_exchange
121
+ exchange_options = {
122
+ durable: @exchange_durable,
123
+ auto_delete: @auto_delete
124
+ }
125
+ @bunny_exchange = Bunny::Exchange.new(channel, @exchange_type, @exchange, exchange_options)
126
+ if @exchange_to_bind
127
+ @bunny_exchange.bind(@exchange_to_bind, routing_key: @exchange_routing_key)
128
+ end
129
+ end
130
+ queue_arguments = {}
131
+ queue_arguments["x-message-ttl"] = @ttl if @ttl
132
+ queue_arguments["x-queue-mode"] = @queue_mode if @queue_mode
133
+ queue_arguments["x-queue-type"] = @queue_type if @queue_type
134
+ queue = channel.queue(
135
+ @queue,
136
+ durable: @durable,
137
+ exclusive: @exclusive,
138
+ auto_delete: @auto_delete,
139
+ arguments: queue_arguments
140
+ )
141
+ if @exchange
142
+ queue.bind(@exchange, routing_key: @routing_key)
143
+ end
144
+ queue.subscribe(manual_ack: @manual_ack) do |delivery_info, properties, payload|
145
+ @parser.parse(payload) do |time, record|
146
+ time = if properties[:timestamp]
147
+ Fluent::EventTime.from_time(properties[:timestamp])
148
+ else
149
+ time
150
+ end
151
+ if @include_headers
152
+ record[@headers_key] = properties.headers
153
+ end
154
+ if @include_delivery_info
155
+ record[@delivery_info_key] = delivery_info
156
+ end
157
+ router.emit(@tag, time, record)
158
+ end
159
+ channel.ack(delivery_info.delivery_tag) if @manual_ack
160
+ end
161
+ end
162
+
163
+ def multi_workers_ready?
164
+ true
165
+ end
166
+
167
+ def shutdown
168
+ @bunny.close
169
+ super
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,175 @@
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 :frame_max, :integer, default: nil
45
+
46
+ config_param :tls, :bool, default: false
47
+ config_param :tls_cert, :string, default: nil
48
+ config_param :tls_key, :string, default: nil
49
+ config_param :tls_ca_certificates, :array, default: nil
50
+ config_param :verify_peer, :bool, default: true
51
+
52
+ config_param :exchange, :string
53
+ config_param :exchange_type, :string
54
+ config_param :exchange_durable, :bool, default: false
55
+
56
+ config_param :persistent, :bool, default: false
57
+ config_param :routing_key, :string, default: nil
58
+ config_param :id_key, :string, default: nil
59
+ config_param :timestamp, :bool, default: false
60
+ config_param :content_type, :string, default: nil
61
+ config_param :content_encoding, :string, default: nil
62
+ config_param :expiration, :integer, default: nil
63
+ config_param :message_type, :string, default: nil
64
+ config_param :priority, :integer, default: nil
65
+ config_param :app_id, :string, default: nil
66
+
67
+ def initialize
68
+ super
69
+ require "bunny"
70
+ end
71
+
72
+ def configure(conf)
73
+ compat_parameters_convert(conf, :inject, :formatter, default_chunk_key: "time")
74
+
75
+ super
76
+
77
+ bunny_options = {}
78
+ bunny_options[:host] = @host if @host
79
+ bunny_options[:hosts] = @hosts if @hosts
80
+ bunny_options[:port] = @port if @port
81
+ bunny_options[:user] = @user if @user
82
+ bunny_options[:pass] = @pass if @pass
83
+ bunny_options[:vhost] = @vhost if @vhost
84
+ bunny_options[:connection_timeout] = @connection_timeout if @connection_timeout
85
+ bunny_options[:continuation_timeout] = @continuation_timeout if @continuation_timeout
86
+ bunny_options[:automatically_recover] = @automatically_recover if @automatically_recover
87
+ bunny_options[:network_recovery_interval] = @network_recovery_interval if @network_recovery_interval
88
+ bunny_options[:recovery_attempts] = @recovery_attempts
89
+ bunny_options[:auth_mechanism] = @auth_mechanism if @auth_mechanism
90
+ bunny_options[:heartbeat] = @heartbeat if @heartbeat
91
+ bunny_options[:frame_max] = @frame_max if @frame_max
92
+
93
+ bunny_options[:tls] = @tls
94
+ bunny_options[:tls_cert] = @tls_cert if @tls_cert
95
+ bunny_options[:tls_key] = @tls_key if @tls_key
96
+ bunny_options[:tls_ca_certificates] = @tls_ca_certificates if @tls_ca_certificates
97
+ bunny_options[:verify_peer] = @verify_peer
98
+
99
+ @bunny = Bunny.new(bunny_options)
100
+
101
+ @publish_options = {}
102
+ @publish_options[:content_type] = @content_type if @content_type
103
+ @publish_options[:content_encoding] = @content_encoding if @content_encoding
104
+ @publish_options[:persistent] = @persistent if @persistent
105
+ @publish_options[:mandatory] = @mandatory if @mandatory
106
+ @publish_options[:expiration] = @expiration if @expiration
107
+ @publish_options[:type] = @message_type if @message_type
108
+ @publish_options[:priority] = @priority if @priority
109
+ @publish_options[:app_id] = @app_id if @app_id
110
+
111
+ @formatter = formatter_create(default_type: @type)
112
+ end
113
+
114
+ def multi_workers_ready?
115
+ true
116
+ end
117
+
118
+ def prefer_buffered_processing
119
+ false
120
+ end
121
+
122
+ def start
123
+ super
124
+ @bunny.start
125
+ @channel = @bunny.create_channel
126
+ exchange_options = {
127
+ durable: @exchange_durable,
128
+ auto_delete: @exchange_auto_delete
129
+ }
130
+ @bunny_exchange = Bunny::Exchange.new(@channel, @exchange_type, @exchange, exchange_options)
131
+ end
132
+
133
+ def shutdown
134
+ @bunny.close
135
+ super
136
+ end
137
+
138
+ def set_publish_options(tag, time, record)
139
+ @publish_options[:timestamp] = time.to_i if @timestamp
140
+
141
+ if @exchange_type != "fanout"
142
+ routing_key_value = "default"
143
+ if @routing_key
144
+ routing_key_value = record[@routing_key]
145
+ @publish_options[:routing_key] = routing_key_value
146
+ end
147
+ end
148
+
149
+ if @id_key
150
+ id = record[@id_key]
151
+ @publish_options[:message_id] = id if id
152
+ end
153
+ end
154
+
155
+ def process(tag, es)
156
+ es.each do |time, record|
157
+ set_publish_options(tag, time, record)
158
+ record = inject_values_to_record(tag, time, record)
159
+ buf = @formatter.format(tag, time, record)
160
+ @bunny_exchange.publish(buf, @publish_options)
161
+ end
162
+ end
163
+
164
+ def write(chunk)
165
+ tag = chunk.metadata.tag
166
+
167
+ chunk.each do |time, record|
168
+ set_publish_options(tag, time, record)
169
+ record = inject_values_to_record(tag, time, record)
170
+ buf = @formatter.format(tag, time, record)
171
+ @bunny_exchange.publish(buf, @publish_options)
172
+ end
173
+ end
174
+ end
175
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-rabbitmq-sklenar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - NTT Communications
8
+ - Pavel Sklenar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: test-unit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: ltsv
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: msgpack
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: fluentd
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.0.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.0.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: bunny
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 2.14.4
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 2.14.4
112
+ description: fluent plugin for rabbitmq (AMQP)
113
+ email:
114
+ - masaki.matsushita@ntt.com
115
+ - pajikos@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - COPYING
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - fluent-plugin-rabbitmq.gemspec
128
+ - lib/fluent/plugin/in_rabbitmq.rb
129
+ - lib/fluent/plugin/out_rabbitmq.rb
130
+ homepage: https://github.com/pajikos/fluent-plugin-rabbitmq
131
+ licenses:
132
+ - Apache-2.0
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '2.5'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubygems_version: 3.0.3.1
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: fluent plugin for rabbitmq (AMQP)
153
+ test_files: []