logstash-integration-rabbitmq 7.0.1-java → 7.2.0-java

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
  SHA256:
3
- metadata.gz: 1c9eb2d5cd3c2ee2cd302c99305d08768545cdca5c8a514d453889aa6261e88d
4
- data.tar.gz: 3f02e987e179e543ccd1e3b1f2db5386aae98a415498c7c33f80c108e8463823
3
+ metadata.gz: 7901c2c7a657f948fa4b0babcfba746e84d15effeacaf98e410b59e774bb015c
4
+ data.tar.gz: 447c27c4a03355df0d307017f88a31c830281f10a80c0a8c6e6b68be80b2d334
5
5
  SHA512:
6
- metadata.gz: 7c39a3f8d79aac858797c485b3c1b749ebdf03ee4ba834b85b6ef6eba4e552d8668a5a40100e1c3c231730c5abe78fccced58b15b558c46ef06bb553a24bab50
7
- data.tar.gz: 309dd81565fa462ca58ba87300e2273fde6b49a505bbfc6276d5ece07b0bfa81ddda98f78ab09894a9b4d4fa5354e52f0190467a42a708d3fa009a0b4f55ad26
6
+ metadata.gz: 459a95ef169e4b25ebe32ab9e72d6925ba987c2dccfd7fc27b68b789668b342ba21bf9e66aa0942ef6e8418cb855b3561731ae4b7cfd9300c45b1f60a2e1b0e0
7
+ data.tar.gz: 3254e80a9990bd0b50bbdda4e4959eb04619006b29b61a1ffcb4fb0bbd037e876aecae4bf208999a4294fb8482c302b9875249cb06525fb35c14e45a98d44909
@@ -1,3 +1,22 @@
1
+ ## 7.2.0
2
+ - Remove ruby pipeline dependency. Starting from Logstash 8, Ruby execution engine is not available. All pipelines should use Java pipeline [#39](https://github.com/logstash-plugins/logstash-integration-rabbitmq/pull/39)
3
+
4
+ ## 7.1.1
5
+ - DOC:Replaced plugin_header file with plugin_header-integration file. ([#34](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/34))
6
+
7
+ ## 7.1.0
8
+ - Added support in Output plugin for `sprintf` templates in values provided to `message_properties` ([#8](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/8))
9
+ - Added support for _extended_ metadata including raw payload to events generated by the Input Plugin [#13](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/13)
10
+ - Fixes an issue with custom port assignment, in which the custom port was not being applied when more than one host was supplied [#12](https://github.com/logstash-plugins/logstash-integration-rabbitmq/pull/12)
11
+ - Fixes bug where attempting to read from undeclared exchange resulted in infinite retry loop ([#10](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/10))
12
+ - Fixes bug where failing to establish initial connection resulted in a pipeline that refused to shut down ([#11](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/11))
13
+
14
+ ## 7.0.3
15
+ - Refactor: scope (and remove unused) java imports [#29](https://github.com/logstash-plugins/logstash-integration-rabbitmq/pull/29)
16
+
17
+ ## 7.0.2
18
+ - Fixes issue in Output where failure to register connection reovery hooks prevented the output from starting
19
+
1
20
  ## 7.0.1
2
21
  - Improves Input Plugin documentation to better align with upstream guidance [#4](https://github.com/logstash-plugins/logstash-integration-rabbitmq/pull/4)
3
22
 
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
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
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
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.
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
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-integration-rabbitmq.svg)](https://travis-ci.org/logstash-plugins/logstash-integration-rabbitmq)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-integration-rabbitmq.svg)](https://travis-ci.com/logstash-plugins/logstash-integration-rabbitmq)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
@@ -1,3 +1,4 @@
1
+ :integration: rabbitmq
1
2
  :plugin: rabbitmq
2
3
  :type: input
3
4
  :default_codec: json
@@ -17,7 +18,7 @@ END - GENERATED VARIABLES, DO NOT EDIT!
17
18
 
18
19
  === Rabbitmq input plugin
19
20
 
20
- include::{include_path}/plugin_header.asciidoc[]
21
+ include::{include_path}/plugin_header-integration.asciidoc[]
21
22
 
22
23
  ==== Description
23
24
 
@@ -34,7 +35,7 @@ and other parts of the RabbitMQ documentation are useful for deeper
34
35
  understanding.
35
36
 
36
37
  The properties of messages received will be stored in the
37
- `[@metadata][rabbitmq_properties]` field if the `@metadata_enabled` setting is checked.
38
+ `[@metadata][rabbitmq_properties]` field if the `@metadata_enabled` setting is enabled.
38
39
  Note that storing metadata may degrade performance.
39
40
  The following properties may be available (in most cases dependent on whether
40
41
  they were set by the sender):
@@ -187,6 +188,8 @@ The default connection timeout in milliseconds. If not specified the timeout is
187
188
  * Default value is `false`
188
189
 
189
190
  Is this queue durable? (aka; Should it survive a broker restart?)
191
+ If consuming directly from a queue you must set this value to match the existing queue setting,
192
+ otherwise the connection will fail due to an inequivalent arg error.
190
193
 
191
194
  [id="plugins-{type}s-{plugin}-exchange"]
192
195
  ===== `exchange`
@@ -259,8 +262,14 @@ This is only relevant for direct or topic exchanges.
259
262
  [id="plugins-{type}s-{plugin}-metadata_enabled"]
260
263
  ===== `metadata_enabled`
261
264
 
262
- * Value type is <<boolean,boolean>>
263
- * Default value is `false`
265
+ * Value type is <<string,string>>
266
+ * Accepted values are:
267
+ - `none`: no metadata is added
268
+ - `basic`: headers and properties are added
269
+ - `extended`: headers, properties, and raw payload are added
270
+ - `false`: deprecated alias for `none`
271
+ - `true`: deprecated alias for `basic`
272
+ * Default value is `none`
264
273
 
265
274
  Enable the storage of message headers and properties in `@metadata`. This may impact performance
266
275
 
@@ -1,3 +1,4 @@
1
+ :integration: rabbitmq
1
2
  :plugin: rabbitmq
2
3
  :type: output
3
4
  :default_codec: json
@@ -17,7 +18,7 @@ END - GENERATED VARIABLES, DO NOT EDIT!
17
18
 
18
19
  === Rabbitmq output plugin
19
20
 
20
- include::{include_path}/plugin_header.asciidoc[]
21
+ include::{include_path}/plugin_header-integration.asciidoc[]
21
22
 
22
23
  ==== Description
23
24
 
@@ -168,7 +169,8 @@ Key to route to by default. Defaults to 'logstash'
168
169
  * Value type is <<hash,hash>>
169
170
  * Default value is `{}`
170
171
 
171
- Add properties to be set per-message here, such as 'content_type', 'priority'
172
+ Add properties to be set per-message here, such as 'content_type', 'priority'.
173
+ Values can be {logstash-ref}/event-dependent-configuration.html#sprintf[`sprintf` templates], whose value for each message will be populated from the event.
172
174
 
173
175
  Example:
174
176
  [source,ruby]
@@ -2,8 +2,6 @@
2
2
  require_relative '../plugin_mixins/rabbitmq_connection'
3
3
  require 'logstash/inputs/threadable'
4
4
  require 'logstash/event'
5
- java_import java.util.concurrent.ArrayBlockingQueue
6
- java_import java.util.concurrent.TimeUnit
7
5
 
8
6
  module LogStash
9
7
  module Inputs
@@ -59,6 +57,9 @@ module LogStash
59
57
  # Additionally, any message headers will be saved in the
60
58
  # `[@metadata][rabbitmq_headers]` field.
61
59
  class RabbitMQ < LogStash::Inputs::Threadable
60
+
61
+ java_import java.util.concurrent.TimeUnit
62
+
62
63
  include ::LogStash::PluginMixins::RabbitMQConnection
63
64
 
64
65
  # The properties to extract from each message and store in a
@@ -165,16 +166,26 @@ module LogStash
165
166
  config :subscription_retry_interval_seconds, :validate => :number, :required => true, :default => 5
166
167
 
167
168
  # Enable the storage of message headers and properties in `@metadata`. This may impact performance
168
- config :metadata_enabled, :validate => :boolean, :default => false
169
+ config :metadata_enabled, :validate => %w(none basic extended false true), :default => "none"
169
170
 
170
171
  def register
171
172
  @internal_queue = java.util.concurrent.ArrayBlockingQueue.new(@prefetch_count*2)
173
+ @metadata_level = extract_metadata_level(@metadata_enabled)
172
174
  end
173
175
 
176
+ attr_reader :metadata_level
177
+
174
178
  def run(output_queue)
175
179
  setup!
176
180
  @output_queue = output_queue
177
181
  consume!
182
+ rescue => e
183
+ raise unless stop?
184
+
185
+ logger.warn("Ignoring exception thrown during plugin shutdown",
186
+ :message => e.message,
187
+ :class => e.class.name,
188
+ :location => e.backtrace.first)
178
189
  end
179
190
 
180
191
  def setup!
@@ -183,14 +194,32 @@ module LogStash
183
194
  bind_exchange!
184
195
  @hare_info.channel.prefetch = @prefetch_count
185
196
  rescue => e
197
+ # when encountering an exception during shut-down,
198
+ # re-raise the exception instead of retrying
199
+ raise if stop?
200
+
201
+ reset!
202
+
186
203
  @logger.warn("Error while setting up connection for rabbitmq input! Will retry.",
187
- :message => e.message,
188
- :class => e.class.name,
204
+ :message => e.message,
205
+ :class => e.class.name,
189
206
  :location => e.backtrace.first)
190
207
  sleep_for_retry
191
208
  retry
192
209
  end
193
210
 
211
+ # reset a partially-established connection, enabling subsequent
212
+ # call to `RabbitMQ#setup!` to succeed.
213
+ #
214
+ # @api private
215
+ def reset!
216
+ @hare_info.connection && @hare_info.connection.close
217
+ rescue => e
218
+ @logger.debug("Exception while resetting connection", :exception => e.message, :backtrace => e.backtrace)
219
+ ensure
220
+ @hare_info = nil
221
+ end
222
+
194
223
  def bind_exchange!
195
224
  if @exchange
196
225
  if @exchange_type # Only declare the exchange if @exchange_type is set!
@@ -249,12 +278,11 @@ module LogStash
249
278
 
250
279
  metadata, data = payload
251
280
  @codec.decode(data) do |event|
252
- decorate(event)
253
- if @metadata_enabled
254
- event.set("[@metadata][rabbitmq_headers]", get_headers(metadata))
255
- event.set("[@metadata][rabbitmq_properties]", get_properties(metadata))
281
+ if event
282
+ decorate(event, metadata, data)
283
+
284
+ @output_queue << event
256
285
  end
257
- @output_queue << event if event
258
286
  end
259
287
 
260
288
  i += 1
@@ -269,6 +297,16 @@ module LogStash
269
297
  end
270
298
  end
271
299
 
300
+ def decorate(event, metadata, data)
301
+ super(event)
302
+
303
+ event.set("[@metadata][rabbitmq_headers]", get_headers(metadata)) if metadata_level.include?(:headers)
304
+ event.set("[@metadata][rabbitmq_properties]", get_properties(metadata)) if metadata_level.include?(:properties)
305
+ event.set("[@metadata][rabbitmq_payload]", data) if metadata_level.include?(:payload) && !data.nil?
306
+
307
+ nil
308
+ end
309
+
272
310
  def stop
273
311
  @internal_queue.put(INTERNAL_QUEUE_POISON)
274
312
  shutdown_consumer
@@ -310,6 +348,28 @@ module LogStash
310
348
  acc
311
349
  end
312
350
  end
351
+
352
+ METADATA_NONE = Set[].freeze
353
+ METADATA_BASIC = Set[:headers,:properties].freeze
354
+ METADATA_EXTENDED = Set[:headers,:properties,:payload].freeze
355
+ METADATA_DEPRECATION_MAP = { 'true' => 'basic', 'false' => 'none' }
356
+
357
+ private
358
+ def extract_metadata_level(metadata_enabled_setting)
359
+ metadata_enabled = metadata_enabled_setting
360
+
361
+ if METADATA_DEPRECATION_MAP.include?(metadata_enabled)
362
+ canonical_value = METADATA_DEPRECATION_MAP[metadata_enabled]
363
+ logger.warn("Deprecated value `#{metadata_enabled_setting}` for `metadata_enabled` option; use `#{canonical_value}` instead.")
364
+ metadata_enabled = canonical_value
365
+ end
366
+
367
+ case metadata_enabled
368
+ when 'none' then METADATA_NONE
369
+ when 'basic' then METADATA_BASIC
370
+ when 'extended' then METADATA_EXTENDED
371
+ end
372
+ end
313
373
  end
314
374
  end
315
375
  end
@@ -1,14 +1,12 @@
1
1
  # encoding: UTF-8
2
2
  require "logstash/pipeline"
3
3
  require_relative '../plugin_mixins/rabbitmq_connection'
4
- java_import java.util.concurrent.TimeoutException
5
- java_import com.rabbitmq.client.AlreadyClosedException
6
4
 
7
5
  require 'back_pressure'
8
6
 
9
7
  # Push events to a RabbitMQ exchange. Requires RabbitMQ 2.x
10
8
  # or later version (3.x is recommended).
11
- #
9
+ #
12
10
  # Relevant links:
13
11
  #
14
12
  # * http://www.rabbitmq.com/[RabbitMQ]
@@ -16,10 +14,14 @@ require 'back_pressure'
16
14
  module LogStash
17
15
  module Outputs
18
16
  class RabbitMQ < LogStash::Outputs::Base
17
+
18
+ java_import java.util.concurrent.TimeoutException
19
+ java_import com.rabbitmq.client.AlreadyClosedException
20
+
19
21
  include LogStash::PluginMixins::RabbitMQConnection
20
22
 
21
23
  config_name "rabbitmq"
22
-
24
+
23
25
  concurrency :shared
24
26
 
25
27
  # The default codec for this plugin is JSON. You can override this to suit your particular needs however.
@@ -46,6 +48,8 @@ module LogStash
46
48
  config :message_properties, :validate => :hash, :default => {}
47
49
 
48
50
  def register
51
+ @message_properties_template = MessagePropertiesTemplate.new(symbolize(@message_properties).merge(:persistent => @persistent))
52
+
49
53
  connect!
50
54
  @hare_info.exchange = declare_exchange!(@hare_info.channel, @exchange, @exchange_type, @durable)
51
55
  # The connection close should close all channels, so it is safe to store thread locals here without closing them
@@ -67,8 +71,10 @@ module LogStash
67
71
 
68
72
  def publish(event, message)
69
73
  raise ArgumentError, "No exchange set in HareInfo!!!" unless @hare_info.exchange
74
+ routing_key = event.sprintf(@key)
75
+ message_properties = @message_properties_template.build(event)
70
76
  @gated_executor.execute do
71
- local_exchange.publish(message, :routing_key => event.sprintf(@key), :properties => symbolize(@message_properties.merge(:persistent => @persistent)))
77
+ local_exchange.publish(message, :routing_key => routing_key, :properties => message_properties)
72
78
  end
73
79
  rescue MarchHare::Exception, IOError, AlreadyClosedException, TimeoutException => e
74
80
  @logger.error("Error while publishing. Will retry.",
@@ -118,7 +124,7 @@ module LogStash
118
124
  march_hare_connection.on_unblocked do
119
125
  executor.remove_back_pressure('connection flagged as unblocked')
120
126
  end
121
- march_hare_connection.on_recovery_started do
127
+ march_hare_connection.on_recovery_start do
122
128
  executor.engage_back_pressure("connection is being recovered")
123
129
  end
124
130
  march_hare_connection.on_recovery do
@@ -126,6 +132,64 @@ module LogStash
126
132
  end
127
133
  end
128
134
  end
135
+
136
+ ##
137
+ # A `MessagePropertiesTemplate` efficiently produces per-event message properties from the
138
+ # provided template Hash.
139
+ #
140
+ # In order to efficiently reuse constant-value objects, returned values may be frozen.
141
+ class MessagePropertiesTemplate
142
+ ##
143
+ # Creates a new `MessagePropertiesTemplate` from the provided `template`
144
+ # @param template [Hash{Symbol=>Object}]
145
+ def initialize(template)
146
+ constant_properties = template.reject { |_,v| templated?(v) }
147
+ variable_properties = template.select { |_,v| templated?(v) }
148
+
149
+ @constant_properties = normalize(constant_properties).freeze
150
+ @variable_properties = variable_properties
151
+ end
152
+
153
+ ##
154
+ # Builds a property mapping for the given `event`, including templated values.
155
+ #
156
+ # @param event [LogStash::Event]: the event with which to populated templated values, if any.
157
+ # @return [Hash{Symbol=>Object}] a possibly-frozen properties hash for the provided `event`.
158
+ def build(event)
159
+ return @constant_properties if @variable_properties.empty?
160
+
161
+ properties = @variable_properties.each_with_object(@constant_properties.dup) do |(k,v), memo|
162
+ memo.store(k, event.sprintf(v))
163
+ end
164
+
165
+ return normalize(properties)
166
+ end
167
+
168
+ private
169
+
170
+ ##
171
+ # Normalize the provided property mapping with respect to the value types the underlying
172
+ # client expects.
173
+ #
174
+ # @api private
175
+ # @param properties [Hash{Symbol=>Object}]: a possibly-frozen Hash whose values may need type-coercion.
176
+ # @return [Hash{Symbol=>Object}]
177
+ def normalize(properties)
178
+ if properties[:priority] && properties[:priority].kind_of?(String)
179
+ properties = properties.merge(:priority => properties[:priority].to_i)
180
+ end
181
+
182
+ properties
183
+ end
184
+
185
+ ##
186
+ # @api private
187
+ # @param [Object]: an object, which may or may not be a template `String`
188
+ # @return [Boolean]: returns `true` IFF `value` is a template `String`
189
+ def templated?(value)
190
+ value.kind_of?(String) && value.include?('%{')
191
+ end
192
+ end
129
193
  end
130
194
  end
131
- end
195
+ end
@@ -2,6 +2,7 @@
2
2
  require "logstash/namespace"
3
3
  require "march_hare"
4
4
  require "java"
5
+ require "stud/interval"
5
6
 
6
7
  # Common functionality for the rabbitmq input/output
7
8
  module LogStash
@@ -104,10 +105,10 @@ module LogStash
104
105
  def rabbitmq_settings
105
106
  return @rabbitmq_settings if @rabbitmq_settings
106
107
 
108
+
107
109
  s = {
108
110
  :vhost => @vhost,
109
- :hosts => @host,
110
- :port => @port,
111
+ :addresses => addresses_from_hosts_and_port(@host, @port),
111
112
  :user => @user,
112
113
  :automatic_recovery => @automatic_recovery,
113
114
  :pass => @password ? @password.value : "guest",
@@ -133,6 +134,11 @@ module LogStash
133
134
  @rabbitmq_settings = s
134
135
  end
135
136
 
137
+ def addresses_from_hosts_and_port(hosts, port)
138
+ hosts.map {|host| host.include?(':') ? host : "#{host}:#{port}"}
139
+ end
140
+
141
+
136
142
  def connect!
137
143
  @hare_info = connect() unless @hare_info # Don't duplicate the conn!
138
144
  rescue MarchHare::Exception, java.io.IOException => e
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-rabbitmq'
3
- s.version = '7.0.1'
3
+ s.version = '7.2.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Integration with RabbitMQ - input and output plugins"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline "+
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.add_runtime_dependency 'stud', '~> 0.0.22'
48
48
  s.add_runtime_dependency 'back_pressure', '~> 1.0'
49
49
 
50
- s.add_development_dependency 'logstash-devutils'
50
+ s.add_development_dependency 'logstash-devutils', '~>2.0'
51
51
  s.add_development_dependency 'logstash-input-generator'
52
52
  s.add_development_dependency 'logstash-codec-plain'
53
53
  end
@@ -21,8 +21,13 @@ describe LogStash::Inputs::RabbitMQ do
21
21
  "prefetch_count" => 123
22
22
  }
23
23
  }
24
- let(:instance) { klass.new(rabbitmq_settings) }
24
+ subject(:instance) { klass.new(rabbitmq_settings) }
25
25
  let(:hare_info) { instance.instance_variable_get(:@hare_info) }
26
+ let(:instance_logger) { double("Logger").as_null_object }
27
+
28
+ before do
29
+ allow_any_instance_of(klass).to receive(:logger).and_return(instance_logger)
30
+ end
26
31
 
27
32
  context "when connected" do
28
33
  let(:connection) { double("MarchHare Connection") }
@@ -39,6 +44,7 @@ describe LogStash::Inputs::RabbitMQ do
39
44
  allow(connection).to receive(:on_shutdown)
40
45
  allow(connection).to receive(:on_blocked)
41
46
  allow(connection).to receive(:on_unblocked)
47
+ allow(connection).to receive(:close)
42
48
  allow(channel).to receive(:exchange).and_return(exchange)
43
49
  allow(channel).to receive(:queue).and_return(queue)
44
50
  allow(channel).to receive(:prefetch=)
@@ -127,11 +133,193 @@ describe LogStash::Inputs::RabbitMQ do
127
133
  end
128
134
  end
129
135
  end
136
+
137
+ context '#register' do
138
+ let(:rabbitmq_settings) { super().merge(metadata_enabled_override) }
139
+ let(:metadata_enabled_override) { { "metadata_enabled" => metadata_enabled } }
140
+ before do
141
+ instance.register
142
+ end
143
+
144
+ shared_examples('`metadata_enabled => none`') do
145
+ context 'metadata_level' do
146
+ subject(:metadata_level) { instance.metadata_level }
147
+ it { is_expected.to be_empty }
148
+ it { is_expected.to be_frozen }
149
+ end
150
+ end
151
+
152
+ shared_examples('`metadata_enabled => basic`') do
153
+ context 'metadata_level' do
154
+ subject(:metadata_level) { instance.metadata_level }
155
+ it { is_expected.to include :headers }
156
+ it { is_expected.to include :properties }
157
+ it { is_expected.to_not include :payload }
158
+ it { is_expected.to be_frozen }
159
+ end
160
+ end
161
+
162
+ shared_examples("deprecated `metadata_enabled` setting") do |deprecated_value|
163
+ context 'the logger' do
164
+ subject(:logger) { instance_logger }
165
+ it 'receives a useful deprecation warning' do
166
+ expect(logger).to have_received(:warn).with(/Deprecated value `#{Regexp.escape(deprecated_value)}`/)
167
+ end
168
+ end
169
+ end
170
+
171
+ context 'when `metadata_enabled` is `true`' do
172
+ let(:metadata_enabled) { "true" }
173
+ it_behaves_like '`metadata_enabled => basic`'
174
+ include_examples "deprecated `metadata_enabled` setting", "true"
175
+ end
176
+
177
+ context 'when `metadata_enabled` is `false`' do
178
+ let(:metadata_enabled) { "false" }
179
+ it_behaves_like '`metadata_enabled => none`'
180
+ include_examples "deprecated `metadata_enabled` setting", "false"
181
+ end
182
+
183
+ context 'when `metadata_enabled` is not provided' do
184
+ let(:metadata_enabled_override) { Hash.new }
185
+ it_behaves_like '`metadata_enabled => none`'
186
+ end
187
+
188
+ context 'when `metadata_enabled` is `basic`' do
189
+ let(:metadata_enabled) { "basic" }
190
+ include_examples '`metadata_enabled => basic`'
191
+ end
192
+
193
+ context 'when `metadata_enabled` is `none`' do
194
+ let(:metadata_enabled) { "none" }
195
+ include_examples '`metadata_enabled => none`'
196
+ end
197
+
198
+ context 'when `metadata_enabled` is `extended`' do
199
+ let(:metadata_enabled) { "extended" }
200
+ context 'metadata_level' do
201
+ subject(:metadata_level) { instance.metadata_level }
202
+ it { is_expected.to include :headers }
203
+ it { is_expected.to include :properties }
204
+ it { is_expected.to include :payload }
205
+ it { is_expected.to be_frozen }
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "#decorate(event, metadata, data)" do
211
+ let(:rabbitmq_settings) do
212
+ super().merge("metadata_enabled" => metadata_enabled)
213
+ end
214
+ before(:each) { instance.register }
215
+
216
+ let(:metadata) { double("METADATA") }
217
+ let(:headers) { Hash("header_key"=>"header_value") }
218
+ let(:properties) { Hash("property_key"=>"property_value") }
219
+
220
+ let(:data) { %Q({"message"=>"fubar"}\n) }
221
+
222
+ before do
223
+ allow(instance).to receive(:get_headers).with(metadata).and_return(headers)
224
+ allow(instance).to receive(:get_properties).with(metadata).and_return(properties)
225
+ end
226
+
227
+ describe 'the decorated event' do
228
+ subject(:decorated_event) do
229
+ LogStash::Event.new("message"=>"fubar").tap do |e|
230
+ instance.decorate(e, metadata, data)
231
+ end
232
+ end
233
+
234
+ matcher :include_field do |fieldref|
235
+ match do |event|
236
+ # setting `@actual` makes failure messages clearer
237
+ @actual = event.to_hash_with_metadata
238
+
239
+ break false unless event.include?(fieldref)
240
+ break true unless @specific_value
241
+
242
+ values_match?(@expected_value, event.get(fieldref))
243
+ end
244
+ chain :with_value do |expected_value|
245
+ @specific_value = true
246
+ @expected_value = expected_value
247
+ end
248
+ description do
249
+ desc = "include field `#{fieldref}`"
250
+ desc += " with value matching `#{@expected_value.inspect}`" if @specific_value
251
+ desc
252
+ end
253
+ end
254
+
255
+ shared_examples('core decoration features') do
256
+ let(:rabbitmq_settings) do
257
+ super().merge("type" => "decorated_type",
258
+ "add_field" => {"added_field" => "field_value"})
259
+ end
260
+ it 'has been decorated with core decoration features' do
261
+ expect(decorated_event).to include_field("added_field").with_value("field_value")
262
+ expect(decorated_event).to include_field("type").with_value("decorated_type")
263
+ end
264
+ end
265
+
266
+ let(:headers_fieldref) { "[@metadata][rabbitmq_headers]" }
267
+ let(:properties_fieldref) { "[@metadata][rabbitmq_properties]" }
268
+ let(:payload_fieldref) { "[@metadata][rabbitmq_payload]" }
269
+
270
+ shared_examples('`metadata_enabled => none`') do
271
+ it { is_expected.to_not include_field(headers_fieldref) }
272
+ it { is_expected.to_not include_field(properties_fieldref) }
273
+ it { is_expected.to_not include_field(payload_fieldref) }
274
+
275
+ include_examples 'core decoration features'
276
+ end
277
+
278
+ shared_examples('`metadata_enabled => basic`') do
279
+ it { is_expected.to include_field(headers_fieldref).with_value(headers) }
280
+ it { is_expected.to include_field(properties_fieldref).with_value(properties) }
281
+ it { is_expected.to_not include_field(payload_fieldref) }
282
+
283
+ include_examples 'core decoration features'
284
+ end
285
+
286
+ context "with `metadata_enabled => none`" do
287
+ let(:metadata_enabled) { "none" }
288
+ include_examples '`metadata_enabled => none`'
289
+ end
290
+
291
+ context "with `metadata_enabled => basic`" do
292
+ let(:metadata_enabled) { "basic" }
293
+ include_examples '`metadata_enabled => basic`'
294
+ end
295
+
296
+ context 'with `metadata_enabled => extended`' do
297
+ let(:metadata_enabled) { "extended" }
298
+ it { is_expected.to include_field(headers_fieldref).with_value(headers) }
299
+ it { is_expected.to include_field(properties_fieldref).with_value(properties) }
300
+ it { is_expected.to include_field(payload_fieldref).with_value(data) }
301
+ include_examples 'core decoration features'
302
+ end
303
+
304
+ # Deprecated alias: false -> none
305
+ context "with `metadata_enabled => false`" do
306
+ let(:metadata_enabled) { "false" }
307
+ it_behaves_like '`metadata_enabled => none`'
308
+ end
309
+
310
+ # Deprecated alias: true -> basic
311
+ context "with `metadata_enabled => true`" do
312
+ let(:metadata_enabled) { "true" }
313
+ it_behaves_like '`metadata_enabled => basic`'
314
+ end
315
+ end
316
+ end
130
317
  end
131
318
 
132
- describe "with a live server", :integration => true do
319
+ describe "LogStash::Inputs::RabbitMQ with a live server", :integration => true do
133
320
  let(:klass) { LogStash::Inputs::RabbitMQ }
134
- let(:config) { {"host" => "127.0.0.1", "auto_delete" => true, "codec" => "plain", "add_field" => {"[@metadata][foo]" => "bar"} } }
321
+ let(:rabbitmq_host) { ENV["RABBITMQ_HOST"] || "127.0.0.1" }
322
+ let(:config) { {"host" => rabbitmq_host, "auto_delete" => true, "codec" => "plain", "add_field" => {"[@metadata][foo]" => "bar"} } }
135
323
  let(:instance) { klass.new(config) }
136
324
  let(:hare_info) { instance.instance_variable_get(:@hare_info) }
137
325
  let(:output_queue) { Queue.new }
@@ -185,7 +373,7 @@ describe "with a live server", :integration => true do
185
373
  end
186
374
 
187
375
  describe "receiving a message with a queue + exchange specified" do
188
- let(:config) { super.merge("queue" => queue_name, "exchange" => exchange_name, "exchange_type" => "fanout", "metadata_enabled" => true) }
376
+ let(:config) { super.merge("queue" => queue_name, "exchange" => exchange_name, "exchange_type" => "fanout", "metadata_enabled" => "true") }
189
377
  let(:event) { output_queue.pop }
190
378
  let(:exchange) { test_channel.exchange(exchange_name, :type => "fanout") }
191
379
  let(:exchange_name) { "logstash-input-rabbitmq-#{rand(0xFFFFFFFF)}" }
@@ -237,7 +425,7 @@ describe "with a live server", :integration => true do
237
425
  expect(event).to include("@metadata")
238
426
  expect(event.get("@metadata")).to include("rabbitmq_properties")
239
427
 
240
- props = event.get("[@metadata][rabbitmq_properties")
428
+ props = event.get("[@metadata][rabbitmq_properties]")
241
429
  expect(props["app-id"]).to eq(app_id)
242
430
  expect(props["delivery-mode"]).to eq(1)
243
431
  expect(props["exchange"]).to eq(exchange_name)
@@ -274,6 +462,7 @@ describe "with a live server", :integration => true do
274
462
  end
275
463
 
276
464
  describe LogStash::Inputs::RabbitMQ do
465
+ require "logstash/devutils/rspec/shared_examples"
277
466
  it_behaves_like "an interruptible input plugin"
278
467
  end
279
468
  end
@@ -1,8 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
- require "logstash/pipeline"
4
3
  require "logstash/outputs/rabbitmq"
5
- java_import java.util.concurrent.TimeoutException
6
4
 
7
5
  describe LogStash::Outputs::RabbitMQ do
8
6
  let(:klass) { LogStash::Outputs::RabbitMQ }
@@ -60,7 +58,7 @@ describe LogStash::Outputs::RabbitMQ do
60
58
  allow(connection).to receive(:on_blocked)
61
59
  allow(connection).to receive(:on_unblocked)
62
60
  allow(connection).to receive(:on_shutdown)
63
- allow(connection).to receive(:on_recovery_started)
61
+ allow(connection).to receive(:on_recovery_start)
64
62
  allow(connection).to receive(:on_recovery)
65
63
  allow(channel).to receive(:exchange).and_return(exchange)
66
64
 
@@ -84,18 +82,67 @@ describe LogStash::Outputs::RabbitMQ do
84
82
  before do
85
83
  allow(exchange).to receive(:publish).with(any_args)
86
84
  allow(event).to receive(:sprintf).with(key).and_return(sprinted_key)
87
- instance.send(:publish, event, encoded_event)
88
85
  end
89
86
 
90
87
  it "should send the correct message" do
88
+ instance.send(:publish, event, encoded_event)
91
89
  expect(exchange).to have_received(:publish).with(encoded_event, anything)
92
90
  end
93
91
 
94
92
  it "should send the correct metadata" do
95
93
  expected_metadata = {:routing_key => sprinted_key, :properties => {:persistent => persistent }}
96
94
 
95
+ instance.send(:publish, event, encoded_event)
96
+
97
97
  expect(exchange).to have_received(:publish).with(anything, expected_metadata)
98
98
  end
99
+
100
+ context 'with message_properties' do
101
+ let(:rabbitmq_settings) { super().merge("message_properties" => message_properties) }
102
+ let(:message_properties) { Hash.new }
103
+ context 'priority' do
104
+ let(:message_properties) { super().merge("priority" => priority) }
105
+ context 'as literal Integer value' do
106
+ let(:priority) { 3 }
107
+ it 'publishes with the constant-value priority' do
108
+ instance.send(:publish, event, encoded_event)
109
+ expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 3)))
110
+ end
111
+ end
112
+
113
+ context 'as literal String value' do
114
+ let(:priority) { "7" }
115
+ it 'publishes with the constant-value priority' do
116
+ instance.send(:publish, event, encoded_event)
117
+ expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 7)))
118
+ end
119
+ end
120
+
121
+ context 'as template value' do
122
+ let(:priority) { "%{[@metadata][priority]}" }
123
+ context 'when event expands template value' do
124
+ before do
125
+ expect(event).to receive(:sprintf).with(priority).and_return("31")
126
+ end
127
+
128
+ it 'publishes with the priority extracted from the event' do
129
+ instance.send(:publish, event, encoded_event)
130
+ expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 31)))
131
+ end
132
+ end
133
+ context 'when event cannot expand template value' do
134
+ before do
135
+ expect(event).to receive(:sprintf).with(priority).and_return(priority)
136
+ end
137
+
138
+ it 'publishes with the priority of zero (`0`)' do
139
+ instance.send(:publish, event, encoded_event)
140
+ expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 0)))
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
99
146
  end
