march_hare 2.0.0.rc4-java → 2.0.0.rc5-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: 2f065caf463f688b529731afb0836d0e82f521df
4
- data.tar.gz: 4eea56b6d2f68dfa448770b844a084a34f4e8661
3
+ metadata.gz: c3751b35f7f4b24f8b9025947c7434302377ddde
4
+ data.tar.gz: 9e704b59d72ff697d2719d763c8018cbbe7019cd
5
5
  SHA512:
6
- metadata.gz: 94d6f44bba40d0b97299f02f856a9f8fea49b50ed007c2c8e67daaa1ec7d573447d3b8ff6144df74611adf6690fbcb1a9888b8baaf5f069e96335f7a0118e9a0
7
- data.tar.gz: be9226fe597a26584fd7099c9f1d23a421778fb65077605cea34c616712d10a306333a458c7ca0806b980016788d33645102cf256b288775e22f42bafca43cc3
6
+ metadata.gz: 1401bc111360744377a3d1eb46104caa6613bbc0607fd57edd02edefa1aaa3a556b6a95efc1f34f7f6f62bd56122fe80f59da9345f2c81679dedd49edce4b284
7
+ data.tar.gz: 30f4e4bf8d075b88595166cd7b6668f2cd119536478a622f6600bfb51da1a61b70112211c35985a3085c101df3d9908e06855314f97075eb49bb04cd7a60b6df
@@ -188,7 +188,7 @@ module MarchHare
188
188
 
189
189
  self.recover_prefetch_setting
190
190
  self.recover_exchanges
191
- # this includes recovering bindings
191
+ # # this includes bindings recovery
192
192
  self.recover_queues
193
193
  self.recover_consumers
194
194
  self.increment_recoveries_counter
@@ -218,7 +218,12 @@ module MarchHare
218
218
  #
219
219
  def recover_exchanges
220
220
  @exchanges.values.each do |x|
221
- x.recover_from_network_failure
221
+ begin
222
+ x.recover_from_network_failure
223
+ rescue Exception => e
224
+ # TODO: logger
225
+ $stderr.puts "Caught exception when recovering exchange #{x.name}"
226
+ end
222
227
  end
223
228
  end
224
229
 
@@ -226,7 +231,12 @@ module MarchHare
226
231
  # Recovery feature.
227
232
  def recover_queues
228
233
  @queues.values.each do |q|
229
- q.recover_from_network_failure
234
+ begin
235
+ q.recover_from_network_failure
236
+ rescue Exception => e
237
+ # TODO: logger
238
+ $stderr.puts "Caught exception when recovering queue #{q.name}"
239
+ end
230
240
  end
231
241
  end
232
242
 
@@ -234,14 +244,19 @@ module MarchHare
234
244
  # Recovery feature.
235
245
  def recover_consumers
236
246
  @consumers.values.each do |c|
237
- self.unregister_consumer(c)
238
- c.recover_from_network_failure
247
+ begin
248
+ self.unregister_consumer(c)
249
+ c.recover_from_network_failure
250
+ rescue Exception => e
251
+ # TODO: logger
252
+ $stderr.puts "Caught exception when recovering consumer #{c.consumer_tag}"
253
+ end
239
254
  end
240
255
  end
241
256
 
242
257
  # @private
243
258
  def increment_recoveries_counter
244
- @recoveries_counter.increment
259
+ @recoveries_counter.increment_and_get
245
260
  end
246
261
 
247
262
  attr_reader :recoveries_counter
@@ -805,6 +820,12 @@ module MarchHare
805
820
  self.add_return_listener(BlockReturnListener.from(block))
806
821
  end
807
822
 
823
+ # Defines a publisher confirm handler
824
+ # @see http://rubymarchhare.info/articles/exchanges.html Exchanges and Publishers guide
825
+ def on_confirm(&block)
826
+ self.add_confirm_listener(BlockConfirmListener.from(block))
827
+ end
828
+
808
829
  def method_missing(selector, *args)
809
830
  @delegate.__send__(selector, *args)
810
831
  end
@@ -814,6 +835,27 @@ module MarchHare
814
835
  # Implementation
815
836
  #
816
837
 
838
+ # @private
839
+ class BlockConfirmListener
840
+ include com.rabbitmq.client.ConfirmListener
841
+
842
+ def self.from(block)
843
+ new(block)
844
+ end
845
+
846
+ def initialize(block)
847
+ @block = block
848
+ end
849
+
850
+ def handleAck(delivery_tag, multiple)
851
+ @block.call(:ack, delivery_tag, multiple)
852
+ end
853
+
854
+ def handleNack(delivery_tag, multiple)
855
+ @block.call(:nack, delivery_tag, multiple)
856
+ end
857
+ end
858
+
817
859
  # @private
818
860
  class BlockReturnListener
819
861
  include com.rabbitmq.client.ReturnListener
@@ -38,6 +38,9 @@ module MarchHare
38
38
 
39
39
  # Raised when RabbitMQ closes network connection before
40
40
  # finalizing the connection, typically indicating authentication failure.
