bmabey-rosetta_queue 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -2
- data/README.rdoc +90 -18
- data/Rakefile +2 -2
- data/VERSION.yml +2 -2
- data/examples/sample_amqp_consumer.rb +35 -0
- data/examples/sample_amqp_fanout_consumer.rb +49 -0
- data/examples/sample_amqp_fanout_producer.rb +17 -0
- data/examples/sample_amqp_producer.rb +15 -0
- data/features/filtering.feature +5 -9
- data/features/messaging.feature +40 -0
- data/features/step_definitions/common_messaging_steps.rb +45 -0
- data/features/{messaging/step_definitions → step_definitions}/point_to_point_steps.rb +4 -12
- data/features/{messaging/step_definitions → step_definitions}/publish_subscribe_steps.rb +3 -3
- data/features/support/env.rb +1 -5
- data/lib/rosetta_queue/adapter.rb +14 -8
- data/lib/rosetta_queue/adapters/amqp.rb +21 -142
- data/lib/rosetta_queue/adapters/amqp_evented.rb +132 -0
- data/lib/rosetta_queue/adapters/amqp_synch.rb +117 -0
- data/lib/rosetta_queue/adapters/base.rb +1 -1
- data/lib/rosetta_queue/adapters/beanstalk.rb +3 -3
- data/lib/rosetta_queue/adapters/null.rb +2 -2
- data/lib/rosetta_queue/adapters/stomp.rb +7 -2
- data/lib/rosetta_queue/consumer.rb +8 -1
- data/lib/rosetta_queue/consumer_managers/base.rb +1 -1
- data/lib/rosetta_queue/filters.rb +1 -3
- data/lib/rosetta_queue/logger.rb +1 -1
- data/lib/rosetta_queue/producer.rb +2 -10
- data/lib/rosetta_queue/spec_helpers/helpers.rb +1 -1
- data/lib/rosetta_queue.rb +4 -1
- data/spec/rosetta_queue/adapter_spec.rb +46 -0
- data/spec/rosetta_queue/adapters/{amqp_spec.rb → amqp_synchronous_spec.rb} +109 -121
- data/spec/rosetta_queue/adapters/beanstalk_spec.rb +1 -1
- data/spec/rosetta_queue/adapters/null_spec.rb +1 -1
- data/spec/rosetta_queue/adapters/shared_adapter_behavior.rb +4 -4
- data/spec/rosetta_queue/adapters/shared_fanout_behavior.rb +7 -7
- data/spec/rosetta_queue/adapters/stomp_spec.rb +3 -3
- data/spec/rosetta_queue/consumer_spec.rb +25 -1
- data/spec/spec_helper.rb +3 -1
- metadata +18 -11
- data/features/messaging/point_to_point.feature +0 -30
- data/features/support/common_messaging_steps.rb +0 -28
data/History.txt
CHANGED
@@ -1,11 +1,32 @@
|
|
1
|
-
== 0.
|
1
|
+
== 0.2.x (git)
|
2
|
+
|
3
|
+
=== New features
|
4
|
+
=== Bufixes
|
5
|
+
|
6
|
+
== 0.2.0
|
7
|
+
=== New features
|
8
|
+
* Synchronous AMQP adapter
|
9
|
+
* Uses celldee's synchronous AMQP client, 'Bunny'.
|
10
|
+
* Added .delete method to Consumer class
|
11
|
+
* Allows user to purge a queue.
|
12
|
+
* Works for AMQP adapters only.
|
13
|
+
=== Bufixes
|
14
|
+
* client :ack now working.
|
15
|
+
|
16
|
+
== 0.1.4
|
2
17
|
|
3
18
|
=== New features
|
4
19
|
* Removed dependency on ActiveSupport and brought over needed String methods. (Derek and Matt - Greenview Data, Inc.)
|
5
20
|
* Safer shutdown in ThreadedManager (Rob Sanheim - Relevance)
|
6
21
|
* Beanstalk Adaper (David Brady - Lead Media Partners)
|
7
22
|
* Still needs some work to have it take advantage of beanstalk's subscribe functionality.
|
8
|
-
|
23
|
+
* Synchronous AMQP adapter
|
24
|
+
* Uses celldee's synchronous AMQP client, 'Bunny'.
|
25
|
+
* Added .delete method to Consumer class
|
26
|
+
* Allows user to purge a queue.
|
27
|
+
* Works for AMQP adapters only.
|
28
|
+
* Beanstalk Adaper (David Brady)
|
29
|
+
* Still needs some work to have it take advantage of beanstalk's subscribe funtionality.
|
9
30
|
|
10
31
|
== 0.1.0 / 2008-01-28 - Initial Release
|
11
32
|
RosettaQueue was realased in the wild! RQ's initial development was primarily sponsored by Alliance Health Networks (thanks!!). The original authors were Chris Wyckoff and Ben Mabey. The initial release included adapters for stomp and amqp, in addition to a null and fake adapters for testing.
|
data/README.rdoc
CHANGED
@@ -4,17 +4,28 @@ Rosetta Queue is a messaging gateway API with adapters for many messaging system
|
|
4
4
|
|
5
5
|
The adapters provided currently are for stomp, amqp, and beanstalk. We would like to add adapters for other messaging gateways. The stomp adapter has been used in production along side with Apache's ActiveMQ. The amqp adapter currently works along side RabbitMQ and passes the acceptance tests but as of yet has not been used in production.
|
6
6
|
|
7
|
+
|
8
|
+
== Authors
|
9
|
+
|
10
|
+
Ben Mabey [http://github.com/bmabey]
|
11
|
+
|
12
|
+
Chris Wyckoff [http://github.com/cwyckoff]
|
13
|
+
|
14
|
+
|
7
15
|
== Quick Tutorial
|
16
|
+
|
8
17
|
Note: The API will most likely change until we reach 1.0. We will be moving to a more concise API (i.e. queue(:test_queue) << message, etc...) We will also be changing how exceptions are handled.
|
9
18
|
|
10
19
|
When using Rosetta Queue in an application you will need to configure the queues, adapters, and filters (optional). These configurations should be placed in a file that gets loaded once when your program starts. If you are using Rails then a good place for this is config/initializers/rosetta_queue.rb.
|
11
20
|
|
12
|
-
|
21
|
+
|
22
|
+
To set up destinations for producing and consuming messages:
|
13
23
|
|
14
24
|
RosettaQueue::Destinations.define do |queue|
|
15
25
|
queue.map :test_queue, '/queue/my_test_queue'
|
16
26
|
end
|
17
27
|
|
28
|
+
|
18
29
|
Defining your adapter:
|
19
30
|
|
20
31
|
RosettaQueue::Adapter.define do |a|
|
@@ -25,6 +36,7 @@ Defining your adapter:
|
|
25
36
|
a.type = "stomp"
|
26
37
|
end
|
27
38
|
|
39
|
+
|
28
40
|
Define a logger for Rosetta Queue to use. The logger should be a standard ruby logger:
|
29
41
|
|
30
42
|
RosettaQueue.logger = Logger.new('/my_project/rosetta_queue.log')
|
@@ -76,33 +88,72 @@ It is recommended that you set your adapter to the 'null' adapter for your specs
|
|
76
88
|
Please look at the publishing matchers for more information. For examples on how to write acceptance tests for your Rosetta Queue's code please see RosettaQueue's own Cucumber features and read this {blog post}[http://www.benmabey.com/2009/02/17/using-cucumber-to-integrate-distributed-systems-and-test-messaging/].
|
77
89
|
|
78
90
|
|
91
|
+
== Adapters
|
79
92
|
|
80
|
-
|
81
|
-
----------------------------------------------------------------
|
82
|
-
Gems you will need:
|
83
|
-
cucumber, rspec, yaml, stomp, tmm1-amqp, beanstalk-client
|
93
|
+
=== AMQP
|
84
94
|
|
85
|
-
|
95
|
+
RosettaQueue comes with two AMQP adapters: a synchronous adapter and an evented one. The former uses the synchronous AMQP client "Bunny" by celldee [http://github.com/celldee/bunny] and the latter, the evented AMQP client by Aman Gupta [http://github.com/tmm1/amqp].
|
86
96
|
|
87
|
-
|
97
|
+
==== Set Up
|
88
98
|
|
89
|
-
|
90
|
-
Go to http://activemq.apache.org/download.html to download the latest version, and see http://activemq.apache.org/getting-started.html for installation and configuration instructions.
|
91
|
-
The stomp client and features should work with ApacheMQ out of the box. If you are running any ApacheMQ servers in production on your network you will want to disable the multicast autodiscovery in conf/activemq.xml. (Around lines 56 and 98.)
|
99
|
+
Install Erlang, unless already installed, and the RabbitMQ messaging broker. Mac OSX users can install from ports. Linux users should use their package manager or choice. One installed, you can launch rabbitmq by running
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
rabbitmq-server
|
102
|
+
|
103
|
+
or
|
104
|
+
|
105
|
+
rabbitmqctl start_app
|
96
106
|
|
97
|
-
rabbitmqctl add_user rosetta password
|
98
|
-
rabbitmqctl map_user_vhost rosetta /
|
99
107
|
|
100
|
-
|
108
|
+
==== Configuration
|
109
|
+
|
110
|
+
If you are using an AMQP adapter, there are some important rules when defining the adapter and mapping your destinations. Two of the basic building blocks of AMQP are queues and exchanges. Queues bind to exchanges in several different ways. A can queue bind to an exchange and requests messages that match a specific routing key, which is called 'direct exchange' and is analogous to the 'point-to-point' messaging pattern. Alternately, queues can bind to an exchange to receive all messages sent to that exchange; this is called 'fanout exchange' and is analogous to the 'publish-subscribe' pattern. So, when you want to define a simple 'direct-exchange' queue, your queue name must begin with the term "queue".
|
111
|
+
|
112
|
+
RosettaQueue::Destinations.define do |queue|
|
113
|
+
queue.map :test_queue, 'queue.my_test_queue'
|
114
|
+
end
|
115
|
+
|
116
|
+
And, when you want to define a queue that will bind to a 'fanout-exchange', your queue name must begin with the term "fanout".
|
117
|
+
|
118
|
+
RosettaQueue::Destinations.define do |queue|
|
119
|
+
queue.map :test_queue, 'fanout.my_test_queue'
|
120
|
+
end
|
121
|
+
|
122
|
+
Finally, when defining your adapter, the synchronous AMQP adapter should be defined as :*amqp_synch*, and the evented adapter as :*amqp_evented*.
|
123
|
+
|
124
|
+
==== Evented AMQP adapter
|
125
|
+
|
126
|
+
When publishing and subscribing using the evented AMQP adapter, you need to wrap that code in an event machine run block. For example, publishing a message might look like this:
|
127
|
+
|
128
|
+
EM.run do
|
129
|
+
Em.add_periodic_timer(1) do
|
130
|
+
RosettaQueue::Producer.publish(:foo, "Hello World!")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
And a sample consumer might look like this:
|
135
|
+
|
136
|
+
EM.run do
|
137
|
+
RosettaQueue::Consumer.new(MyMessageHandler.new).receive
|
138
|
+
end
|
139
|
+
|
140
|
+
Although, if you are using the evented AMQP adapter to consume messages you could simply wrap your consumers in RosettaQueue's EventedManager:
|
141
|
+
|
142
|
+
RosettaQueue::EventedManager.create do |m|
|
143
|
+
m.add(MyFirstMessageHandler.new)
|
144
|
+
m.add(MySecondMessageHandler.new)
|
145
|
+
m.add(MyThirdMessageHandler.new)
|
146
|
+
|
147
|
+
m.start
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
=== Beanstalk
|
101
152
|
|
102
153
|
You should set up and run a local instance of beanstalk for your
|
103
154
|
tests.
|
104
155
|
|
105
|
-
==== beanstalkd
|
156
|
+
==== beanstalkd
|
106
157
|
|
107
158
|
Mac OSX users can install beanstalkd from ports. Linux users should
|
108
159
|
check their package manager of choice. This is probably the optimal
|
@@ -120,7 +171,7 @@ which the specs use. You might also want to daemonize beanstalk with
|
|
120
171
|
the -d option but for testing this is not recommended, as the queue
|
121
172
|
can get stuck with old messages, which will break your specs.
|
122
173
|
|
123
|
-
==== beanstalk-client
|
174
|
+
==== beanstalk-client
|
124
175
|
|
125
176
|
You will also need the Ruby beanstalk-client gem.
|
126
177
|
|
@@ -128,4 +179,25 @@ You will also need the Ruby beanstalk-client gem.
|
|
128
179
|
|
129
180
|
|
130
181
|
|
182
|
+
== How to contribute
|
183
|
+
----------------------------------------------------------------
|
184
|
+
Gems you will need:
|
185
|
+
cucumber, rspec, yaml, stomp, amqp, bunny, beanstalk-client
|
186
|
+
|
187
|
+
You should be able to run the rspec code examples (specs) without any brokers running with autospec or 'rake spec'.
|
188
|
+
|
189
|
+
To run the cucumber features you will need the a messaging system setup that can speak stomp and AMQP. We have been using the following brokers in testing:
|
190
|
+
|
191
|
+
=== Apache ActiveMQ (for the stomp adapter)
|
192
|
+
Go to http://activemq.apache.org/download.html to download the latest version, and see http://activemq.apache.org/getting-started.html for installation and configuration instructions.
|
193
|
+
The stomp client and features should work with ApacheMQ out of the box. If you are running any ApacheMQ servers in production on your network you will want to disable the multicast autodiscovery in conf/activemq.xml. (Around lines 56 and 98.)
|
194
|
+
|
195
|
+
=== RabbitMQ (for the amqp adapter)
|
196
|
+
Download the right tar from here: http://www.rabbitmq.com/download.html and follow the installation directions that comes with it.
|
197
|
+
The features rely on a user of 'rosetta' being setup with the password of 'password' and added to the default virtualhost. You can set them up like so:
|
198
|
+
|
199
|
+
rabbitmqctl add_user rosetta password
|
200
|
+
rabbitmqctl map_user_vhost rosetta /
|
201
|
+
|
202
|
+
|
131
203
|
|
data/Rakefile
CHANGED
@@ -18,8 +18,8 @@ begin
|
|
18
18
|
s.name = "rosetta_queue"
|
19
19
|
s.rubyforge_project = "rosetta-queue"
|
20
20
|
s.summary = %Q{Messaging gateway API with adapters for many messaging systems available in Ruby.}
|
21
|
-
s.email = "
|
22
|
-
s.homepage = "http://github.com/
|
21
|
+
s.email = "cbwyckoff@gmail.com"
|
22
|
+
s.homepage = "http://github.com/cwyckoff/rosetta_queue"
|
23
23
|
s.description = %Q{Messaging gateway API with adapters for many messaging systems available in Ruby. Messaging systems can be easily switched out with a small configuration change. Code for testing on the object and application level is also provided.}
|
24
24
|
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
|
25
25
|
s.files = FileList["[A-Z]*.*", "{bin,generators,lib,features,spec}/**/*", "Rakefile", "cucumber.yml"]
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/rosetta_queue/consumer_managers/threaded')
|
4
|
+
|
5
|
+
module RosettaQueue
|
6
|
+
|
7
|
+
Adapter.define do |a|
|
8
|
+
a.user = "rosetta"
|
9
|
+
a.password = "password"
|
10
|
+
a.host = "localhost"
|
11
|
+
a.type = 'amqp_synch'
|
12
|
+
end
|
13
|
+
|
14
|
+
Destinations.define do |dest|
|
15
|
+
dest.map :foo, "queuep.foo"
|
16
|
+
end
|
17
|
+
|
18
|
+
class MessageHandlerFoo
|
19
|
+
include RosettaQueue::MessageHandler
|
20
|
+
subscribes_to :foo
|
21
|
+
options :ack => true
|
22
|
+
attr_reader :msg
|
23
|
+
|
24
|
+
def on_message(msg)
|
25
|
+
puts "FOO received message: #{msg}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
ThreadedManager.create do |m|
|
31
|
+
m.add MessageHandlerFoo.new
|
32
|
+
m.start
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/rosetta_queue/consumer_managers/threaded.rb')
|
4
|
+
|
5
|
+
module RosettaQueue
|
6
|
+
|
7
|
+
Adapter.define do |a|
|
8
|
+
a.user = "rosetta"
|
9
|
+
a.password = "password"
|
10
|
+
a.host = "localhost"
|
11
|
+
a.type = 'amqp'
|
12
|
+
end
|
13
|
+
|
14
|
+
Destinations.define do |dest|
|
15
|
+
dest.map :foo, "fanout.foo"
|
16
|
+
end
|
17
|
+
|
18
|
+
class MessageHandlerFoo
|
19
|
+
include RosettaQueue::MessageHandler
|
20
|
+
subscribes_to :foo
|
21
|
+
options :ack => true
|
22
|
+
attr_reader :msg
|
23
|
+
|
24
|
+
def on_message(msg)
|
25
|
+
puts "FOO received message: #{msg}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class MessageHandlerBar
|
31
|
+
include RosettaQueue::MessageHandler
|
32
|
+
subscribes_to :foo
|
33
|
+
options :ack => true
|
34
|
+
attr_reader :msg
|
35
|
+
|
36
|
+
def on_message(msg)
|
37
|
+
puts "BAR received message: #{msg}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# threaded version
|
43
|
+
ThreadedManager.create do |m|
|
44
|
+
m.add MessageHandlerFoo.new
|
45
|
+
m.add MessageHandlerBar.new
|
46
|
+
m.start
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
3
|
+
|
4
|
+
RosettaQueue::Adapter.define do |a|
|
5
|
+
a.user = "rosetta"
|
6
|
+
a.password = "password"
|
7
|
+
a.host = "localhost"
|
8
|
+
a.type = "amqp"
|
9
|
+
end
|
10
|
+
|
11
|
+
RosettaQueue::Destinations.define do |dest|
|
12
|
+
dest.map :foo, "fanout.foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
RosettaQueue::Producer.publish(:foo, "hello there")
|
17
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
3
|
+
|
4
|
+
RosettaQueue::Adapter.define do |a|
|
5
|
+
a.user = "rosetta"
|
6
|
+
a.password = "password"
|
7
|
+
a.host = "localhost"
|
8
|
+
a.type = "amqp_synch"
|
9
|
+
end
|
10
|
+
|
11
|
+
RosettaQueue::Destinations.define do |dest|
|
12
|
+
dest.map :foo, "queue.foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
RosettaQueue::Producer.publish(:foo, "hello there")
|
data/features/filtering.feature
CHANGED
@@ -9,27 +9,23 @@ Feature: Message Filtering
|
|
9
9
|
And a point-to-point destination is set
|
10
10
|
And a receiving filter is defined to prepend 'Foo' to all messages
|
11
11
|
And the message "Hello World" is published to queue "foo"
|
12
|
-
|
13
12
|
When the message on "foo" is consumed
|
14
|
-
|
15
13
|
Then the consumed message should equal "Foo Hello World"
|
16
|
-
|
14
|
+
|
17
15
|
Examples:
|
18
16
|
| Adapter |
|
17
|
+
| amqp_synch |
|
19
18
|
| stomp |
|
20
|
-
|
21
|
-
|
22
|
-
Scenario Outline: sending filter
|
19
|
+
|
20
|
+
Scenario Outline: sending filter
|
23
21
|
Given RosettaQueue is configured for '<Adapter>'
|
24
22
|
And a point-to-point destination is set
|
25
23
|
And a sending filter is defined to prepend 'Foo' to all messages
|
26
24
|
And the message "Hello World" is published to queue "foo"
|
27
|
-
|
28
25
|
When the message on "foo" is consumed
|
29
|
-
|
30
26
|
Then the consumed message should equal "Foo Hello World"
|
31
27
|
|
32
28
|
Examples:
|
33
29
|
| Adapter |
|
30
|
+
| amqp_synch |
|
34
31
|
| stomp |
|
35
|
-
| amqp |
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Story: Producing and Consuming
|
2
|
+
|
3
|
+
As a RosettaQueue user
|
4
|
+
I want to publish and consume point-to-point using various messaging protocols
|
5
|
+
So that I can reliably integrate my systems with a message broker
|
6
|
+
|
7
|
+
Scenario Outline: Point-to-Point
|
8
|
+
Given RosettaQueue is configured for '<Adapter>'
|
9
|
+
And a point-to-point destination is set
|
10
|
+
When a message is published to queue 'foo'
|
11
|
+
Then the message should be consumed
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
| Adapter |
|
15
|
+
| amqp_synch |
|
16
|
+
| stomp |
|
17
|
+
| beanstalk |
|
18
|
+
|
19
|
+
Scenario Outline: Delete queue
|
20
|
+
Given RosettaQueue is configured for '<Adapter>'
|
21
|
+
And a point-to-point destination is set
|
22
|
+
When a message is published to queue '<Queue>'
|
23
|
+
And the queue '<Queue>' is deleted
|
24
|
+
Then the queue '<Queue>' should no longer exist
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
| Adapter | Queue |
|
28
|
+
| amqp_synch | foo |
|
29
|
+
|
30
|
+
|
31
|
+
# Scenario Outline: Publish-Subscribe
|
32
|
+
# Given RosettaQueue is configured for '<Adapter>'
|
33
|
+
# And a '<PublishSubscribe>' destination is set
|
34
|
+
# When a message is published to 'foobar'
|
35
|
+
# Then multiple messages should be consumed from the topic
|
36
|
+
|
37
|
+
# Examples:
|
38
|
+
# | Adapter | PublishSubscribe |
|
39
|
+
# | amqp_synch | fanout |
|
40
|
+
# | stomp | topic |
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Given /^RosettaQueue is configured for '(\w+)'$/ do |adapter_type|
|
2
|
+
@adapter_type = adapter_type
|
3
|
+
RosettaQueue::Adapter.define do |a|
|
4
|
+
a.user = "rosetta"
|
5
|
+
a.password = "password"
|
6
|
+
a.host = "localhost"
|
7
|
+
a.type = @adapter_type
|
8
|
+
a.port = case @adapter_type
|
9
|
+
when /stomp/
|
10
|
+
"61613"
|
11
|
+
when /beanstalk/
|
12
|
+
"11300"
|
13
|
+
else
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Given /^a point-to-point destination is set$/ do
|
20
|
+
RosettaQueue::Destinations.define do |dest|
|
21
|
+
dest.map :foo, "/queue/bar"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Given /^a '(.*)' destination is set$/ do |pub_sub|
|
26
|
+
case pub_sub
|
27
|
+
when /fanout/
|
28
|
+
RosettaQueue::Destinations.define do |dest|
|
29
|
+
dest.map :foobar, "/fanout/foobar"
|
30
|
+
end
|
31
|
+
when /topic/
|
32
|
+
RosettaQueue::Destinations.define do |dest|
|
33
|
+
dest.map :foobar, "/topic/foobar"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
When /^the queue '(.*)' is deleted$/ do |queue|
|
39
|
+
system("rabbitmqctl list_queues | grep bar").should be_true
|
40
|
+
RosettaQueue::Consumer.delete(queue.to_sym)
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^the queue 'foo' should no longer exist$/ do
|
44
|
+
system("rabbitmqctl list_queues | grep bar").should be_false
|
45
|
+
end
|
@@ -1,20 +1,12 @@
|
|
1
|
+
Given /^the message "(.+)" is published to queue "(.+)"$/ do |message, queue_name|
|
2
|
+
publish_message(message, {:options => {:ack => "client"}}.merge(:to => queue_name))
|
3
|
+
end
|
4
|
+
|
1
5
|
When /^a message is published to queue '(\w+)'$/ do |q|
|
2
6
|
publish_message("Hello World!", {:options => {:ack => "client"}}.merge(:to => q))
|
3
7
|
end
|
4
8
|
|
5
9
|
Then /^the message should be consumed$/ do
|
6
|
-
sleep 1
|
7
10
|
RosettaQueue::Consumer.receive(:foo).should =~ /Hello World!/
|
8
11
|
# consume_once_with(SampleConsumer).should =~ /Hello World!/
|
9
|
-
|
10
|
-
# RosettaQueue::EventedManager.create do |m|
|
11
|
-
#
|
12
|
-
# m.add(SampleConsumer.new)
|
13
|
-
# m.start
|
14
|
-
#
|
15
|
-
# end
|
16
12
|
end
|
17
|
-
|
18
|
-
Given /^the message "(.+)" is published to queue "(.+)"$/ do |message, queue_name|
|
19
|
-
publish_message(message, {:options => {:ack => "client"}}.merge(:to => queue_name))
|
20
|
-
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
When /^a message is published to
|
2
|
-
RosettaQueue::Producer.publish(topic.to_sym, "Hello World
|
1
|
+
When /^a message is published to '(\w+)'$/ do |topic|
|
2
|
+
RosettaQueue::Producer.publish(topic.to_sym, "Hello World!", {:durable => true})
|
3
3
|
# publish_message("Hello World!", {:options => {:ack => "client"}}.merge(:to => topic))
|
4
4
|
end
|
5
5
|
|
@@ -8,4 +8,4 @@ Then /^multiple messages should be consumed from the topic$/ do
|
|
8
8
|
RosettaQueue::Consumer.receive(:foobar).should =~ /Hello World!/
|
9
9
|
# RosettaQueue::Consumer.receive(:bar).should =~ /Hello World!/
|
10
10
|
# consume_once_with(SampleConsumer).should == "Hello World!"
|
11
|
-
end
|
11
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -4,10 +4,9 @@ require 'rosetta_queue'
|
|
4
4
|
require 'rosetta_queue/spec_helpers'
|
5
5
|
require 'spec/expectations'
|
6
6
|
require 'rosetta_queue/spec_helpers'
|
7
|
-
require 'amqp'
|
8
7
|
|
9
8
|
begin
|
10
|
-
RosettaQueue.logger = RosettaQueue::Logger.new(File.join(File.dirname(__FILE__), '
|
9
|
+
RosettaQueue.logger = RosettaQueue::Logger.new(File.join(File.dirname(__FILE__), '../../../log', 'rosetta_queue.log'))
|
11
10
|
rescue Errno::ENOENT
|
12
11
|
Kernel.warn "No log directory setup at the root of rosetta_queue. Using the null logger instead."
|
13
12
|
class NullLogger
|
@@ -22,6 +21,3 @@ rescue Errno::ENOENT
|
|
22
21
|
end
|
23
22
|
|
24
23
|
World(RosettaQueue::SpecHelpers)
|
25
|
-
|
26
|
-
AMQP.logging = false # true
|
27
|
-
# Thread.new {EM.run{}}
|
@@ -4,30 +4,36 @@ module RosettaQueue
|
|
4
4
|
class Adapter
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_writer :user, :password, :host, :port
|
7
|
+
attr_writer :user, :password, :host, :port, :options
|
8
8
|
|
9
9
|
def define
|
10
10
|
yield self
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def reset
|
14
|
-
@user, @password, @host, @port, @adapter_class = nil, nil, nil, nil, nil
|
14
|
+
@user, @password, @host, @port, @options, @adapter_class = nil, nil, nil, nil, nil, nil
|
15
15
|
end
|
16
16
|
|
17
17
|
def type=(adapter_prefix)
|
18
|
-
|
19
|
-
|
18
|
+
require "rosetta_queue/adapters/#{adapter_prefix}"
|
19
|
+
@adapter_class = RosettaQueue::Gateway.const_get("#{adapter_prefix.to_s.classify}Adapter")
|
20
|
+
|
20
21
|
rescue LoadError
|
21
22
|
raise AdapterException, "Adapter type '#{adapter_prefix}' does not match existing adapters!"
|
22
|
-
end
|
23
|
-
@adapter_class = RosettaQueue::Gateway.const_get("#{adapter_prefix.to_s.classify}Adapter")
|
24
23
|
end
|
25
24
|
|
26
25
|
def instance
|
27
26
|
raise AdapterException, "Adapter type was never defined!" unless @adapter_class
|
28
|
-
@adapter_class.new(@user, @password, @host, @port)
|
27
|
+
@adapter_class.new({:user => @user, :password => @password, :host => @host, :port => @port, :opts => opts})
|
29
28
|
end
|
30
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
def opts
|
33
|
+
raise AdapterException, "Adapter options should be a hash" unless @options.nil? || @options.is_a?(Hash)
|
34
|
+
@options ||= {}
|
35
|
+
end
|
36
|
+
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|