amq-client 0.7.0.alpha31 → 0.7.0.alpha32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ __dir = File.dirname(File.expand_path(__FILE__))
5
+ require File.join(__dir, "..", "example_helper")
6
+
7
+ amq_client_example "Declare a new fanout exchange" do |connection|
8
+ channel = AMQ::Client::Channel.new(connection, 1)
9
+ channel.open do
10
+ puts "Channel #{channel.id} is now open!"
11
+
12
+ channel.on_error do |ch, close|
13
+ puts "Handling a channel-level exception: #{close.reply_text}"
14
+ end
15
+
16
+ EventMachine.add_timer(0.4) do
17
+ # these two definitions result in a race condition. For sake of this example,
18
+ # however, it does not matter. Whatever definition succeeds first, 2nd one will
19
+ # cause a channel-level exception (because attributes are not identical)
20
+ AMQ::Client::Queue.new(connection, channel, "amqpgem.examples.channel_exception").declare(false, false, false, true) do |queue|
21
+ puts "#{queue.name} is ready to go"
22
+ end
23
+
24
+ AMQ::Client::Queue.new(connection, channel, "amqpgem.examples.channel_exception").declare(false, true, false, false) do |queue|
25
+ puts "#{queue.name} is ready to go"
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ show_stopper = Proc.new do
32
+ $stdout.puts "Stopping..."
33
+
34
+ connection.close {
35
+ EM.stop { exit }
36
+ }
37
+ end
38
+
39
+ Signal.trap "INT", show_stopper
40
+ EM.add_timer(2, show_stopper)
41
+ end
@@ -26,21 +26,16 @@ module AMQ
26
26
 
27
27
  host.class_eval do
28
28
 
29
- #
30
- # Behaviors
31
- #
32
-
33
- include Entity
34
-
35
-
36
-
37
29
  #
38
30
  # API
39
31
  #
40
32
 
41
33
  attr_accessor :logger
42
34
  attr_accessor :settings
43
- attr_accessor :connection
35
+
36
+ # @return [Array<#call>]
37
+ attr_reader :callbacks
38
+
44
39
 
45
40
  # The locale defines the language in which the server will send reply texts.
46
41
  #
@@ -172,7 +167,9 @@ module AMQ
172
167
  # Behaviors
173
168
  #
174
169
 
175
- include AMQ::Client::Openable
170
+ include Openable
171
+ include Callbacks
172
+
176
173
 
177
174
  extend RegisterEntityMixin
178
175
 
@@ -367,6 +364,23 @@ module AMQ
367
364
 
368
365
 
369
366
 
367
+
368
+ # @group Error handling
369
+
370
+ # Defines a callback that will be executed when channel is closed after
371
+ # channel-level exception. Only one callback can be added (the one added last
372
+ # replaces previous added ones).
373
+ #
374
+ # @api public
375
+ def on_error(&block)
376
+ self.redefine_callback(:error, &block)
377
+ end
378
+
379
+ # @endgroup
380
+
381
+
382
+
383
+
370
384
  # Handles connection.start.
371
385
  #
372
386
  # @api plugin
@@ -420,8 +434,7 @@ module AMQ
420
434
 
421
435
  closed!
422
436
  # TODO: use proper exception class, provide protocol class (we know conn_close.class_id and conn_close.method_id) as well!
423
- error = RuntimeError.new(conn_close.reply_text)
424
- self.error(error)
437
+ self.exec_callback_yielding_self(:error, conn_close)
425
438
  end
426
439
 
427
440
 
@@ -139,7 +139,7 @@ module AMQ
139
139
  def initialize
140
140
  # Be careful with default values for #ruby hashes: h = Hash.new(Array.new); h[:key] ||= 1
141
141
  # won't assign anything to :key. MK.
142
- @callbacks = {}
142
+ @callbacks = Hash.new
143
143
 
144
144
  self.logger = self.class.logger
145
145
 
@@ -137,6 +137,7 @@ module AMQ
137
137
 
138
138
  @frames = Array.new
139
139
  @channels = Hash.new
140
+ @callbacks = Hash.new
140
141
 
141
142
  opening!
142
143
 
@@ -359,9 +360,9 @@ module AMQ
359
360
 
360
361
 
361
362
  def reset
362
- @size = 0
363
- @payload = ""
364
- @frames = Array.new
363
+ @size = 0
364
+ @payload = ""
365
+ @frames = Array.new
365
366
 
366
367
  @chunk_buffer = ""
367
368
  @connection_deferrable = EventMachine::DefaultDeferrable.new
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Client
3
- VERSION = "0.7.0.alpha31"
3
+ VERSION = "0.7.0.alpha32"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amq-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3702664430
4
+ hash: -3702664340
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 0
10
10
  - alpha
11
- - 31
12
- version: 0.7.0.alpha31
11
+ - 32
12
+ version: 0.7.0.alpha32
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jakub Stastny
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2011-05-29 00:00:00 Z
23
+ date: 2011-05-31 00:00:00 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: eventmachine
@@ -117,6 +117,7 @@ files:
117
117
  - examples/eventmachine_adapter/connection_failure_callback.rb
118
118
  - examples/eventmachine_adapter/connection_failure_exception.rb
119
119
  - examples/eventmachine_adapter/connection_loss_handler.rb
120
+ - examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb
120
121
  - examples/eventmachine_adapter/example_helper.rb
121
122
  - examples/eventmachine_adapter/exchange_declare.rb
122
123
  - examples/eventmachine_adapter/extensions/rabbitmq/handling_confirm_select_ok.rb