41
+ #
42
+ # RabbitMQ versions beyond 3.2 use a better defined authentication failure
43
+ # notifications.
41
44
  class PossibleAuthenticationFailureError < Exception
42
45
  attr_reader :username, :vhost
43
46
 
@@ -45,10 +48,19 @@ module MarchHare
45
48
  @username = username
46
49
  @vhost = vhost
47
50
 
48
- super("RabbitMQ closed TCP connection before authentication succeeded: this usually means authentication failure due to misconfiguration or that RabbitMQ version does not support AMQP 0.9.1. Please check your configuration. Username: #{username}, vhost: #{vhost}, password length: #{password_length}")
51
+ super("Authentication with RabbitMQ failed or RabbitMQ version used does not support AMQP 0-9-1. Username: #{username}, vhost: #{vhost}, password length: #{password_length}. Please check your configuration.")
49
52
  end
50
53
  end
51
54
 
55
+ # Raised when RabbitMQ 3.2+ reports authentication
56
+ # failure before closing TCP connection.
57
+ class AuthenticationFailureError < PossibleAuthenticationFailureError
58
+ attr_reader :username, :vhost
59
+
60
+ def initialize(username, vhost, password_length)
61
+ super(username, vhost, password_length)
62
+ end
63
+ end
52
64
 
53
65
  class PreconditionFailed < ChannelLevelException
54
66
  end
@@ -7,6 +7,7 @@ module MarchHare
7
7
  #
8
8
  # @see http://rubymarchhare.info/articles/exchanges.html Exchanges and Publishing guide
9
9
  # @see http://rubymarchhare.info/articles/extensions.html RabbitMQ Extensions guide
10
+ # @see Queue#bind
10
11
  class Exchange
11
12
  # @return [String] Exchange name
12
13
  attr_reader :name
@@ -17,6 +18,23 @@ module MarchHare
17
18
  # @return [Symbol]
18
19
  attr_reader :type
19
20
 
21
+ # Instantiates a new exchange.
22
+ #
23
+ # @param [Channel] channel Channel to declare exchange on
24
+ # @params [String] name Exchange name
25
+ # @params [Hash] options ({}) Exchange and declaration attributes
26
+ #
27
+ # @options opts :type [Symbol, String] Exchange type
28
+ # @options opts :durable [Boolean] (false) Will the exchange be durable?
29
+ # @options opts :auto_delete [Boolean] (false) Will the exchange be auto-deleted?
30
+ # @options opts :passive [Boolean] (false) Should passive declaration be used?
31
+ #
32
+ # @see MarchHare::Channel#default_exchange
33
+ # @see MarchHare::Channel#fanout
34
+ # @see MarchHare::Channel#topic
35
+ # @see MarchHare::Channel#direct
36
+ # @see MarchHare::Channel#headers
37
+ # @see MarchHare::Channel#exchange
20
38
  def initialize(channel, name, options = {})
21
39
  raise ArgumentError, "exchange channel cannot be nil" if channel.nil?
22
40
  raise ArgumentError, "exchange name cannot be nil" if name.nil?
@@ -146,7 +164,16 @@ module MarchHare
146
164
  # @private
147
165
  def recover_from_network_failure
148
166
  # puts "Recovering exchange #{@name} from network failure"
149
- declare! unless predefined?
167
+ unless predefined?
168
+ begin
169
+ declare!
170
+
171
+ @channel.register_exchange(self)
172
+ rescue Exception => e
173
+ # TODO: use a logger
174
+ puts "Caught #{e.inspect} while redeclaring and registering exchange #{@name}!"
175
+ end
176
+ end
150
177
  end
151
178
  end
152
179
  end
@@ -224,6 +224,11 @@ module MarchHare
224
224
  # Implementation
225
225
  #
226
226
 
227
+ # @return [Boolean] true if this queue is a pre-defined one (amq.direct, amq.fanout, amq.match and so on)
228
+ def predefined?
229
+ @name.start_with?("amq.")
230
+ end
231
+
227
232
  # @private
228
233
  def declare!
229
234
  response = if @options[:passive]
@@ -242,15 +247,9 @@ module MarchHare
242
247
  @channel.deregister_queue_named(old_name)
243
248
  end
244
249
 
245
- # puts "Recovering queue #{@name}"
246
- begin
247
- declare!
250
+ declare! if !predefined?
248
251
 
249
- @channel.register_queue(self)
250
- rescue Exception => e
251
- # TODO: use a logger
252
- puts "Caught #{e.inspect} while redeclaring and registering #{@name}!"
253
- end
252
+ @channel.register_queue(self)
254
253
  recover_bindings
255
254
  end
256
255
 
@@ -6,6 +6,7 @@ require "march_hare/thread_pools"
6
6
  module MarchHare
7
7
  java_import com.rabbitmq.client.ConnectionFactory
8
8
  java_import com.rabbitmq.client.Connection
9
+ java_import com.rabbitmq.client.BlockedListener
9
10
 
10
11
  # Connection to a RabbitMQ node.
11
12
  #
@@ -135,6 +136,11 @@ module MarchHare
135
136
  end
136
137
  alias connected? open?
137
138
 
