beetle 0.3.0.rc.10 → 0.3.0.rc.13

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.
data/beetle.gemspec CHANGED
@@ -35,16 +35,16 @@ Gem::Specification.new do |s|
35
35
  s.add_runtime_dependency("uuid4r", [">= 0.1.2"])
36
36
  s.add_runtime_dependency("bunny", ["= 0.7.8"])
37
37
  s.add_runtime_dependency("redis", ["= 2.2.2"])
38
- s.add_runtime_dependency("hiredis", ["= 0.3.2"])
39
- s.add_runtime_dependency("amq-client", ["= 0.8.5"])
40
- s.add_runtime_dependency("amq-protocol", ["= 0.8.3"])
41
- s.add_runtime_dependency("amqp", ["= 0.8.2"])
38
+ s.add_runtime_dependency("hiredis", ["= 0.4.4"])
39
+ s.add_runtime_dependency("amq-client", ["= 0.9.1"])
40
+ s.add_runtime_dependency("amq-protocol", ["= 0.9.0"])
41
+ s.add_runtime_dependency("amqp", ["= 0.9.2"])
42
42
  s.add_runtime_dependency("activesupport", [">= 2.3.4"])
43
43
  s.add_runtime_dependency("eventmachine_httpserver", [">= 0.2.1"])
44
44
  s.add_runtime_dependency("daemons", [">= 1.0.10"])
45
45
  s.add_development_dependency("rake", [">= 0.8.7"])
46
46
  s.add_development_dependency("mocha", [">= 0"])
47
- s.add_development_dependency("rcov", [">= 0"])
47
+ s.add_development_dependency("rcov", ["~> 0.9.10"])
48
48
  s.add_development_dependency("cucumber", [">= 0.7.2"])
49
49
  s.add_development_dependency("daemon_controller", [">= 0"])
50
50
  end
data/examples/simple.rb CHANGED
@@ -15,7 +15,7 @@ Beetle.config.logger.level = Logger::INFO
15
15
 
16
16
  # setup client
17
17
  client = Beetle::Client.new
18
- client.register_queue(:test)
18
+ client.register_queue(:test, :arguments => {"x-message-ttl" => 60 * 1000})
19
19
  client.register_message(:test)
20
20
 
21
21
  # purge the test queue
data/lib/beetle/client.rb CHANGED
@@ -149,9 +149,10 @@ module Beetle
149
149
 
150
150
  # this is a convenience method to configure exchanges, queues, messages and handlers
151
151
  # with a common set of options. allows one to call all register methods without the
152
- # register_ prefix. returns self.
152
+ # register_ prefix. returns self. if the passed in block has no parameters, the block
153
+ # will be evaluated in the context of the client configurator.
153
154
  #
154
- # Example:
155
+ # Example: (block with config argument)
155
156
  # client = Beetle.client.new.configure :exchange => :foobar do |config|
156
157
  # config.queue :q1, :key => "foo"
157
158
  # config.queue :q2, :key => "bar"
@@ -160,8 +161,24 @@ module Beetle
160
161
  # config.handler :q1 { puts "got foo"}
161
162
  # config.handler :q2 { puts "got bar"}
162
163
  # end
163
- def configure(options={}) #:yields: config
164
- yield Configurator.new(self, options)
164
+ #
165
+ # Example: (block without config argument)
166
+ # client = Beetle.client.new.configure :exchange => :foobar do
167
+ # queue :q1, :key => "foo"
168
+ # queue :q2, :key => "bar"
169
+ # message :foo
170
+ # message :bar
171
+ # handler :q1 { puts "got foo"}
172
+ # handler :q2 { puts "got bar"}
173
+ # end
174
+ #
175
+ def configure(options={}, &block)
176
+ configurator = Configurator.new(self, options)
177
+ if block.arity == 1
178
+ yield configurator
179
+ else
180
+ configurator.instance_eval &block
181
+ end
165
182
  self
166
183
  end
167
184
 
@@ -223,18 +240,22 @@ module Beetle
223
240
  end
224
241
 
225
242
  # traces queues without consuming them. useful for debugging message flow.
226
- def trace(queue_names=self.queues.keys, &block)
243
+ def trace(queue_names=self.queues.keys, tracer=nil, &block)
227
244
  queues_to_trace = self.queues.slice(*queue_names)
228
245
  queues_to_trace.each do |name, opts|
229
246
  opts.merge! :durable => false, :auto_delete => true, :amqp_name => queue_name_for_tracing(opts[:amqp_name])
230
247
  end
231
- register_handler(queue_names) do |msg|
232
- puts "-----===== new message =====-----"
233
- puts "SERVER: #{msg.server}"
234
- puts "HEADER: #{msg.header.inspect}"
235
- puts "MSGID: #{msg.msg_id}"
236
- puts "DATA: #{msg.data}"
237
- end
248
+ tracer ||=
249
+ lambda do |msg|
250
+ puts "-----===== new message =====-----"
251
+ puts "SERVER: #{msg.server}"
252
+ puts "HEADER: #{msg.header.attributes[:headers].inspect}"
253
+ puts "EXCHANGE: #{msg.header.method.exchange}"
254
+ puts "KEY: #{msg.header.method.routing_key}"
255
+ puts "MSGID: #{msg.msg_id}"
256
+ puts "DATA: #{msg.data}"
257
+ end
258
+ register_handler(queue_names){|msg| tracer.call msg }
238
259
  listen_queues(queue_names, &block)
