beetle 0.2.9.4 → 0.2.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/beetle.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "beetle"
3
- s.version = "0.2.9.4"
3
+ s.version = "0.2.9.5"
4
4
 
5
5
  s.required_rubygems_version = ">= 1.3.1"
6
6
  s.authors = ["Stefan Kaes", "Pascal Friederich", "Ali Jelveh", "Sebastian Roebke"]
data/examples/rpc.rb CHANGED
@@ -9,13 +9,13 @@ Beetle.config.servers = "localhost:5672, localhost:5673"
9
9
 
10
10
  client = Beetle::Client.new
11
11
 
12
- # register a durable queue named 'test'
13
- # this implicitly registers a durable topic exchange called 'test'
12
+ # register a durable queue named 'echo'
13
+ # this implicitly registers a durable topic exchange called 'echo'
14
14
  client.register_queue(:echo)
15
15
  client.register_message(:echo)
16
16
 
17
17
  if ARGV.include?("--server")
18
- # register a handler for the test message, listing on queue "test"
18
+ # register a handler for the echo message, listing on queue "echo"
19
19
  # echoing all data sent to it
20
20
  client.register_handler(:echo) do |m|
21
21
  # send data back to publisher
@@ -111,9 +111,10 @@ end
111
111
  Then /^the redis master of the beetle handler should be "([^\"]*)"$/ do |redis_name|
112
112
  Beetle.config.servers = "localhost:5672" # rabbitmq
113
113
  Beetle.config.logger.level = Logger::INFO
114
- client = Beetle::Client.new
115
- client.register_queue(:echo)
116
- client.register_message(:echo)
114
+ client = Beetle::Client.new.configure :auto_delete => true do |config|
115
+ config.queue(:echo)
116
+ config.message(:echo)
117
+ end
117
118
  assert_equal TestDaemons::Redis[redis_name].ip_with_port, client.rpc(:echo, 'nil').second
118
119
  end
119
120
 
@@ -33,12 +33,12 @@ module Beetle
33
33
  end
34
34
 
35
35
  def publish_with_failover(exchange_name, message_name, data, opts) #:nodoc:
36
- tries = @servers.size
36
+ tries = @servers.size * 2
37
37
  logger.debug "Beetle: sending #{message_name}"
38
38
  published = 0
39
39
  opts = Message.publishing_options(opts)
40
40
  begin
41
- select_next_server
41
+ select_next_server if tries.even?
42
42
  bind_queues_for_exchange(exchange_name)
43
43
  logger.debug "Beetle: trying to send message #{message_name}:#{opts[:message_id]} to #{@server}"
44
44
  exchange(exchange_name).publish(data, opts)
@@ -46,8 +46,11 @@ module Beetle
46
46
  published = 1
47
47
  rescue *bunny_exceptions
48
48
  stop!
49
- mark_server_dead
50
49
  tries -= 1
50
+ # retry same server on receiving the first exception for it (might have been a normal restart)
51
+ # in this case you'll see either a broken pipe or a forced connection shutdown error
52
+ retry if tries.odd?
53
+ mark_server_dead
51
54
  retry if tries > 0
52
55
  logger.error "Beetle: message could not be delivered: #{message_name}"
53
56
  raise NoMessageSent.new
@@ -64,8 +67,9 @@ module Beetle
64
67
  opts = Message.publishing_options(opts)
65
68
  loop do
66
69
  break if published.size == 2 || @servers.empty? || published == @servers
70
+ tries = 0
71
+ select_next_server
67
72
  begin
68
- select_next_server
69
73
  next if published.include? @server
70
74
  bind_queues_for_exchange(exchange_name)
71
75
  logger.debug "Beetle: trying to send #{message_name}:#{opts[:message_id]} to #{@server}"
@@ -74,6 +78,7 @@ module Beetle
74
78
  logger.debug "Beetle: message sent (#{published})!"
75
79
  rescue *bunny_exceptions
76
80
  stop!
81
+ retry if (tries += 1) == 1
77
82
  mark_server_dead
78
83
  end
79
84
  end
@@ -122,6 +122,9 @@ module Beetle
122
122
  Beetle::reraise_expectation_errors!
123
123
  # swallow all exceptions
124
124
  logger.error "Beetle: internal error during message processing: #{$!}: #{$!.backtrace.join("\n")}"
125
+ ensure
126
+ # support amqp metrics logging if we have it
127
+ logger.agent.flush if logger.respond_to?(:agent)
125
128
  end
126
129
  end
127
130
  end
@@ -79,12 +79,12 @@ module Beetle
79
79
  @pub.servers << "localhost:3333"
80
80
  raising_exchange = mock("raising exchange")
81
81
  nice_exchange = mock("nice exchange")
82
- @pub.stubs(:exchange).with("mama-exchange").returns(raising_exchange).then.returns(nice_exchange)
82
+ @pub.stubs(:exchange).with("mama-exchange").returns(raising_exchange).then.returns(raising_exchange).then.returns(nice_exchange)
83
83
 
84
- raising_exchange.expects(:publish).raises(Bunny::ConnectionError)
84
+ raising_exchange.expects(:publish).raises(Bunny::ConnectionError).twice
85
85
  nice_exchange.expects(:publish)
86
86
  @pub.expects(:set_current_server).twice
87
- @pub.expects(:stop!).once
87
+ @pub.expects(:stop!).twice
88
88
  @pub.expects(:mark_server_dead).once
89
89
  @pub.publish_with_failover("mama-exchange", "mama", @data, @opts)
90
90
  end
@@ -112,6 +112,8 @@ module Beetle
112
112
  @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
113
113
  e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
114
114
  @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
115
+ e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
116
+ @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
115
117
  e.expects(:publish).in_sequence(redundant)
116
118
 
117
119
  assert_equal 1, @pub.publish_with_redundancy("mama-exchange", "mama", @data, @opts)
@@ -127,6 +129,10 @@ module Beetle
127
129
  e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
128
130
  @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
129
131
  e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
132
+ @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
133
+ e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
134
+ @pub.expects(:exchange).with("mama-exchange").returns(e).in_sequence(redundant)
135
+ e.expects(:publish).raises(Bunny::ConnectionError).in_sequence(redundant)
130
136
 
131
137
  assert_raises Beetle::NoMessageSent do
132
138
  @pub.publish_with_redundancy("mama-exchange", "mama", @data, @opts)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 115
4
+ hash: 113
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 9
10
- - 4
11
- version: 0.2.9.4
10
+ - 5
11
+ version: 0.2.9.5
12
12
  platform: ruby
13
13
  authors:
14
14
  - Stefan Kaes
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-11-22 00:00:00 +01:00
22
+ date: 2010-11-30 00:00:00 +01:00
23
23
  default_executable: beetle
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency