logstash-output-rabbitmq 1.0.0-java → 1.0.1-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
  SHA1:
3
- metadata.gz: b08471687f256720f2c7c35dbda03c185639848b
4
- data.tar.gz: 2fa26fc00f0cafc76300787286ac0ae0f7ceaa53
3
+ metadata.gz: 196e13c70544a6e6b7429647f627d2909ca4b5df
4
+ data.tar.gz: 3e6871d57fdcb9afde9a531058728e0f57b252f8
5
5
  SHA512:
6
- metadata.gz: 18bf67935083fc252e633b027883b5557b11822482357f1d10696f24650288e7a70b3e10dd21975d2fbdffab16bac1521c2be3eabbe46f916f750d19f71b7f68
7
- data.tar.gz: e58ba7fcc3327a74c590ccdcc566f840e251cc32081a4b2c945d0590418e6ac94ff8c51a745f8181a51fe3359329cc67eb5ff1942b55f923439d60ae7943eb04
6
+ metadata.gz: 28810116ec622545494f279bb88107edf73e74d8f9886f533a8cf51c2e42dd096255ebcffbbefd8ae97b64031a024c6279128923280a53f5ad31e0b6c3fec87b
7
+ data.tar.gz: 4088c7f9ebdf63d9458effc176127df3c4fa3a8cd9acb6299d3e60ac47c4efb71f58935be1d49db8a341673bba6e29c5768f284e3a69871551b8938cd9ed4d62
data/CHANGELOG.md CHANGED
@@ -0,0 +1,2 @@
1
+ * 1.0.1
2
+ - Fix connection leakage/failure to reconnect on disconnect
@@ -35,26 +35,28 @@ class LogStash::Outputs::RabbitMQ
35
35
  end
36
36
 
37
37
  def publish_serialized(event, message)
38
- begin
39
- if @connected.get
40
- @x.publish(message, :routing_key => event.sprintf(@key), :properties => { :persistent => @persistent })
41
- else
42
- @logger.warn("Tried to send a message, but not connected to RabbitMQ.")
43
- end
44
- rescue MarchHare::Exception, IOError, com.rabbitmq.client.AlreadyClosedException => e
45
- @connected.set(false)
46
- n = 10
38
+ attempt_publish_serialized(event, message)
39
+ rescue MarchHare::Exception, IOError, com.rabbitmq.client.AlreadyClosedException => e
40
+ @connected.set(false)
41
+ n = 10
47
42
 
48
- @logger.error("RabbitMQ connection error: #{e.message}. Will attempt to reconnect in #{n} seconds...",
49
- :exception => e,
50
- :backtrace => e.backtrace)
51
- return if terminating?
43
+ @logger.error("RabbitMQ connection error: #{e.message}. Will attempt to reconnect in #{n} seconds...",
44
+ :exception => e,
45
+ :backtrace => e.backtrace)
46
+ return if terminating?
52
47
 
53
- sleep n
48
+ sleep n
54
49
 
55
- connect
56
- declare_exchange
57
- retry
50
+ connect
51
+ @x = declare_exchange
52
+ retry
53
+ end
54
+
55
+ def attempt_publish_serialized(event, message)
56
+ if @connected.get
57
+ @x.publish(message, :routing_key => event.sprintf(@key), :properties => { :persistent => @persistent })
58
+ else
59
+ @logger.warn("Tried to send a message, but not connected to RabbitMQ.")
58
60
  end
59
61
  end
60
62
 
@@ -105,7 +107,7 @@ class LogStash::Outputs::RabbitMQ
105
107
  @connection_url = "#{proto}://#{@user}@#{@host}:#{@port}#{vhost}/#{@queue}"
106
108
 
107
109
  begin
108
- @conn = MarchHare.connect(@settings)
110
+ @conn = MarchHare.connect(@settings) unless @conn && @conn.open?
109
111
 
110
112
  @logger.debug("Connecting to RabbitMQ. Settings: #{@settings.inspect}, queue: #{@queue.inspect}")
111
113
 
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-rabbitmq'
4
- s.version = '1.0.0'
4
+ s.version = '1.0.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Push events to a RabbitMQ exchange"
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -69,4 +69,64 @@ describe LogStash::Outputs::RabbitMQ do
69
69
  end
70
70
 
71
71
  end
72
+
73
+ # TODO: Redo all this
74
+ # This is a crazy test to fix an urgent bug. It tests that we actually to change the
75
+ # store exchange value when an exception happens
76
+ # This should be a small number of lines, but until we refactor we must jump through hoops
77
+ # to put the plugin in the proper state and extract the proper state to test
78
+ describe "retrying a publish" do
79
+ let(:settings) {
80
+ {
81
+ "host" => "localhost",
82
+ "exchange_type" => "topic",
83
+ "exchange" => "foo",
84
+ "key" => "%{foo}"
85
+ }
86
+ }
87
+ let(:event) { LogStash::Event.new("foo" => "bar")}
88
+
89
+ subject { LogStash::Outputs::RabbitMQ.new(settings) }
90
+
91
+ before do
92
+ allow(subject).to receive(:connect) {
93
+ subject.instance_variable_get(:@connected).set(true)
94
+ }
95
+
96
+ exchange_invocation = 0
97
+
98
+ @most_recent_exchange = nil
99
+
100
+ allow(subject).to receive(:declare_exchange) do
101
+ exchange_invocation += 1
102
+ @most_recent_exchange = double("exchange #{exchange_invocation}")
103
+ end
104
+
105
+ subject.register
106
+ end
107
+
108
+ context "when the connection aborts once" do
109
+ before do
110
+ i = 0
111
+ allow(subject).to receive(:attempt_publish_serialized) do
112
+ i+=1
113
+ if i == 1 # Raise an exception once
114
+ raise MarchHare::Exception, "First"
115
+ else
116
+ "nope"
117
+ end
118
+ end
119
+
120
+ subject.publish_serialized(event, "hello")
121
+ end
122
+
123
+ it "should re-declare the exchange" do
124
+ expect(subject).to have_received(:declare_exchange).twice
125
+ end
126
+
127
+ it "should set the exchange to the second double" do
128
+ expect(subject.instance_variable_get(:@x)).to eql(@most_recent_exchange)
129
+ end
130
+ end
131
+ end
72
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-rabbitmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.1.9
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Push events to a RabbitMQ exchange