239
260
  end
240
261
 
@@ -83,7 +83,7 @@ module Beetle
83
83
  # called when handler execution raised an exception and no error callback was
84
84
  # specified when the handler instance was created
85
85
  def error(exception)
86
- logger.error "Beetle: handler execution raised an exception: #{exception}"
86
+ logger.error "Beetle: handler execution raised an exception: #{exception.class}(#{exception.message})"
87
87
  end
88
88
 
89
89
  # called when message processing has finally failed (i.e., the number of allowed
@@ -1,3 +1,3 @@
1
1
  module Beetle
2
- VERSION = "0.3.0.rc.10"
2
+ VERSION = "0.3.0.rc.13"
3
3
  end
data/lib/beetle.rb CHANGED
@@ -40,7 +40,7 @@ module Beetle
40
40
  # AMQP options for exchange creation
41
41
  EXCHANGE_CREATION_KEYS = [:auto_delete, :durable, :internal, :nowait, :passive]
42
42
  # AMQP options for queue creation
43
- QUEUE_CREATION_KEYS = [:passive, :durable, :exclusive, :auto_delete, :no_wait]
43
+ QUEUE_CREATION_KEYS = [:passive, :durable, :exclusive, :auto_delete, :no_wait, :arguments]
44
44
  # AMQP options for queue bindings
45
45
  QUEUE_BINDING_KEYS = [:key, :no_wait]
46
46
  # AMQP options for message publishing
@@ -151,6 +151,16 @@ module Beetle
151
151
  @client.configure(options) {|config| assert_equal 42, config}
152
152
  end
153
153
 
154
+ test "configure should eval a passed block without arguments in the context of the configurator" do
155
+ options = {:exchange => :foobar}
156
+ m = "mock"
157
+ m.expects(:foo).returns(42)
158
+ Client::Configurator.expects(:new).with(@client, options).returns(m)
159
+ value = nil
160
+ @client.configure(options) { value = foo }
161
+ assert_equal 42, value
162
+ end
163
+
154
164
  test "a configurator should forward all known registration methods to the client" do
155
165
  options = {:foo => :bar}
156
166
  config = Client::Configurator.new(@client, options)
@@ -353,7 +363,7 @@ module Beetle
353
363
  client = Client.new
354
364
  client.register_queue("test")
355
365
  sub = client.send(:subscriber)
356
- sub.expects(:register_handler).with(client.queues.keys, {}, nil).yields(stub_everything("message"))
366
+ sub.expects(:register_handler).with(client.queues.keys, {}, nil).yields(message_stub_for_tracing)
357
367
  sub.expects(:listen_queues)
358
368
  client.stubs(:puts)
359
369
  client.trace
@@ -369,11 +379,19 @@ module Beetle
369
379
  client.register_queue("test")
370
380
  client.register_queue("irrelevant")
371
381
  sub = client.send(:subscriber)
372
- sub.expects(:register_handler).with(["test"], {}, nil).yields(stub_everything("message"))
382
+ sub.expects(:register_handler).with(["test"], {}, nil).yields(message_stub_for_tracing)
373
383
  sub.expects(:listen_queues).with(["test"])
374
384
  client.stubs(:puts)
375
385
  client.trace(["test"])
376
386
  end
377
387
 
388
+ def message_stub_for_tracing
389
+ header_stub = stub_everything("header")
390
+ header_stub.stubs(:method).returns(stub_everything("method"))
391
+ header_stub.stubs(:attributes).returns(stub_everything("attributes"))
392
+ msg_stub = stub_everything("message")
393
+ msg_stub.stubs(:header).returns(header_stub)
394
+ msg_stub
395
+ end
378
396
  end
379
397
  end
@@ -80,7 +80,7 @@ module Beetle
80
80
  test "default implementation of error and process and failure and completed should not crash" do
81
81
  handler = Handler.create(lambda {})
82
82
  handler.process
83
- handler.error('barfoo')
83
+ handler.error(StandardError.new('barfoo'))
84
84
  handler.failure('razzmatazz')
85
85
  handler.completed
86
86
  end
@@ -224,12 +224,12 @@ module Beetle
224
224
  end
225
225
 
226
226
  test "binding a queue should create it using the config and bind it to the exchange with the name specified" do
227
- @client.register_queue("some_queue", :exchange => "some_exchange", :key => "haha.#")
227
+ @client.register_queue("some_queue", :exchange => "some_exchange", :key => "haha.#", :arguments => {"foo" => "fighter"})
228
228
  @pub.expects(:exchange).with("some_exchange").returns(:the_exchange)
229
229
  q = mock("queue")
230
230
  q.expects(:bind).with(:the_exchange, {:key => "haha.#"})
231
231
  m = mock("Bunny")
