beetle 0.2.11 → 0.2.12
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 +1 -1
- data/features/support/env.rb +3 -1
- data/features/support/test_daemons/redis.conf.erb +2 -2
- data/lib/beetle/base.rb +1 -1
- data/lib/beetle/client.rb +16 -10
- data/lib/beetle/subscriber.rb +11 -8
- data/lib/beetle.rb +1 -0
- data/test/beetle/client_test.rb +30 -11
- data/test/beetle/subscriber_test.rb +9 -7
- metadata +4 -4
data/beetle.gemspec
CHANGED
data/features/support/env.rb
CHANGED
@@ -40,7 +40,9 @@ def first_redis_configuration_client_pid
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def system_notification_log_path
|
43
|
-
tmp_path + "/system_notifications.log"
|
43
|
+
log_path = tmp_path + "/system_notifications.log"
|
44
|
+
`touch #{log_path}` unless File.exists?(log_path)
|
45
|
+
log_path
|
44
46
|
end
|
45
47
|
|
46
48
|
def tmp_path
|
@@ -185,5 +185,5 @@ glueoutputbuf yes
|
|
185
185
|
# WARNING: object sharing is experimental, don't enable this feature
|
186
186
|
# in production before of Redis 1.0-stable. Still please try this feature in
|
187
187
|
# your development environment so that we can test it better.
|
188
|
-
shareobjects no
|
189
|
-
shareobjectspoolsize 1024
|
188
|
+
# shareobjects no
|
189
|
+
# shareobjectspoolsize 1024
|
data/lib/beetle/base.rb
CHANGED
@@ -53,7 +53,7 @@ module Beetle
|
|
53
53
|
queues[name] ||=
|
54
54
|
begin
|
55
55
|
opts = @client.queues[name]
|
56
|
-
|
56
|
+
raise UnknownQueue.new("You are trying to bind a queue #{name} which is not configured!") unless opts
|
57
57
|
logger.debug("Beetle: binding queue #{name} with internal name #{opts[:amqp_name]} on server #{@server}")
|
58
58
|
queue_name = opts[:amqp_name]
|
59
59
|
creation_options = opts.slice(*QUEUE_CREATION_KEYS)
|
data/lib/beetle/client.rb
CHANGED
@@ -189,12 +189,17 @@ module Beetle
|
|
189
189
|
publisher.purge(queue_name)
|
190
190
|
end
|
191
191
|
|
192
|
-
# start listening to
|
192
|
+
# start listening to all registered queues. Calls #listen_queues internally
|
193
193
|
# runs the given block before entering the eventmachine loop.
|
194
|
-
def listen(
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
def listen(_deprecated_messages=nil, &block)
|
195
|
+
raise Error.new("Beetle::Client#listen no longer works with arguments. Please use #listen_queues(['queue1', 'queue2']) instead") if _deprecated_messages
|
196
|
+
listen_queues(&block)
|
197
|
+
end
|
198
|
+
|
199
|
+
# start listening to a list of queues (default to all registered queues).
|
200
|
+
# runs the given block before entering the eventmachine loop.
|
201
|
+
def listen_queues(queues=self.queues.keys, &block)
|
202
|
+
subscriber.listen_queues(queues, &block)
|
198
203
|
end
|
199
204
|
|
200
205
|
# stops the eventmachine loop
|
@@ -207,19 +212,20 @@ module Beetle
|
|
207
212
|
publisher.stop
|
208
213
|
end
|
209
214
|
|
210
|
-
# traces
|
211
|
-
def trace(
|
212
|
-
queues.
|
215
|
+
# traces queues without consuming them. useful for debugging message flow.
|
216
|
+
def trace(queue_names=self.queues.keys, &block)
|
217
|
+
queues_to_trace = self.queues.slice(*queue_names)
|
218
|
+
queues_to_trace.each do |name, opts|
|
213
219
|
opts.merge! :durable => false, :auto_delete => true, :amqp_name => queue_name_for_tracing(opts[:amqp_name])
|
214
220
|
end
|
215
|
-
register_handler(
|
221
|
+
register_handler(queue_names) do |msg|
|
216
222
|
puts "-----===== new message =====-----"
|
217
223
|
puts "SERVER: #{msg.server}"
|
218
224
|
puts "HEADER: #{msg.header.inspect}"
|
219
225
|
puts "MSGID: #{msg.msg_id}"
|
220
226
|
puts "DATA: #{msg.data}"
|
221
227
|
end
|
222
|
-
|
228
|
+
listen_queues(queue_names, &block)
|
223
229
|
end
|
224
230
|
|
225
231
|
# evaluate the ruby files matching the given +glob+ pattern in the context of the client instance.
|
data/lib/beetle/subscriber.rb
CHANGED
@@ -14,26 +14,25 @@ module Beetle
|
|
14
14
|
@mqs = {}
|
15
15
|
end
|
16
16
|
|
17
|
-
# the client calls this method to subscribe to
|
18
|
-
#
|
19
|
-
# things:
|
17
|
+
# the client calls this method to subscribe to a list of queues.
|
18
|
+
# this method does the following things:
|
20
19
|
#
|
21
|
-
# * creates all exchanges which have been registered for the given
|
22
|
-
# * creates and binds
|
20
|
+
# * creates all exchanges which have been registered for the given queues
|
21
|
+
# * creates and binds each listed queue queues
|
23
22
|
# * subscribes the handlers for all these queues
|
24
23
|
#
|
25
24
|
# yields before entering the eventmachine loop (if a block was given)
|
26
|
-
def
|
25
|
+
def listen_queues(queues) #:nodoc:
|
27
26
|
EM.run do
|
28
|
-
exchanges =
|
27
|
+
exchanges = exchanges_for_queues(queues)
|
29
28
|
create_exchanges(exchanges)
|
30
|
-
queues = queues_for_exchanges(exchanges)
|
31
29
|
bind_queues(queues)
|
32
30
|
subscribe_queues(queues)
|
33
31
|
yield if block_given?
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
|
37
36
|
# closes all AMQP connections and stops the eventmachine loop
|
38
37
|
def stop! #:nodoc:
|
39
38
|
if @amqp_connections.empty?
|
@@ -53,6 +52,10 @@ module Beetle
|
|
53
52
|
|
54
53
|
private
|
55
54
|
|
55
|
+
def exchanges_for_queues(queues)
|
56
|
+
@client.bindings.slice(*queues).map{|_, opts| opts.map{|opt| opt[:exchange]}}.flatten.uniq
|
57
|
+
end
|
58
|
+
|
56
59
|
def exchanges_for_messages(messages)
|
57
60
|
@client.messages.slice(*messages).map{|_, opts| opts[:exchange]}.uniq
|
58
61
|
end
|
data/lib/beetle.rb
CHANGED
data/test/beetle/client_test.rb
CHANGED
@@ -261,18 +261,26 @@ module Beetle
|
|
261
261
|
|
262
262
|
test "should delegate listening to the subscriber instance" do
|
263
263
|
client = Client.new
|
264
|
-
client.register_queue(
|
265
|
-
client.
|
266
|
-
client.
|
267
|
-
client.
|
268
|
-
client.send(:subscriber).expects(:listen).with(["a", "b"]).yields
|
269
|
-
x = 0
|
270
|
-
client.listen([:a, "b"]) { x = 5 }
|
271
|
-
assert_equal 5, x
|
264
|
+
client.register_queue("b_queue")
|
265
|
+
client.register_queue("a_queue")
|
266
|
+
client.send(:subscriber).expects(:listen_queues).with {|value| value.include?("a_queue") && value.include?("b_queue")}.yields
|
267
|
+
client.listen
|
272
268
|
end
|
273
269
|
|
274
|
-
test "trying to listen to
|
275
|
-
assert_raises(
|
270
|
+
test "trying to listen to a message is no longer supported and should raise an exception" do
|
271
|
+
assert_raises(Error) { Client.new.listen([:a])}
|
272
|
+
end
|
273
|
+
|
274
|
+
test "should delegate listening to queues to the subscriber instance" do
|
275
|
+
client = Client.new
|
276
|
+
client.register_queue(:test)
|
277
|
+
client.send(:subscriber).expects(:listen_queues).with([:test]).yields
|
278
|
+
client.listen_queues([:test])
|
279
|
+
end
|
280
|
+
|
281
|
+
test "trying to listen to an unknown queue should raise an exception" do
|
282
|
+
client = Client.new
|
283
|
+
assert_raises(UnknownQueue) { Client.new.listen_queues([:foobar])}
|
276
284
|
end
|
277
285
|
|
278
286
|
test "should delegate stop_listening to the subscriber instance" do
|
@@ -314,7 +322,7 @@ module Beetle
|
|
314
322
|
client.register_queue("test")
|
315
323
|
sub = client.send(:subscriber)
|
316
324
|
sub.expects(:register_handler).with(client.queues.keys, {}, nil).yields(stub_everything("message"))
|
317
|
-
sub.expects(:
|
325
|
+
sub.expects(:listen_queues)
|
318
326
|
client.stubs(:puts)
|
319
327
|
client.trace
|
320
328
|
test_queue_opts = client.queues["test"]
|
@@ -324,5 +332,16 @@ module Beetle
|
|
324
332
|
assert !test_queue_opts[:durable]
|
325
333
|
end
|
326
334
|
|
335
|
+
test "limiting tracing to some queues" do
|
336
|
+
client = Client.new
|
337
|
+
client.register_queue("test")
|
338
|
+
client.register_queue("irrelevant")
|
339
|
+
sub = client.send(:subscriber)
|
340
|
+
sub.expects(:register_handler).with(["test"], {}, nil).yields(stub_everything("message"))
|
341
|
+
sub.expects(:listen_queues).with(["test"])
|
342
|
+
client.stubs(:puts)
|
343
|
+
client.trace(["test"])
|
344
|
+
end
|
345
|
+
|
327
346
|
end
|
328
347
|
end
|
@@ -249,14 +249,16 @@ module Beetle
|
|
249
249
|
assert_raises(Error){ @sub.send(:subscribe, "some_queue") }
|
250
250
|
end
|
251
251
|
|
252
|
-
test "
|
253
|
-
@client.
|
254
|
-
@client.
|
252
|
+
test "listeninging on queues should use eventmachine. create exchanges. bind queues. install subscribers. and yield." do
|
253
|
+
@client.register_exchange(:an_exchange)
|
254
|
+
@client.register_queue(:a_queue, :exchange => :an_exchange)
|
255
|
+
@client.register_message(:a_message, :key => "foo", :exchange => :an_exchange)
|
256
|
+
|
255
257
|
EM.expects(:run).yields
|
256
|
-
@sub.expects(:create_exchanges).with(["
|
257
|
-
@sub.expects(:bind_queues).with(["
|
258
|
-
@sub.expects(:subscribe_queues).with(["
|
259
|
-
@sub.
|
258
|
+
@sub.expects(:create_exchanges).with(["an_exchange"])
|
259
|
+
@sub.expects(:bind_queues).with(["a_queue"])
|
260
|
+
@sub.expects(:subscribe_queues).with(["a_queue"])
|
261
|
+
@sub.listen_queues(["a_queue"]) {}
|
260
262
|
end
|
261
263
|
end
|
262
264
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beetle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 12
|
10
|
+
version: 0.2.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stefan Kaes
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-02-
|
21
|
+
date: 2011-02-17 00:00:00 +01:00
|
22
22
|
default_executable: beetle
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|