logstash-integration-rabbitmq 7.0.2-java → 7.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/input-rabbitmq.asciidoc +13 -4
- data/docs/output-rabbitmq.asciidoc +4 -2
- data/lib/logstash/inputs/rabbitmq.rb +72 -16
- data/lib/logstash/outputs/rabbitmq.rb +71 -10
- data/lib/logstash/plugin_mixins/rabbitmq_connection.rb +75 -45
- data/logstash-integration-rabbitmq.gemspec +2 -2
- data/spec/inputs/rabbitmq_spec.rb +228 -9
- data/spec/outputs/rabbitmq_spec.rb +61 -9
- data/spec/plugin_mixins/rabbitmq_connection_spec.rb +48 -23
- metadata +7 -7
@@ -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 }
|
@@ -62,6 +60,10 @@ describe LogStash::Outputs::RabbitMQ do
|
|
62
60
|
allow(connection).to receive(:on_shutdown)
|
63
61
|
allow(connection).to receive(:on_recovery_start)
|
64
62
|
allow(connection).to receive(:on_recovery)
|
63
|
+
allow(connection).to receive(:host).and_return host
|
64
|
+
allow(connection).to receive(:port).and_return port
|
65
|
+
allow(connection).to receive(:vhost).and_return nil
|
66
|
+
allow(connection).to receive(:user).and_return 'guest'
|
65
67
|
allow(channel).to receive(:exchange).and_return(exchange)
|
66
68
|
|
67
69
|
instance.register
|
@@ -84,18 +86,67 @@ describe LogStash::Outputs::RabbitMQ do
|
|
84
86
|
before do
|
85
87
|
allow(exchange).to receive(:publish).with(any_args)
|
86
88
|
allow(event).to receive(:sprintf).with(key).and_return(sprinted_key)
|
87
|
-
instance.send(:publish, event, encoded_event)
|
88
89
|
end
|
89
90
|
|
90
91
|
it "should send the correct message" do
|
92
|
+
instance.send(:publish, event, encoded_event)
|
91
93
|
expect(exchange).to have_received(:publish).with(encoded_event, anything)
|
92
94
|
end
|
93
95
|
|
94
96
|
it "should send the correct metadata" do
|
95
97
|
expected_metadata = {:routing_key => sprinted_key, :properties => {:persistent => persistent }}
|
96
98
|
|
99
|
+
instance.send(:publish, event, encoded_event)
|
100
|
+
|
97
101
|
expect(exchange).to have_received(:publish).with(anything, expected_metadata)
|
98
102
|
end
|
103
|
+
|
104
|
+
context 'with message_properties' do
|
105
|
+
let(:rabbitmq_settings) { super().merge("message_properties" => message_properties) }
|
106
|
+
let(:message_properties) { Hash.new }
|
107
|
+
context 'priority' do
|
108
|
+
let(:message_properties) { super().merge("priority" => priority) }
|
109
|
+
context 'as literal Integer value' do
|
110
|
+
let(:priority) { 3 }
|
111
|
+
it 'publishes with the constant-value priority' do
|
112
|
+
instance.send(:publish, event, encoded_event)
|
113
|
+
expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 3)))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'as literal String value' do
|
118
|
+
let(:priority) { "7" }
|
119
|
+
it 'publishes with the constant-value priority' do
|
120
|
+
instance.send(:publish, event, encoded_event)
|
121
|
+
expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 7)))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'as template value' do
|
126
|
+
let(:priority) { "%{[@metadata][priority]}" }
|
127
|
+
context 'when event expands template value' do
|
128
|
+
before do
|
129
|
+
expect(event).to receive(:sprintf).with(priority).and_return("31")
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'publishes with the priority extracted from the event' do
|
133
|
+
instance.send(:publish, event, encoded_event)
|
134
|
+
expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 31)))
|
135
|
+
end
|
136
|
+
end
|
137
|
+
context 'when event cannot expand template value' do
|
138
|
+
before do
|
139
|
+
expect(event).to receive(:sprintf).with(priority).and_return(priority)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'publishes with the priority of zero (`0`)' do
|
143
|
+
instance.send(:publish, event, encoded_event)
|
144
|
+
expect(exchange).to have_received(:publish).with(anything, hash_including(:properties => hash_including(:priority => 0)))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
99
150
|
end
|
100
151
|
|
101
152
|
context 'when an exception is encountered' do
|
@@ -124,7 +175,7 @@ describe LogStash::Outputs::RabbitMQ do
|
|
124
175
|
end
|
125
176
|
|
126
177
|
context 'when it is a TimeoutException' do
|
127
|
-
let(:exception) { TimeoutException.new }
|
178
|
+
let(:exception) { java.util.concurrent.TimeoutException.new }
|
128
179
|
it_behaves_like 'recovers from exception gracefully'
|
129
180
|
end
|
130
181
|
end
|
@@ -133,14 +184,15 @@ describe LogStash::Outputs::RabbitMQ do
|
|
133
184
|
end
|
134
185
|
|
135
186
|
|
136
|
-
describe "with a live server", :integration => true do
|
187
|
+
describe "LogStash::Outputs::RabbitMQ with a live server", :integration => true do
|
188
|
+
let(:rabbitmq_host) { ENV["RABBITMQ_HOST"] || "127.0.0.1" }
|
137
189
|
let(:klass) { LogStash::Outputs::RabbitMQ }
|
138
190
|
let(:exchange) { "myexchange" }
|
139
191
|
let(:exchange_type) { "topic" }
|
140
192
|
let(:priority) { 34 }
|
141
193
|
let(:default_plugin_config) {
|
142
194
|
{
|
143
|
-
"host" =>
|
195
|
+
"host" => rabbitmq_host,
|
144
196
|
"exchange" => exchange,
|
145
197
|
"exchange_type" => exchange_type,
|
146
198
|
"key" => "foo",
|
@@ -158,7 +210,7 @@ describe "with a live server", :integration => true do
|
|
158
210
|
instance.register
|
159
211
|
|
160
212
|
20.times do
|
161
|
-
instance.
|
213
|
+
instance.send(:connection_open?) ? break : sleep(0.1)
|
162
214
|
end
|
163
215
|
|
164
216
|
# Extra time to make sure the output can attach
|
@@ -190,12 +242,12 @@ describe "with a live server", :integration => true do
|
|
190
242
|
|
191
243
|
context "using defaults" do
|
192
244
|
it "should start, connect, and stop cleanly" do
|
193
|
-
expect(instance.
|
245
|
+
expect(instance.send(:connection_open?)).to be_truthy
|
194
246
|
end
|
195
247
|
|
196
248
|
it "should close cleanly" do
|
197
249
|
instance.close
|
198
|
-
expect(instance.
|
250
|
+
expect(instance.send(:connection_open?)).to be_falsey
|
199
251
|
end
|
200
252
|
|
201
253
|
it 'applies per message settings' do
|
@@ -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) {
|
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,12 +27,28 @@ 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 }
|
33
49
|
after { File.unlink(path)}
|
34
50
|
|
35
|
-
let(:rabbitmq_settings) { super.merge({"connection_timeout" => 123,
|
51
|
+
let(:rabbitmq_settings) { super().merge({"connection_timeout" => 123,
|
36
52
|
"heartbeat" => 456,
|
37
53
|
"ssl" => true,
|
38
54
|
"ssl_version" => "TLSv1.1",
|
@@ -40,11 +56,11 @@ describe LogStash::PluginMixins::RabbitMQConnection do
|
|
40
56
|
"ssl_certificate_password" => "123"}) }
|
41
57
|
|
42
58
|
it "should set the timeout to the expected value" do
|
43
|
-
expect(instance.rabbitmq_settings[:
|
59
|
+
expect(instance.rabbitmq_settings[:connection_timeout]).to eql(rabbitmq_settings["connection_timeout"])
|
44
60
|
end
|
45
61
|
|
46
62
|
it "should set heartbeat to the expected value" do
|
47
|
-
expect(instance.rabbitmq_settings[:
|
63
|
+
expect(instance.rabbitmq_settings[:requested_heartbeat]).to eql(rabbitmq_settings["heartbeat"])
|
48
64
|
end
|
49
65
|
|
50
66
|
it "should set tls to the expected value" do
|
@@ -59,17 +75,18 @@ 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
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
|
71
88
|
describe "ssl enabled, but no verification" do
|
72
|
-
let(:rabbitmq_settings) { super.merge({"connection_timeout" => 123,
|
89
|
+
let(:rabbitmq_settings) { super().merge({"connection_timeout" => 123,
|
73
90
|
"heartbeat" => 456,
|
74
91
|
"ssl" => true}) }
|
75
92
|
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
96
|
-
|
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
|
|
@@ -108,6 +129,10 @@ describe LogStash::PluginMixins::RabbitMQConnection do
|
|
108
129
|
allow(connection).to receive(:on_blocked)
|
109
130
|
allow(connection).to receive(:on_unblocked)
|
110
131
|
allow(connection).to receive(:on_shutdown)
|
132
|
+
allow(connection).to receive(:host).and_return host
|
133
|
+
allow(connection).to receive(:port).and_return port
|
134
|
+
allow(connection).to receive(:vhost).and_return nil
|
135
|
+
allow(connection).to receive(:user).and_return 'guest'
|
111
136
|
|
112
137
|
instance.register
|
113
138
|
end
|
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
|
4
|
+
version: 7.3.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-07 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.
|
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
|