232
- m.expects(:queue).with("some_queue", :durable => true, :passive => false, :auto_delete => false, :exclusive => false).returns(q)
232
+ m.expects(:queue).with("some_queue", :durable => true, :passive => false, :auto_delete => false, :exclusive => false, :arguments => {"foo" => "fighter"}).returns(q)
233
233
  @pub.expects(:bunny).returns(m)
234
234
 
235
235
  @pub.send(:queue, "some_queue")
@@ -128,12 +128,12 @@ module Beetle
128
128
  end
129
129
 
130
130
  test "binding a queue should create it using the config and bind it to the exchange with the name specified" do
131
- @client.register_queue("some_queue", "durable" => true, "exchange" => "some_exchange", "key" => "haha.#")
131
+ @client.register_queue("some_queue", "durable" => true, "exchange" => "some_exchange", "key" => "haha.#", "arguments" => {"schmu" => 5})
132
132
  @sub.expects(:exchange).with("some_exchange").returns(:the_exchange)
133
133
  q = mock("queue")
134
134
  q.expects(:bind).with(:the_exchange, {:key => "haha.#"})
135
135
  m = mock("MQ")
136
- m.expects(:queue).with("some_queue", :durable => true, :passive => false, :auto_delete => false, :exclusive => false).returns(q)
136
+ m.expects(:queue).with("some_queue", :durable => true, :passive => false, :auto_delete => false, :exclusive => false, :arguments => {"schmu" => 5}).returns(q)
137
137
  @sub.expects(:channel).returns(m)
138
138
 
139
139
  @sub.send(:queue, "some_queue")
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424049
5
- prerelease: 6
4
+ hash: 3659109081
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
9
  - 0
10
10
  - rc
11
- - 10
12
- version: 0.3.0.rc.10
11
+ - 13
12
+ version: 0.3.0.rc.13
13
13
  platform: ruby
14
14
  authors:
15
15
  - Stefan Kaes
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2011-10-31 00:00:00 +01:00
24
+ date: 2012-03-06 00:00:00 +01:00
25
25
  default_executable: beetle
26
26
  dependencies:
27
27
  - !ruby/object:Gem::Dependency
@@ -80,12 +80,12 @@ dependencies:
80
80
  requirements:
81
81
  - - "="
82
82
  - !ruby/object:Gem::Version
83
- hash: 23
83
+ hash: 7
84
84
  segments:
85
85
  - 0
86
- - 3
87
- - 2
88
- version: 0.3.2
86
+ - 4
87
+ - 4
88
+ version: 0.4.4
89
89
  type: :runtime
90
90
  version_requirements: *id004
91
91
  - !ruby/object:Gem::Dependency
@@ -96,12 +96,12 @@ dependencies:
96
96
  requirements:
97
97
  - - "="
98
98
  - !ruby/object:Gem::Version
99
- hash: 53
99
+ hash: 57
100
100
  segments:
101
101
  - 0
102
- - 8
103
- - 5
104
- version: 0.8.5
102
+ - 9
103
+ - 1
104
+ version: 0.9.1
105
105
  type: :runtime
106
106
  version_requirements: *id005
107
107
  - !ruby/object:Gem::Dependency
@@ -112,12 +112,12 @@ dependencies:
112
112
  requirements:
113
113
  - - "="
114
114
  - !ruby/object:Gem::Version
115
- hash: 57
115
+ hash: 59
116
116
  segments:
117
117
  - 0
118
- - 8
119
- - 3
120
- version: 0.8.3
118
+ - 9
119
+ - 0
120
+ version: 0.9.0
121
121
  type: :runtime
122
122
  version_requirements: *id006
123
123
  - !ruby/object:Gem::Dependency
@@ -128,12 +128,12 @@ dependencies:
128
128
  requirements:
129
129
  - - "="
130
130
  - !ruby/object:Gem::Version
131
- hash: 59
131
+ hash: 63
132
132
  segments:
133
133
  - 0
134
- - 8
134
+ - 9
135
135
  - 2
136
- version: 0.8.2
136
+ version: 0.9.2
137
137
  type: :runtime
138
138
  version_requirements: *id007
139
139
  - !ruby/object:Gem::Dependency
@@ -220,12 +220,14 @@ dependencies:
220
220
  requirement: &id013 !ruby/object:Gem::Requirement
221
221
  none: false
222
222
  requirements:
223
- - - ">="
223
+ - - ~>
224
224
  - !ruby/object:Gem::Version
225
- hash: 3
225
+ hash: 47
226
226
  segments:
227
227
  - 0
228
- version: "0"
228
+ - 9
229
+ - 10
230
+ version: 0.9.10
229
231
  type: :development
230
232
  version_requirements: *id013
231
233
  - !ruby/object:Gem::Dependency
@@ -373,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
373
375
  requirements: []
374
376
 
375
377
  rubyforge_project:
376
- rubygems_version: 1.6.2
378
+ rubygems_version: 1.3.7
377
379
  signing_key:
378
380
  specification_version: 3
379
381
  summary: High Availability AMQP Messaging with Redundant Queues