raq 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTI4ZmI5NTZhMjhmMGY1MTY3MDEyOGU1ZWFiMjlhYTczMmQ0ZmIyZg==
5
+ data.tar.gz: !binary |-
6
+ NGU1NTdlMzI0OWIxNjZiZWU5YTAzYjhjOWE1MWEzY2U5Y2Q4MTRjNg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjRmODcyOGEyZDRmNDYwOTQ4OTY1MjNlZTRjZDdmZDU4N2QxZTUzN2VmYjY1
10
+ MzJiMDA4OGQ4MWZhYWU5ODAxMjkzOTExM2VkZTQ0ZDM2MmY0ZjAxY2ZhMzEz
11
+ YTRjNDlhZWY1YjE0OTY5MDhiZjllNzc5ZTAyNjQ1MGU4MmUxZjg=
12
+ data.tar.gz: !binary |-
13
+ ZjI2ZDdhNjI5Y2NkNTJjNDdkZTgxNjE4NmJiOTA0NDZhZmQ3YmFmMjRkZTky
14
+ ZmNmODQwY2M5ZmU1OTdkOTJiZWNhZDk3MDYwODNlNzNmNGQwNDM0ZTJiOWVi
15
+ ODU0YjlmOGM0ZTI2OTMwNjUzMGY5NDlmZmFkNzBhZDBjOGFkNDU=
@@ -2,5 +2,7 @@ language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
4
  - 1.9.3
5
+ services:
6
+ - rabbitmq
5
7
  notifications:
6
8
  hipchat: f99d2e5a191d805ae29ae7b5811eea@AZ dev
data/README.md CHANGED
@@ -3,7 +3,7 @@ Raq [![Build Status](https://travis-ci.org/cpb/raq.png?branch=master)](https://t
3
3
 
4
4
  Raq makes it easy to create durable message queue consumers. It tries to learn from [Thin](https://github.com/macournoyer/thin) and [Rack](https://github.com/rack/rack) in order to provide a reasonably familiar way of creating and running AMQP consumers.
5
5
 
6
- Raq expresses the opinion that, like database configuration, queue configuration should be configured by the environment. Raq offers the ability to specify message broker connection information and queue names as command line flags, or in an separate configuration file.
6
+ Raq expresses the opinion that, like database configuration, queue configuration should handled by the environment. Raq offers the ability to specify message broker connection information and queue names as command line flags, or in a separate configuration file.
7
7
 
8
8
  Installation
9
9
  ------------
@@ -65,7 +65,27 @@ $ ruby example.rb --queue a.queue.with.messages
65
65
 
66
66
  It will print the payload to stdout a couple times, acknowledge the message, and exit.
67
67
 
68
- == Contributing to raq
68
+ Configuration
69
+ -------------
70
+
71
+ You can choose to configure Raq with either commandline flags or a configuration file. The configuration file is a simple YAML file. The keys should be the same as the long form commandline flags.
72
+
73
+ For example, consider this sample.yml:
74
+
75
+ ```yaml
76
+ --
77
+ queue: RabbitEmergencyRoom
78
+ ```
79
+
80
+ When you run the above example.rb like so:
81
+ ```bash
82
+ $ ruby example.rb --config sample.yml
83
+ ```
84
+
85
+ It will connect to the ```RabbitEmergencyRoom``` queue!
86
+
87
+ Contributing to Raq
88
+ -------------------
69
89
 
70
90
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
71
91
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -75,7 +95,8 @@ It will print the payload to stdout a couple times, acknowledge the message, and
75
95
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
76
96
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
77
97
 
78
- == Copyright
98
+ Copyright
99
+ ---------
79
100
 
80
101
  Copyright (c) 2013 Caleb Buxton. See LICENSE.txt for further details.
81
102
 
data/Rakefile CHANGED
@@ -27,6 +27,21 @@ Jeweler::RubygemsDotOrgTasks.new
27
27
 
28
28
  require 'cucumber/rake/task'
29
29
  Cucumber::Rake::Task.new(:features)
30
+ Cucumber::Rake::Task.new(:aruba_features) do |t|
31
+ t.cucumber_opts = "ARUBA_REPORT_DIR=doc --format progress"
32
+ end
33
+
34
+ task :aruba_doc => [:check_aruba_doc_dependencies, :aruba_features]
35
+
36
+ task :check_aruba_doc_dependencies do
37
+ unless system('pygmentize',[:err,:out]=>"/dev/null")
38
+ puts "Generating Aruba Reports depends on Pygments."
39
+ puts "Check http://pygments.org/"
40
+ puts "Or you can just try `easy_install Pygments`"
41
+ puts
42
+ raise "You do not have all the dependencies required to generate Aruba Reports"
43
+ end
44
+ end
30
45
 
31
46
  require 'rspec/core'
32
47
  require 'rspec/core/rake_task'
@@ -39,7 +54,7 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
54
  spec.rcov = true
40
55
  end
41
56
 
42
- task :default => :spec
57
+ task :default => [:spec,:features]
43
58
 
44
59
  require 'rdoc/task'
45
60
  Rake::RDocTask.new do |rdoc|
@@ -50,3 +65,5 @@ Rake::RDocTask.new do |rdoc|
50
65
  rdoc.rdoc_files.include('README*')
51
66
  rdoc.rdoc_files.include('lib/**/*.rb')
52
67
  end
68
+
69
+ task :doc => [:rdoc,:aruba_doc]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -97,3 +97,32 @@ Feature: Raq provides a friendly and familiar way of consuming messages off a du
97
97
  And I run the consumer on the queue
98
98
  When I run the consumer on the queue, again
99
99
  Then it should never return
100
+
101
+ @amqp
102
+ Scenario: Running raq with a configuration file
103
+ Given a file named "raq.yml" with:
104
+ """
105
+ ---
106
+ queue: RabbitEmergencyRoom
107
+ """
108
+ And a consumer with:
109
+ """
110
+ runner = Raq::Runner.new(ARGV)
111
+ server = Raq::Server.new(
112
+ connection: runner.connection_options,
113
+ queues: runner.options[:queue]) do
114
+
115
+ run do |meta, payload|
116
+ puts "Got #{payload}"
117
+ meta.ack
118
+ server.connection.close { EM.stop }
119
+ end
120
+ end
121
+
122
+ server.run
123
+ """
124
+ And I produce a unique message on the queue "RabbitEmergencyRoom"
125
+ When I run the consumer with "--config raq.yml"
126
+ Then the output should contain the unique message
127
+
128
+
@@ -94,6 +94,12 @@ When(/^I run the raq agent "(.*?)"(, failing)?(, again)?$/) do |agent_run_string
94
94
  end
95
95
  end
96
96
 
97
+ When(/^I run (#{THE_CONSUMER}) with "(.*?)"$/) do |consumer, arguments|
98
+ steps %{
99
+ When I run the raq agent "#{consumer} #{arguments}"
100
+ }
101
+ end
102
+
97
103
  When(/^I run (#{THE_CONSUMER}) on (#{QUEUE})(, failing)?(, again)?$/) do |consumer, queue, failing, again|
98
104
  steps %{
99
105
  When I run the raq agent "#{consumer} --queue #{queue}"#{failing}#{again}
@@ -50,8 +50,12 @@ module RaqUnderTestHelper
50
50
  end
51
51
 
52
52
  module DependentServiceHelper
53
+ def travis?
54
+ ENV['TRAVIS'] == 'true'
55
+ end
56
+
53
57
  def start_amqp
54
- unless rabbitmq_running?
58
+ unless travis? || rabbitmq_running?
55
59
  system("rabbitmq-server &", out: "/dev/null", err: "/dev/null")
56
60
  unless system("rabbitmqctl wait /usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost.pid", out: "/dev/null", err: "/dev/null")
57
61
  raise "Unable to start rabbitmq"
@@ -66,7 +70,7 @@ module DependentServiceHelper
66
70
  end
67
71
 
68
72
  def stop_amqp
69
- if rabbitmq_running?
73
+ if !travis? && rabbitmq_running?
70
74
  unless system("rabbitmqctl stop", out: "/dev/null", err: "/dev/null")
71
75
  raise "Unable to stop rabbitmq"
72
76
  else
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'yaml'
2
3
 
3
4
  module Raq
4
5
  class Runner
@@ -25,13 +26,28 @@ module Raq
25
26
 
26
27
  opts.on("-r", "--require LIBRARY","Require the provided library before starting") { |lib| require lib }
27
28
  # ... and on
29
+
30
+ opts.on("-C", "--config CONFIG.YML", "YAML file containing Raq configuration") { |path| @options[:config] = path }
28
31
  end
29
32
  end
30
33
 
31
34
  def parse!
32
35
  parser.parse! @argv
36
+ # Defaults < Configuration File < Command line arguments
37
+
38
+ @options = symbolized_configuration_file_data(@options.delete(:config)).merge(@options)
39
+
33
40
  @command = @argv.shift
34
41
  @connection_options = @options.reject {|k,v| [:queue, :type].include?(k) }
35
42
  end
43
+
44
+ private
45
+ def symbolized_configuration_file_data(configuration_file_path=nil)
46
+ if configuration_file_path
47
+ ::YAML::load_file(configuration_file_path).inject({}){|memo,(k,v)| memo.merge(k.to_sym => v)}
48
+ else
49
+ {}
50
+ end
51
+ end
36
52
  end
37
53
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "raq"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Caleb Buxton"]
12
- s.date = "2013-07-05"
12
+ s.date = "2013-07-19"
13
13
  s.description = "The elegance of Rack with none of the unreliability of HTTP"
14
14
  s.email = "me@cpb.ca"
15
15
  s.extra_rdoc_files = [
@@ -49,11 +49,11 @@ Gem::Specification.new do |s|
49
49
  s.homepage = "http://github.com/cpb/raq"
50
50
  s.licenses = ["MIT"]
51
51
  s.require_paths = ["lib"]
52
- s.rubygems_version = "1.8.25"
52
+ s.rubygems_version = "2.0.4"
53
53
  s.summary = "Middleware for your AMQP Message Consumer"
54
54
 
55
55
  if s.respond_to? :specification_version then
56
- s.specification_version = 3
56
+ s.specification_version = 4
57
57
 
58
58
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
59
  s.add_runtime_dependency(%q<eventmachine>, ["~> 1.0"])
@@ -49,6 +49,31 @@ describe Raq::Runner do
49
49
  # broker=>nil
50
50
  # frame_max=>131072
51
51
  # heartbeat=>0}"
52
+
53
+ it "should parse config file" do
54
+ expect do
55
+ runner = described_class.new(%w(start --config path/to/file))
56
+ end.to_not raise_error(OptionParser::InvalidOption)
57
+ end
58
+ end
59
+
60
+ context "configuration file" do
61
+
62
+ # First time used it creates the configuration file.
63
+ # Each time accessed it returns the filename.
64
+ let(:configuration_file) do
65
+ File.open("foobar.yml","w") do |f|
66
+ f.write(YAML::dump({
67
+ "queue" => "queue.name"
68
+ }))
69
+ f.path
70
+ end
71
+ end
72
+
73
+ it "should be used to set values" do
74
+ runner = described_class.new(%w(start --config) << configuration_file)
75
+ expect(runner.options[:queue]).to eql("queue.name")
76
+ end
52
77
  end
53
78
 
54
79
  it "should parse specified command" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Caleb Buxton
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: amqp
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bcat
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: guard
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: guard-cucumber
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: guard-rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: pry
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: rdoc
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
@@ -158,7 +139,6 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: rdiscount
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - ~>
164
144
  - !ruby/object:Gem::Version
@@ -166,7 +146,6 @@ dependencies:
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - ~>
172
151
  - !ruby/object:Gem::Version
@@ -174,7 +153,6 @@ dependencies:
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: travis-lint
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
157
  - - ~>
180
158
  - !ruby/object:Gem::Version
@@ -182,7 +160,6 @@ dependencies:
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
164
  - - ~>
188
165
  - !ruby/object:Gem::Version
@@ -226,29 +203,25 @@ files:
226
203
  homepage: http://github.com/cpb/raq
227
204
  licenses:
228
205
  - MIT
206
+ metadata: {}
229
207
  post_install_message:
230
208
  rdoc_options: []
231
209
  require_paths:
232
210
  - lib
233
211
  required_ruby_version: !ruby/object:Gem::Requirement
234
- none: false
235
212
  requirements:
236
213
  - - ! '>='
237
214
  - !ruby/object:Gem::Version
238
215
  version: '0'
239
- segments:
240
- - 0
241
- hash: -107125167469032534
242
216
  required_rubygems_version: !ruby/object:Gem::Requirement
243
- none: false
244
217
  requirements:
245
218
  - - ! '>='
246
219
  - !ruby/object:Gem::Version
247
220
  version: '0'
248
221
  requirements: []
249
222
  rubyforge_project:
250
- rubygems_version: 1.8.25
223
+ rubygems_version: 2.0.4
251
224
  signing_key:
252
- specification_version: 3
225
+ specification_version: 4
253
226
  summary: Middleware for your AMQP Message Consumer
254
227
  test_files: []