bmabey-rosetta_queue 0.2.0 → 0.3.3
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/History.txt +6 -3
- data/README.rdoc +1 -193
- data/Rakefile +7 -1
- data/cucumber.yml +1 -1
- data/examples/sample_amqp_consumer.rb +13 -3
- data/examples/sample_amqp_fanout_consumer.rb +6 -3
- data/examples/sample_amqp_fanout_producer.rb +3 -2
- data/examples/sample_amqp_producer.rb +2 -1
- data/features/filtering.feature +13 -13
- data/features/messaging.feature +28 -20
- data/features/step_definitions/common_messaging_steps.rb +54 -17
- data/features/step_definitions/filtering_steps.rb +2 -2
- data/features/step_definitions/point_to_point_steps.rb +19 -9
- data/features/step_definitions/publish_subscribe_steps.rb +22 -8
- data/features/support/env.rb +2 -0
- data/features/support/sample_consumers.rb +6 -6
- data/lib/rosetta_queue.rb +1 -0
- data/lib/rosetta_queue/adapter.rb +6 -6
- data/lib/rosetta_queue/adapters/amqp.rb +6 -3
- data/lib/rosetta_queue/adapters/amqp_evented.rb +22 -22
- data/lib/rosetta_queue/adapters/amqp_synch.rb +42 -36
- data/lib/rosetta_queue/adapters/base.rb +3 -3
- data/lib/rosetta_queue/adapters/beanstalk.rb +5 -5
- data/lib/rosetta_queue/adapters/fake.rb +5 -5
- data/lib/rosetta_queue/adapters/null.rb +9 -9
- data/lib/rosetta_queue/adapters/stomp.rb +25 -12
- data/lib/rosetta_queue/base.rb +2 -2
- data/lib/rosetta_queue/consumer.rb +4 -4
- data/lib/rosetta_queue/consumer_managers/base.rb +8 -6
- data/lib/rosetta_queue/consumer_managers/evented.rb +5 -5
- data/lib/rosetta_queue/consumer_managers/threaded.rb +4 -4
- data/lib/rosetta_queue/core_ext/string.rb +3 -3
- data/lib/rosetta_queue/core_ext/time.rb +20 -0
- data/lib/rosetta_queue/destinations.rb +6 -6
- data/lib/rosetta_queue/filters.rb +8 -8
- data/lib/rosetta_queue/logger.rb +2 -2
- data/lib/rosetta_queue/message_handler.rb +10 -4
- data/lib/rosetta_queue/producer.rb +2 -2
- data/lib/rosetta_queue/spec_helpers/hash.rb +3 -3
- data/lib/rosetta_queue/spec_helpers/helpers.rb +8 -8
- data/lib/rosetta_queue/spec_helpers/publishing_matchers.rb +26 -26
- data/spec/rosetta_queue/adapter_spec.rb +27 -27
- data/spec/rosetta_queue/adapters/amqp_synchronous_spec.rb +21 -1
- data/spec/rosetta_queue/adapters/beanstalk_spec.rb +3 -3
- data/spec/rosetta_queue/adapters/fake_spec.rb +6 -6
- data/spec/rosetta_queue/adapters/null_spec.rb +5 -5
- data/spec/rosetta_queue/adapters/shared_adapter_behavior.rb +4 -4
- data/spec/rosetta_queue/adapters/shared_fanout_behavior.rb +1 -1
- data/spec/rosetta_queue/adapters/stomp_spec.rb +39 -18
- data/spec/rosetta_queue/consumer_managers/evented_spec.rb +6 -6
- data/spec/rosetta_queue/consumer_managers/shared_manager_behavior.rb +3 -3
- data/spec/rosetta_queue/consumer_managers/threaded_spec.rb +5 -5
- data/spec/rosetta_queue/consumer_spec.rb +13 -13
- data/spec/rosetta_queue/core_ext/string_spec.rb +3 -3
- data/spec/rosetta_queue/destinations_spec.rb +8 -8
- data/spec/rosetta_queue/filters_spec.rb +16 -16
- data/spec/rosetta_queue/producer_spec.rb +15 -15
- data/spec/rosetta_queue/shared_messaging_behavior.rb +6 -6
- metadata +3 -2
@@ -95,7 +95,7 @@ module RosettaQueue::Gateway
|
|
95
95
|
|
96
96
|
before(:each) do
|
97
97
|
@queue = mock("Bunny::Queue", :pop => @msg, :publish => true, :unsubscribe => true)
|
98
|
-
Bunny.stub!(:new).and_return(@conn = mock("Bunny::Client", :queue => @queue, :exchange => @exchange, :status => :connected))
|
98
|
+
Bunny.stub!(:new).and_return(@conn = mock("Bunny::Client", :queue => @queue, :exchange => @exchange, :status => :connected, :stop => nil))
|
99
99
|
@queue.stub!(:subscribe).and_yield(@msg)
|
100
100
|
@handler = mock("handler", :on_message => true, :destination => :foo)
|
101
101
|
@exchange = SynchExchange::DirectExchange.new({:user => 'user', :password => 'pass', :host => 'host', :opts => {:vhost => "foo"}})
|
@@ -251,6 +251,26 @@ module RosettaQueue::Gateway
|
|
251
251
|
# end
|
252
252
|
# end
|
253
253
|
|
254
|
+
# describe SynchExchange::AmqpAdapterProxy do
|
255
|
+
|
256
|
+
# before(:each) do
|
257
|
+
# @queue = mock("Queue", :ack => nil)
|
258
|
+
# @proxy = SynchExchange::AmqpAdapterProxy.new(@queue)
|
259
|
+
# end
|
260
|
+
|
261
|
+
# context "#ack" do
|
262
|
+
|
263
|
+
# it "should delegate to AMQP queue object" do
|
264
|
+
# # expect
|
265
|
+
# @queue.should_receive(:ack)
|
266
|
+
|
267
|
+
# # when
|
268
|
+
# @proxy.ack
|
269
|
+
# end
|
270
|
+
|
271
|
+
# end
|
272
|
+
# end
|
273
|
+
|
254
274
|
end
|
255
275
|
end
|
256
276
|
end
|
@@ -23,7 +23,7 @@ module RosettaQueue
|
|
23
23
|
def do_receiving_once
|
24
24
|
@adapter.receive_once
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should delete messages once received" do
|
28
28
|
when_receiving_once {
|
29
29
|
@msg_obj.should_receive(:delete)
|
@@ -37,11 +37,11 @@ module RosettaQueue
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should delete message during receive" do
|
40
|
-
when_receiving {
|
40
|
+
when_receiving {
|
41
41
|
@msg_obj.should_receive(:delete)
|
42
42
|
}
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -3,7 +3,7 @@ require 'rosetta_queue/adapters/fake'
|
|
3
3
|
|
4
4
|
module RosettaQueue
|
5
5
|
module Gateway
|
6
|
-
|
6
|
+
|
7
7
|
describe FakeAdapter do
|
8
8
|
|
9
9
|
describe "#queues" do
|
@@ -16,7 +16,7 @@ module RosettaQueue
|
|
16
16
|
adapter.queues.should == ['queue 1', 'queue 2']
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe "#messages_sent_to" do
|
21
21
|
|
22
22
|
it "should return the message bodies that were delivered to the specified queue" do
|
@@ -41,7 +41,7 @@ module RosettaQueue
|
|
41
41
|
# then
|
42
42
|
adapter.messages_sent_to('queue').should == ['Filtered Message']
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should return all the message's bodies when nil is passed in at the queue" do
|
46
46
|
# given
|
47
47
|
adapter = FakeAdapter.new
|
@@ -52,7 +52,7 @@ module RosettaQueue
|
|
52
52
|
# then
|
53
53
|
results.should == ['message 1', 'message 2']
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should return an empty array when no messages have been delivered" do
|
57
57
|
# given
|
58
58
|
adapter = FakeAdapter.new
|
@@ -62,11 +62,11 @@ module RosettaQueue
|
|
62
62
|
# then
|
63
63
|
results.should == []
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -6,25 +6,25 @@ module RosettaQueue
|
|
6
6
|
|
7
7
|
|
8
8
|
describe NullAdapter do
|
9
|
-
|
9
|
+
|
10
10
|
def null_adapter
|
11
11
|
NullAdapter.new({:user => 'user', :password => 'password', :host => 'host', :port => 'port'})
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
%w[disconnect receive receive_with send_message subscribe unsubscribe].each do |adapter_method|
|
15
15
|
it "should respond to ##{adapter_method}" do
|
16
16
|
null_adapter.should respond_to(adapter_method)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should raise an error when #receive is called" do
|
21
21
|
running { null_adapter.receive }.should raise_error
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should raise an error when #receive_with is called" do
|
25
25
|
running { null_adapter.receive_with('consumer') }.should raise_error
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -14,7 +14,7 @@ module RosettaQueue
|
|
14
14
|
def do_receiving_with_handler
|
15
15
|
@adapter.receive_with(@handler)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe "#receive_once" do
|
19
19
|
|
20
20
|
it "should return the message from the connection" do
|
@@ -22,7 +22,7 @@ module RosettaQueue
|
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
describe "#receive_with" do
|
27
27
|
|
28
28
|
it "should look up the destination defined on the class" do
|
@@ -30,9 +30,9 @@ module RosettaQueue
|
|
30
30
|
Destinations.should_receive(:lookup).with(:foo).and_return("foo")
|
31
31
|
}
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -18,7 +18,7 @@ module RosettaQueue
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it_should_behave_like "an adapter"
|
21
|
-
|
21
|
+
|
22
22
|
describe "#send_message" do
|
23
23
|
it "should delegate to the connection" do
|
24
24
|
# need this hack since the stomp client overrides #send
|
@@ -26,9 +26,9 @@ module RosettaQueue
|
|
26
26
|
@args = args
|
27
27
|
end
|
28
28
|
def @conn.sent_args ; @args end
|
29
|
-
|
29
|
+
|
30
30
|
after_publishing {
|
31
|
-
@conn.sent_args.should == ['queue', 'message', 'options']
|
31
|
+
@conn.sent_args.should == ['queue', 'message', 'options']
|
32
32
|
}
|
33
33
|
end
|
34
34
|
end
|
@@ -38,16 +38,16 @@ module RosettaQueue
|
|
38
38
|
def do_receiving_once
|
39
39
|
@adapter.receive_once("/queue/foo", {:persistent => false})
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should subscribe to queue" do
|
43
|
-
when_receiving_once {
|
44
|
-
@conn.should_receive("subscribe").with("/queue/foo", {:persistent => false})
|
43
|
+
when_receiving_once {
|
44
|
+
@conn.should_receive("subscribe").with("/queue/foo", {:persistent => false})
|
45
45
|
}
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should unsubscribe from queue" do
|
49
|
-
when_receiving_once {
|
50
|
-
@conn.should_receive("unsubscribe").with("/queue/foo")
|
49
|
+
when_receiving_once {
|
50
|
+
@conn.should_receive("unsubscribe").with("/queue/foo")
|
51
51
|
}
|
52
52
|
end
|
53
53
|
end
|
@@ -64,8 +64,8 @@ module RosettaQueue
|
|
64
64
|
when_receiving_with_handler {
|
65
65
|
@conn.should_receive(:ack)
|
66
66
|
}
|
67
|
-
end
|
68
|
-
|
67
|
+
end
|
68
|
+
|
69
69
|
describe "no ack" do
|
70
70
|
|
71
71
|
before(:each) do
|
@@ -74,15 +74,15 @@ module RosettaQueue
|
|
74
74
|
|
75
75
|
it "should not acknowledge client" do
|
76
76
|
when_receiving_with_handler {
|
77
|
-
@conn.should_not_receive(:ack)
|
77
|
+
@conn.should_not_receive(:ack)
|
78
78
|
}
|
79
|
-
end
|
79
|
+
end
|
80
80
|
|
81
|
-
end
|
81
|
+
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
describe "disconnect" do
|
85
|
-
|
85
|
+
|
86
86
|
def do_disconnecting
|
87
87
|
@adapter.disconnect(@handler)
|
88
88
|
end
|
@@ -98,8 +98,29 @@ module RosettaQueue
|
|
98
98
|
@conn.should_receive("disconnect")
|
99
99
|
}
|
100
100
|
end
|
101
|
-
|
102
|
-
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe StompAdapterProxy do
|
105
|
+
|
106
|
+
before(:each) do
|
107
|
+
@adapter = mock("StompAdapter", :ack => nil)
|
108
|
+
@proxy = StompAdapterProxy.new(@adapter, "foo")
|
109
|
+
end
|
110
|
+
|
111
|
+
context "#ack" do
|
112
|
+
|
113
|
+
it "should delegate to AMQP queue object" do
|
114
|
+
# expect
|
115
|
+
@adapter.should_receive(:ack).with("foo")
|
116
|
+
|
117
|
+
# when
|
118
|
+
@proxy.ack
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
103
124
|
end
|
104
125
|
end
|
105
126
|
end
|
@@ -7,7 +7,7 @@ module RosettaQueue
|
|
7
7
|
|
8
8
|
before(:each) do
|
9
9
|
Stomp::Connection.stub!(:open).and_return(nil)
|
10
|
-
@consumer = mock("test_consumer_1", :receive => true,
|
10
|
+
@consumer = mock("test_consumer_1", :receive => true,
|
11
11
|
:connection => mock("AmqpAdapter", :subscribe => true, :unsubscribe => nil, :disconnect => nil),
|
12
12
|
:unsubscribe => true, :disconnect => true)
|
13
13
|
Consumer.stub!(:new).and_return(@consumer)
|
@@ -24,7 +24,7 @@ module RosettaQueue
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "starting" do
|
27
|
-
|
27
|
+
|
28
28
|
def do_process
|
29
29
|
@manager.start
|
30
30
|
end
|
@@ -34,7 +34,7 @@ module RosettaQueue
|
|
34
34
|
@manager.consumers.each_value { |cons| cons.should_receive(:receive) }
|
35
35
|
}
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "stopping" do
|
@@ -42,15 +42,15 @@ module RosettaQueue
|
|
42
42
|
def do_process
|
43
43
|
@manager.stop
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should stop consumers" do
|
47
47
|
during_process {
|
48
48
|
EM.should_receive(:stop)
|
49
49
|
}
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
@@ -19,7 +19,7 @@ module RosettaQueue
|
|
19
19
|
it_should_behave_like "a consumer manager"
|
20
20
|
|
21
21
|
describe "threading" do
|
22
|
-
|
22
|
+
|
23
23
|
before do
|
24
24
|
@manager.stub!(:join_threads)
|
25
25
|
@manager.stub!(:monitor_threads)
|
@@ -31,9 +31,9 @@ module RosettaQueue
|
|
31
31
|
it "should load subscriptions into threads on start" do
|
32
32
|
during_process {Thread.should_receive(:new).with(:"spec/mocks/mock", @consumer).and_return(@thread)}
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe "shutting down" do
|
36
|
-
|
36
|
+
|
37
37
|
def do_process
|
38
38
|
@manager.start
|
39
39
|
@manager.stop
|
@@ -42,10 +42,10 @@ module RosettaQueue
|
|
42
42
|
it "should shut threaded subscriptions down on stop" do
|
43
43
|
during_process do
|
44
44
|
@consumer.should_receive(:disconnect)
|
45
|
-
@thread.should_receive(:kill)
|
45
|
+
@thread.should_receive(:kill)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
module RosettaQueue
|
4
4
|
describe Consumer do
|
5
|
-
|
5
|
+
|
6
6
|
class TestConsumer
|
7
7
|
include MessageHandler
|
8
8
|
|
@@ -16,14 +16,14 @@ module RosettaQueue
|
|
16
16
|
|
17
17
|
before(:each) do
|
18
18
|
@message = mock("message", "headers" => "foo", "body" => "message body")
|
19
|
-
@adapter = mock("adpater", :subscribe => true, :unsubscribe => true, :disconnect => true, :receive_with => TestConsumer.new,
|
19
|
+
@adapter = mock("adpater", :subscribe => true, :unsubscribe => true, :disconnect => true, :receive_with => TestConsumer.new,
|
20
20
|
:receive_once => @message.body, :ack => true)
|
21
21
|
Adapter.stub!(:instance).and_return(@adapter)
|
22
22
|
Destinations.stub!(:lookup).and_return("/queue/foo")
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it_should_behave_like "a messaging gateway object"
|
26
|
-
|
26
|
+
|
27
27
|
attr_reader :adapter
|
28
28
|
def gateway
|
29
29
|
@gateway ||= Consumer.new(TestConsumer.new)
|
@@ -33,30 +33,30 @@ module RosettaQueue
|
|
33
33
|
before(:each) do
|
34
34
|
@consumer = Consumer.new( @message_handler = TestConsumer.new)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def when_receiving
|
38
38
|
yield if block_given?
|
39
39
|
@consumer.receive
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should pass message handler onto the adpater with #receive" do
|
43
|
-
when_receiving {
|
43
|
+
when_receiving {
|
44
44
|
@adapter.should_receive("receive_with").with(@message_handler)
|
45
45
|
}
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
|
50
50
|
describe ".delete" do
|
51
51
|
|
52
|
-
before(:each) do
|
52
|
+
before(:each) do
|
53
53
|
@adapter.stub!(:delete)
|
54
|
-
Destinations.stub!(:lookup).and_return("/queue/foo")
|
55
|
-
end
|
54
|
+
Destinations.stub!(:lookup).and_return("/queue/foo")
|
55
|
+
end
|
56
56
|
|
57
57
|
it "should look up the destination" do
|
58
58
|
# expect
|
59
|
-
Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
|
59
|
+
Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
|
60
60
|
|
61
61
|
# when
|
62
62
|
Consumer.delete(:test_queue_passed_in)
|
@@ -80,7 +80,7 @@ module RosettaQueue
|
|
80
80
|
|
81
81
|
it "should look up the destination" do
|
82
82
|
when_receiving {
|
83
|
-
Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
|
83
|
+
Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
|
84
84
|
}
|
85
85
|
end
|
86
86
|
|