100
147
 
101
148
  context 'when an exception is encountered' do
@@ -124,7 +171,7 @@ describe LogStash::Outputs::RabbitMQ do
124
171
  end
125
172
 
126
173
  context 'when it is a TimeoutException' do
127
- let(:exception) { TimeoutException.new }
174
+ let(:exception) { java.util.concurrent.TimeoutException.new }
128
175
  it_behaves_like 'recovers from exception gracefully'
129
176
  end
130
177
  end
@@ -133,14 +180,15 @@ describe LogStash::Outputs::RabbitMQ do
133
180
  end
134
181
 
135
182
 
136
- describe "with a live server", :integration => true do
183
+ describe "LogStash::Outputs::RabbitMQ with a live server", :integration => true do
184
+ let(:rabbitmq_host) { ENV["RABBITMQ_HOST"] || "127.0.0.1" }
137
185
  let(:klass) { LogStash::Outputs::RabbitMQ }
138
186
  let(:exchange) { "myexchange" }
139
187
  let(:exchange_type) { "topic" }
140
188
  let(:priority) { 34 }
141
189
  let(:default_plugin_config) {
142
190
  {
143
- "host" => "127.0.0.1",
191
+ "host" => rabbitmq_host,
144
192
  "exchange" => exchange,
145
193
  "exchange_type" => exchange_type,
146
194
  "key" => "foo",
@@ -14,12 +14,12 @@ end
14
14
 
15
15
  describe LogStash::PluginMixins::RabbitMQConnection do
16
16
  let(:klass) { TestPlugin }
17
+ let(:default_port) { 5672 }
17
18
  let(:host) { "localhost" }
18
- let(:port) { 5672 }
19
+ let(:port) { default_port }
19
20
  let(:rabbitmq_settings) {
20
21
  {
21
- "host" => host,
22
- "port" => port,
22
+ "host" => host
23
23
  }
24
24
  }
25
25
  let(:instance) {
@@ -27,6 +27,22 @@ describe LogStash::PluginMixins::RabbitMQConnection do
27
27
  }
28
28
  let(:hare_info) { instance.instance_variable_get(:@hare_info) }
29
29
 
30
+ shared_examples_for 'it sets the addresses correctly' do
31
+ let(:file) { Stud::Temporary.file }
32
+ let(:path) { file.path }
33
+ let(:host) {%w(host01 host02 host03)}
34
+
35
+ it "should set addresses to the expected value" do
36
+ host.each_with_index do |each_host, index|
37
+ expect(instance.rabbitmq_settings[:addresses][index]).to eql("#{each_host}:#{port}")
38
+ end
39
+ end
40
+
41
+ it "should insert the correct number of address entries" do
42
+ expect(instance.rabbitmq_settings[:addresses].length).to eql(host.count)
43
+ end
44
+ end
45
+
30
46
  describe "rabbitmq_settings" do
31
47
  let(:file) { Stud::Temporary.file }
32
48
  let(:path) { file.path }
@@ -59,12 +75,13 @@ describe LogStash::PluginMixins::RabbitMQConnection do
59
75
  expect(instance.rabbitmq_settings[:tls_certificate_password]).to eql(rabbitmq_settings["ssl_certificate_password"])
60
76
  end
61
77
 
62
- it "should set hosts to the expected value " do
63
- expect(instance.rabbitmq_settings[:hosts][0]).to eql(host)
64
- end
78
+ it_behaves_like 'it sets the addresses correctly'
79
+
80
+ context 'with a custom port' do
81
+ let(:port) { 123 }
82
+ let(:rabbitmq_settings) { super.merge({"port" => port})}
65
83
 
66
- it "should only insert a single host entry" do
67
- expect(instance.rabbitmq_settings[:hosts].length).to eql(1)
84
+ it_behaves_like 'it sets the addresses correctly'
68
85
  end
69
86
  end
70
87
 
@@ -79,21 +96,25 @@ describe LogStash::PluginMixins::RabbitMQConnection do
79
96
  end
80
97
 
81
98
  end
82
- describe "rabbitmq_settings multiple hosts" do
83
- let(:file) { Stud::Temporary.file }
84
- let(:path) { file.path }
85
- after { File.unlink(path)}
86
99
 
87
- let(:rabbitmq_settings) { super.merge({"host" => ["host01", "host02", "host03"]}) }
100
+ describe "rabbitmq_settings with multiple hosts" do
101
+ it_behaves_like 'it sets the addresses correctly'
102
+
103
+ context 'with a custom port' do
104
+ let(:port) { 999 }
105
+ let(:rabbitmq_settings) { super.merge({"port" => port})}
88
106
 
89
- it "should set hosts to the expected value" do
90
- expect(instance.rabbitmq_settings[:hosts][0]).to eql("host01")
91
- expect(instance.rabbitmq_settings[:hosts][1]).to eql("host02")
92
- expect(instance.rabbitmq_settings[:hosts][2]).to eql("host03")
107
+ it_behaves_like 'it sets the addresses correctly'
93
108
  end
94
109
 
95
- it "should insert 3 host entries" do
96
- expect(instance.rabbitmq_settings[:hosts].length).to eql(3)
110
+ context 'when ports are set in the host definition' do
111
+ let(:host) { %w(host01:4444 host02:4445 host03:4446)}
112
+
113
+ it "should set the address correctly" do
114
+ expect(instance.rabbitmq_settings[:addresses][0]).to eql("host01:4444")
115
+ expect(instance.rabbitmq_settings[:addresses][1]).to eql("host02:4445")
116
+ expect(instance.rabbitmq_settings[:addresses][2]).to eql("host03:4446")
117
+ end
97
118
  end
98
119
  end
99
120
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-integration-rabbitmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.1
4
+ version: 7.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-14 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -103,17 +103,17 @@ dependencies:
103
103
  - !ruby/object:Gem::Dependency
104
104
  requirement: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - ">="
106
+ - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '0'
108
+ version: '2.0'
109
109
  name: logstash-devutils
110
110
  prerelease: false
111
111
  type: :development
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">="
114
+ - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0'
116
+ version: '2.0'
117
117
  - !ruby/object:Gem::Dependency
118
118
  requirement: !ruby/object:Gem::Requirement
119
119
  requirements:
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  version: '0'
219
219
  requirements: []
220
220
  rubyforge_project:
221
- rubygems_version: 2.6.11
221
+ rubygems_version: 2.6.13
222
222
  signing_key:
223
223
  specification_version: 4
224
224
  summary: Integration with RabbitMQ - input and output plugins