139
+ # @return [Boolean] true if this channel is closed
140
+ def closed?
141
+ !@connection.open?
142
+ end
143
+
138
144
  # Defines a shutdown event callback. Shutdown events are
139
145
  # broadcasted when a connection is closed, either explicitly
140
146
  # or forcefully, or due to a network/peer failure.
@@ -147,6 +153,22 @@ module MarchHare
147
153
  sh
148
154
  end
149
155
 
156
+ # Defines a connection.blocked handler
157
+ def on_blocked(&block)
158
+ self.add_blocked_listener(BlockBlockedUnblockedListener.for_blocked(block))
159
+ end
160
+
161
+ # Defines a connection.unblocked handler
162
+ def on_unblocked(&block)
163
+ self.add_blocked_listener(BlockBlockedUnblockedListener.for_unblocked(block))
164
+ end
165
+
166
+ # Clears all callbacks defined with #on_blocked and #on_unblocked.
167
+ def clear_blocked_connection_callbacks
168
+ @connection.clear_blocked_listeners
169
+ end
170
+
171
+
150
172
  # @private
151
173
  def add_automatic_recovery_hook
152
174
  fn = Proc.new do |_, signal|
@@ -178,8 +200,25 @@ module MarchHare
178
200
  @thread_pool = ThreadPools.dynamically_growing
179
201
  self.recover_shutdown_hooks
180
202
 
181
- @channels.each do |id, ch|
182
- ch.automatically_recover(self, @connection)
203
+ # sorting channels by id means that the cases like the following:
204
+ #
205
+ # ch1 = conn.create_channel
206
+ # ch2 = conn.create_channel
207
+ #
208
+ # x = ch1.topic("logs", :durable => false)
209
+ # q = ch2.queue("", :exclusive => true)
210
+ #
211
+ # q.bind(x)
212
+ #
213
+ # will recover correctly because exchanges and queues will be recovered
214
+ # in the order the user expects and before bindings.
215
+ @channels.sort_by {|id, _| id}.each do |id, ch|
216
+ begin
217
+ ch.automatically_recover(self, @connection)
218
+ rescue Exception, java.io.IOException => e
219
+ # TODO: logging
220
+ $stderr.puts e
221
+ end
183
222
  end
184
223
  end
185
224
 
@@ -319,6 +358,8 @@ module MarchHare
319
358
  raise ConnectionRefused.new("Connection to #{@cf.host}:#{@cf.port} refused")
320
359
  rescue java.net.UnknownHostException => e
321
360
  raise ConnectionRefused.new("Connection to #{@cf.host}:#{@cf.port} refused: host unknown")
361
+ rescue com.rabbitmq.client.AuthenticationFailureException => e
362
+ raise AuthenticationFailureError.new(@cf.username, @cf.virtual_host, @cf.password.bytesize)
322
363
  rescue com.rabbitmq.client.PossibleAuthenticationFailureException => e
323
364
  raise PossibleAuthenticationFailureError.new(@cf.username, @cf.virtual_host, @cf.password.bytesize)
324
365
  end
@@ -356,5 +397,44 @@ module MarchHare
356
397
  return Proc.new { MarchHare::ThreadPools.fixed_of_size(n) }
357
398
  end
358
399
  end
400
+
401
+ # Ruby blocks-based BlockedListener that handles
402
+ # connection.blocked and connection.unblocked.
403
+ # @private
404
+ class BlockBlockedUnblockedListener
405
+ include com.rabbitmq.client.BlockedListener
406
+
407
+ def self.for_blocked(block)
408
+ new(block, noop_fn1)
409
+ end
410
+
411
+ def self.for_unblocked(block)
412
+ new(noop_fn0, block)
413
+ end
414
+
415
+ # Returns a no-op function of arity 0.
416
+ def self.noop_fn0
417
+ Proc.new {}
418
+ end
419
+
420
+ # Returns a no-op function of arity 1.
421
+ def self.noop_fn1
422
+ Proc.new { |_| }
423
+ end
424
+
425
+ def initialize(on_blocked, on_unblocked)
426
+ @blocked = on_blocked
427
+ @unblocked = on_unblocked
428
+ end
429
+
430
+ def handle_blocked(reason)
431
+ @blocked.call(reason)
432
+ end
433
+
434
+ def handle_unblocked()
435
+ @unblocked.call()
436
+ end
437
+ end
438
+
359
439
  end
360
440
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module MarchHare
4
- VERSION = "2.0.0.rc4"
4
+ VERSION = "2.0.0.rc5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: march_hare
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc4
4
+ version: 2.0.0.rc5
5
5
  platform: java
6
6
  authors:
7
7
  - Theo Hultberg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-25 00:00:00.000000000 Z
12
+ date: 2013-11-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: RabbitMQ client for JRuby built around the official RabbitMQ Java client
15
15
  email:
@@ -56,8 +56,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: 1.3.1
57
57
  requirements: []
58
58
  rubyforge_project: march_hare
59
- rubygems_version: 2.1.5
59
+ rubygems_version: 2.1.9
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: RabbitMQ client for JRuby built around the official RabbitMQ Java client
63
63
  test_files: []
64
+ has_rdoc: