rabbit_feed 0.3.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/DEVELOPING.md +6 -6
- data/Gemfile +1 -0
- data/Gemfile.lock +60 -52
- data/README.md +30 -14
- data/example/non_rails_app/Gemfile.lock +27 -23
- data/example/non_rails_app/bin/benchmark +3 -5
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +2 -4
- data/example/non_rails_app/spec/spec_helper.rb +3 -11
- data/example/rails_app/Gemfile +1 -1
- data/example/rails_app/Gemfile.lock +111 -94
- data/example/rails_app/config/environments/development.rb +1 -1
- data/example/rails_app/config/environments/test.rb +1 -1
- data/example/rails_app/config/initializers/rabbit_feed.rb +0 -7
- data/example/rails_app/spec/controllers/beavers_controller_spec.rb +1 -1
- data/example/rails_app/spec/event_routing_spec.rb +2 -5
- data/example/rails_app/spec/rails_helper.rb +52 -0
- data/example/rails_app/spec/spec_helper.rb +1 -44
- data/lib/rabbit_feed/client.rb +23 -11
- data/lib/rabbit_feed/configuration.rb +2 -0
- data/lib/rabbit_feed/event_routing.rb +31 -7
- data/lib/rabbit_feed/producer.rb +0 -4
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +11 -15
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +10 -0
- data/lib/rabbit_feed/testing_support/testing_helpers.rb +1 -7
- data/lib/rabbit_feed/testing_support.rb +32 -0
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +5 -4
- data/rabbit_feed.gemspec +8 -8
- data/spec/lib/rabbit_feed/configuration_spec.rb +15 -7
- data/spec/lib/rabbit_feed/event_routing_spec.rb +41 -1
- data/spec/lib/rabbit_feed/producer_spec.rb +1 -1
- data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +17 -2
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +0 -3
- data/spec/spec_helper.rb +6 -1
- metadata +53 -19
@@ -1,45 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
rabbit_feed (0.
|
5
|
-
activemodel
|
6
|
-
activesupport
|
7
|
-
avro
|
8
|
-
bunny
|
9
|
-
connection_pool
|
4
|
+
rabbit_feed (0.4.0)
|
5
|
+
activemodel (>= 3.2.0, < 5.0.0)
|
6
|
+
activesupport (>= 3.2.0, < 5.0.0)
|
7
|
+
avro (>= 1.5.4, < 1.8.0)
|
8
|
+
bunny (>= 1.1.9, < 1.7.0)
|
9
|
+
connection_pool (< 2.2.0)
|
10
10
|
pidfile
|
11
11
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
actionmailer (4.
|
16
|
-
actionpack (= 4.
|
17
|
-
actionview (= 4.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
actionmailer (4.2.0)
|
16
|
+
actionpack (= 4.2.0)
|
17
|
+
actionview (= 4.2.0)
|
18
|
+
activejob (= 4.2.0)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
21
|
+
actionpack (4.2.0)
|
22
|
+
actionview (= 4.2.0)
|
23
|
+
activesupport (= 4.2.0)
|
24
|
+
rack (~> 1.6.0)
|
23
25
|
rack-test (~> 0.6.2)
|
24
|
-
|
25
|
-
|
26
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
28
|
+
actionview (4.2.0)
|
29
|
+
activesupport (= 4.2.0)
|
26
30
|
builder (~> 3.1)
|
27
31
|
erubis (~> 2.7.0)
|
28
|
-
|
29
|
-
|
32
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
34
|
+
activejob (4.2.0)
|
35
|
+
activesupport (= 4.2.0)
|
36
|
+
globalid (>= 0.3.0)
|
37
|
+
activemodel (4.2.0)
|
38
|
+
activesupport (= 4.2.0)
|
30
39
|
builder (~> 3.1)
|
31
|
-
activerecord (4.
|
32
|
-
activemodel (= 4.
|
33
|
-
activesupport (= 4.
|
34
|
-
arel (~>
|
35
|
-
activesupport (4.
|
36
|
-
i18n (~> 0.
|
40
|
+
activerecord (4.2.0)
|
41
|
+
activemodel (= 4.2.0)
|
42
|
+
activesupport (= 4.2.0)
|
43
|
+
arel (~> 6.0)
|
44
|
+
activesupport (4.2.0)
|
45
|
+
i18n (~> 0.7)
|
37
46
|
json (~> 1.7, >= 1.7.7)
|
38
47
|
minitest (~> 5.1)
|
39
|
-
thread_safe (~> 0.
|
48
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
40
49
|
tzinfo (~> 1.1)
|
41
50
|
amq-protocol (1.9.2)
|
42
|
-
arel (
|
51
|
+
arel (6.0.0)
|
43
52
|
avro (1.7.7)
|
44
53
|
multi_json
|
45
54
|
builder (3.2.2)
|
@@ -48,108 +57,116 @@ GEM
|
|
48
57
|
coffee-rails (4.0.1)
|
49
58
|
coffee-script (>= 2.2.0)
|
50
59
|
railties (>= 4.0.0, < 5.0)
|
51
|
-
coffee-script (2.
|
60
|
+
coffee-script (2.3.0)
|
52
61
|
coffee-script-source
|
53
62
|
execjs
|
54
|
-
coffee-script-source (1.
|
55
|
-
connection_pool (2.
|
63
|
+
coffee-script-source (1.8.0)
|
64
|
+
connection_pool (2.1.0)
|
56
65
|
diff-lcs (1.2.5)
|
57
66
|
erubis (2.7.0)
|
58
|
-
execjs (2.
|
67
|
+
execjs (2.2.2)
|
68
|
+
globalid (0.3.0)
|
69
|
+
activesupport (>= 4.1.0)
|
59
70
|
hike (1.2.3)
|
60
|
-
i18n (0.
|
61
|
-
jbuilder (2.
|
71
|
+
i18n (0.7.0)
|
72
|
+
jbuilder (2.2.6)
|
62
73
|
activesupport (>= 3.0.0, < 5)
|
63
74
|
multi_json (~> 1.2)
|
64
|
-
jquery-rails (
|
65
|
-
|
75
|
+
jquery-rails (4.0.2)
|
76
|
+
rails-dom-testing (~> 1.0)
|
77
|
+
railties (>= 4.2.0)
|
66
78
|
thor (>= 0.14, < 2.0)
|
67
79
|
json (1.8.1)
|
68
|
-
kgio (2.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
kgio (2.9.2)
|
81
|
+
loofah (2.0.1)
|
82
|
+
nokogiri (>= 1.5.9)
|
83
|
+
mail (2.6.3)
|
84
|
+
mime-types (>= 1.16, < 3)
|
85
|
+
mime-types (2.4.3)
|
86
|
+
mini_portile (0.6.1)
|
87
|
+
minitest (5.5.0)
|
88
|
+
multi_json (1.10.1)
|
89
|
+
nokogiri (1.6.5)
|
90
|
+
mini_portile (~> 0.6.0)
|
75
91
|
pidfile (0.3.0)
|
76
|
-
|
77
|
-
rack (1.5.2)
|
92
|
+
rack (1.6.0)
|
78
93
|
rack-test (0.6.2)
|
79
94
|
rack (>= 1.0)
|
80
|
-
rails (4.
|
81
|
-
actionmailer (= 4.
|
82
|
-
actionpack (= 4.
|
83
|
-
actionview (= 4.
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
rails (4.2.0)
|
96
|
+
actionmailer (= 4.2.0)
|
97
|
+
actionpack (= 4.2.0)
|
98
|
+
actionview (= 4.2.0)
|
99
|
+
activejob (= 4.2.0)
|
100
|
+
activemodel (= 4.2.0)
|
101
|
+
activerecord (= 4.2.0)
|
102
|
+
activesupport (= 4.2.0)
|
87
103
|
bundler (>= 1.3.0, < 2.0)
|
88
|
-
railties (= 4.
|
89
|
-
sprockets-rails
|
90
|
-
|
91
|
-
|
92
|
-
|
104
|
+
railties (= 4.2.0)
|
105
|
+
sprockets-rails
|
106
|
+
rails-deprecated_sanitizer (1.0.3)
|
107
|
+
activesupport (>= 4.2.0.alpha)
|
108
|
+
rails-dom-testing (1.0.5)
|
109
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
110
|
+
nokogiri (~> 1.6.0)
|
111
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
112
|
+
rails-html-sanitizer (1.0.1)
|
113
|
+
loofah (~> 2.0)
|
114
|
+
railties (4.2.0)
|
115
|
+
actionpack (= 4.2.0)
|
116
|
+
activesupport (= 4.2.0)
|
93
117
|
rake (>= 0.8.7)
|
94
118
|
thor (>= 0.18.1, < 2.0)
|
95
|
-
raindrops (0.
|
96
|
-
rake (10.
|
97
|
-
rdoc (4.
|
119
|
+
raindrops (0.13.0)
|
120
|
+
rake (10.4.2)
|
121
|
+
rdoc (4.2.0)
|
98
122
|
json (~> 1.4)
|
99
|
-
rspec-
|
100
|
-
rspec-
|
101
|
-
rspec-
|
102
|
-
rspec-support (= 3.0.0.beta2)
|
103
|
-
rspec-expectations (3.0.0.beta2)
|
123
|
+
rspec-core (3.1.7)
|
124
|
+
rspec-support (~> 3.1.0)
|
125
|
+
rspec-expectations (3.1.2)
|
104
126
|
diff-lcs (>= 1.2.0, < 2.0)
|
105
|
-
rspec-support (
|
106
|
-
rspec-mocks (3.
|
107
|
-
rspec-support (
|
108
|
-
rspec-rails (3.
|
127
|
+
rspec-support (~> 3.1.0)
|
128
|
+
rspec-mocks (3.1.3)
|
129
|
+
rspec-support (~> 3.1.0)
|
130
|
+
rspec-rails (3.1.0)
|
109
131
|
actionpack (>= 3.0)
|
110
|
-
activemodel (>= 3.0)
|
111
132
|
activesupport (>= 3.0)
|
112
133
|
railties (>= 3.0)
|
113
|
-
rspec-
|
114
|
-
rspec-
|
115
|
-
rspec-
|
116
|
-
rspec-
|
117
|
-
|
118
|
-
rspec-support (3.0.0.beta2)
|
134
|
+
rspec-core (~> 3.1.0)
|
135
|
+
rspec-expectations (~> 3.1.0)
|
136
|
+
rspec-mocks (~> 3.1.0)
|
137
|
+
rspec-support (~> 3.1.0)
|
138
|
+
rspec-support (3.1.2)
|
119
139
|
sass (3.2.19)
|
120
|
-
sass-rails (4.0.
|
140
|
+
sass-rails (4.0.5)
|
121
141
|
railties (>= 4.0.0, < 5.0)
|
122
|
-
sass (~> 3.2.
|
123
|
-
sprockets (~> 2.8,
|
142
|
+
sass (~> 3.2.2)
|
143
|
+
sprockets (~> 2.8, < 3.0)
|
124
144
|
sprockets-rails (~> 2.0)
|
125
|
-
sdoc (0.4.
|
126
|
-
json (~> 1.
|
127
|
-
rdoc (~> 4.0
|
128
|
-
spring (1.
|
129
|
-
sprockets (2.
|
145
|
+
sdoc (0.4.1)
|
146
|
+
json (~> 1.7, >= 1.7.7)
|
147
|
+
rdoc (~> 4.0)
|
148
|
+
spring (1.2.0)
|
149
|
+
sprockets (2.12.3)
|
130
150
|
hike (~> 1.2)
|
131
151
|
multi_json (~> 1.0)
|
132
152
|
rack (~> 1.0)
|
133
153
|
tilt (~> 1.1, != 1.3.0)
|
134
|
-
sprockets-rails (2.
|
154
|
+
sprockets-rails (2.2.2)
|
135
155
|
actionpack (>= 3.0)
|
136
156
|
activesupport (>= 3.0)
|
137
|
-
sprockets (
|
138
|
-
sqlite3 (1.3.
|
157
|
+
sprockets (>= 2.8, < 4.0)
|
158
|
+
sqlite3 (1.3.10)
|
139
159
|
thor (0.19.1)
|
140
|
-
thread_safe (0.3.
|
160
|
+
thread_safe (0.3.4)
|
141
161
|
tilt (1.4.1)
|
142
|
-
|
143
|
-
polyglot
|
144
|
-
polyglot (>= 0.3.1)
|
145
|
-
turbolinks (2.2.2)
|
162
|
+
turbolinks (2.5.3)
|
146
163
|
coffee-rails
|
147
|
-
tzinfo (1.
|
164
|
+
tzinfo (1.2.2)
|
148
165
|
thread_safe (~> 0.1)
|
149
|
-
uglifier (2.
|
166
|
+
uglifier (2.6.0)
|
150
167
|
execjs (>= 0.3.0)
|
151
168
|
json (>= 1.8.0)
|
152
|
-
unicorn (4.
|
169
|
+
unicorn (4.8.3)
|
153
170
|
kgio (~> 2.6)
|
154
171
|
rack
|
155
172
|
raindrops (~> 0.7)
|
@@ -162,7 +179,7 @@ DEPENDENCIES
|
|
162
179
|
jbuilder (~> 2.0)
|
163
180
|
jquery-rails
|
164
181
|
rabbit_feed!
|
165
|
-
rails (= 4.
|
182
|
+
rails (= 4.2.0)
|
166
183
|
rspec-rails
|
167
184
|
sass-rails (~> 4.0.3)
|
168
185
|
sdoc (~> 0.4.0)
|
@@ -20,7 +20,7 @@ Rails.application.configure do
|
|
20
20
|
# config.action_dispatch.rack_cache = true
|
21
21
|
|
22
22
|
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
-
config.
|
23
|
+
config.serve_static_files = false
|
24
24
|
|
25
25
|
# Compress JavaScripts and CSS.
|
26
26
|
config.assets.js_compressor = :uglifier
|
@@ -13,7 +13,7 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.
|
16
|
+
config.serve_static_files = true
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
@@ -1,10 +1,3 @@
|
|
1
|
-
RabbitFeed.instance_eval do
|
2
|
-
self.log = Logger.new (Rails.root.join 'log', 'rabbit_feed.log')
|
3
|
-
self.log.level = Logger::DEBUG
|
4
|
-
self.environment = Rails.env
|
5
|
-
self.configuration_file_path = Rails.root.join 'config', 'rabbit_feed.yml'
|
6
|
-
end
|
7
|
-
|
8
1
|
EventDefinitions do
|
9
2
|
define_event('user_creates_beaver', version: '1.0.0') do
|
10
3
|
defined_as do
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '../config/initializers/rabbit_feed'
|
1
|
+
require_relative 'rails_helper'
|
3
2
|
|
4
3
|
module RailsApp
|
5
4
|
describe 'Event Routing' do
|
6
|
-
|
7
|
-
include RabbitFeed::TestingSupport::TestingHelpers
|
8
|
-
|
9
5
|
let(:event) { {'application' => 'non_rails_app', 'name' => 'application_acknowledges_event'} }
|
6
|
+
|
10
7
|
it 'routes events correctly' do
|
11
8
|
expect(::EventHandler).to receive(:handle_event)
|
12
9
|
rabbit_feed_consumer.consume_event(event)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.expand_path("../../config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
7
|
+
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
9
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
10
|
+
# run as spec files by default. This means that files in spec/support that end
|
11
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
12
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
13
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
14
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
15
|
+
#
|
16
|
+
# The following line is provided for convenience purposes. It has the downside
|
17
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
18
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
19
|
+
# require only the support files necessary.
|
20
|
+
#
|
21
|
+
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
22
|
+
|
23
|
+
# Checks for pending migrations before tests are run.
|
24
|
+
# If you are not using ActiveRecord, you can remove this line.
|
25
|
+
ActiveRecord::Migration.maintain_test_schema!
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
29
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
30
|
+
|
31
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
32
|
+
# examples within a transaction, remove the following line or assign false
|
33
|
+
# instead of true.
|
34
|
+
config.use_transactional_fixtures = true
|
35
|
+
|
36
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
37
|
+
# based on their file location, for example enabling you to call `get` and
|
38
|
+
# `post` in specs under `spec/controllers`.
|
39
|
+
#
|
40
|
+
# You can disable this behaviour by removing the line below, and instead
|
41
|
+
# explicitly tag your specs with their type, e.g.:
|
42
|
+
#
|
43
|
+
# RSpec.describe UsersController, :type => :controller do
|
44
|
+
# # ...
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# The different available types are documented in the features, such as in
|
48
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
49
|
+
config.infer_spec_type_from_file_location!
|
50
|
+
|
51
|
+
RabbitFeed::TestingSupport.setup(config)
|
52
|
+
end
|
@@ -1,51 +1,8 @@
|
|
1
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
-
ENV["RAILS_ENV"] ||= 'test'
|
3
|
-
require File.expand_path("../../config/environment", __FILE__)
|
4
|
-
require 'rspec/rails'
|
5
|
-
|
6
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
7
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
8
|
-
# run as spec files by default. This means that files in spec/support that end
|
9
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
10
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
11
|
-
# end with _spec.rb. You can configure this pattern with with the --pattern
|
12
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
13
|
-
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
14
|
-
|
15
|
-
# Checks for pending migrations before tests are run.
|
16
|
-
# If you are not using ActiveRecord, you can remove this line.
|
17
|
-
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
18
|
-
|
19
1
|
RSpec.configure do |config|
|
20
|
-
# ## Mock Framework
|
21
|
-
#
|
22
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
23
|
-
#
|
24
|
-
# config.mock_with :mocha
|
25
|
-
# config.mock_with :flexmock
|
26
|
-
# config.mock_with :rr
|
27
|
-
|
28
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
29
|
-
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
30
|
-
|
31
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
32
|
-
# examples within a transaction, remove the following line or assign false
|
33
|
-
# instead of true.
|
34
|
-
config.use_transactional_fixtures = true
|
35
2
|
|
36
3
|
# Run specs in random order to surface order dependencies. If you find an
|
37
4
|
# order dependency and want to debug it, you can fix the order by providing
|
38
5
|
# the seed, which is printed after each run.
|
39
6
|
# --seed 1234
|
40
|
-
config.order =
|
41
|
-
|
42
|
-
config.mock_with :rspec do |c|
|
43
|
-
c.syntax = [:should, :expect]
|
44
|
-
end
|
45
|
-
|
46
|
-
config.before :each do
|
47
|
-
RabbitFeed::Producer.stub!
|
48
|
-
end
|
49
|
-
|
50
|
-
config.include(RabbitFeed::TestingSupport::RSpecMatchers)
|
7
|
+
config.order = 'random'
|
51
8
|
end
|
data/lib/rabbit_feed/client.rb
CHANGED
@@ -16,7 +16,7 @@ module RabbitFeed
|
|
16
16
|
|
17
17
|
attr_reader :command, :options
|
18
18
|
validates_presence_of :command, :options
|
19
|
-
validates :command, inclusion: { in: %w(consume produce), message: "%{value} is not a valid command" }
|
19
|
+
validates :command, inclusion: { in: %w(consume produce shutdown), message: "%{value} is not a valid command" }
|
20
20
|
validate :log_file_path_exists
|
21
21
|
validate :config_file_exists
|
22
22
|
validate :require_path_valid
|
@@ -26,11 +26,14 @@ module RabbitFeed
|
|
26
26
|
def initialize arguments=ARGV
|
27
27
|
@command = arguments[0]
|
28
28
|
@options = parse_options arguments
|
29
|
-
validate!
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
unless shutdown?
|
31
|
+
validate!
|
32
|
+
|
33
|
+
set_logging
|
34
|
+
set_configuration
|
35
|
+
load_dependancies
|
36
|
+
end
|
34
37
|
end
|
35
38
|
|
36
39
|
def run
|
@@ -70,6 +73,14 @@ module RabbitFeed
|
|
70
73
|
RabbitFeed::Consumer.run
|
71
74
|
end
|
72
75
|
|
76
|
+
def shutdown
|
77
|
+
`kill -TERM #{pid}`
|
78
|
+
end
|
79
|
+
|
80
|
+
def pid
|
81
|
+
File.read(options[:pidfile]).to_i
|
82
|
+
end
|
83
|
+
|
73
84
|
def produce
|
74
85
|
RabbitFeed::Producer.publish_event options[:name], options[:payload]
|
75
86
|
end
|
@@ -82,7 +93,8 @@ module RabbitFeed
|
|
82
93
|
def set_configuration
|
83
94
|
RabbitFeed.environment = environment
|
84
95
|
RabbitFeed.configuration_file_path = options[:config_file]
|
85
|
-
ENV['RACK_ENV']
|
96
|
+
ENV['RACK_ENV'] ||= RabbitFeed.environment
|
97
|
+
ENV['RAILS_ENV'] ||= RabbitFeed.environment
|
86
98
|
end
|
87
99
|
|
88
100
|
def load_dependancies
|
@@ -102,11 +114,11 @@ module RabbitFeed
|
|
102
114
|
end
|
103
115
|
|
104
116
|
def environment
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
117
|
+
[options[:environment], ENV['RACK_ENV'], ENV['RAILS_ENV']].detect(&:present?)
|
118
|
+
end
|
119
|
+
|
120
|
+
def shutdown?
|
121
|
+
command == 'shutdown'
|
110
122
|
end
|
111
123
|
|
112
124
|
def daemonize?
|
@@ -28,6 +28,8 @@ module RabbitFeed
|
|
28
28
|
def self.load file_path, environment
|
29
29
|
RabbitFeed.log.debug "Reading configurations from #{file_path} in #{environment}..."
|
30
30
|
|
31
|
+
raise ConfigurationError.new "The RabbitFeed configuration file path specified does not exist: #{file_path}" unless (File.exist? file_path)
|
32
|
+
|
31
33
|
options = read_configuration_file file_path, environment
|
32
34
|
new options.merge(environment: environment)
|
33
35
|
end
|
@@ -65,26 +65,50 @@ module RabbitFeed
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
attr_reader :
|
68
|
+
attr_reader :named_applications, :catch_all_application
|
69
69
|
|
70
70
|
def initialize
|
71
|
-
@
|
71
|
+
@named_applications = {}
|
72
72
|
end
|
73
73
|
|
74
74
|
def accept_from name, &block
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
if name == :any
|
76
|
+
accept_from_any_application &block
|
77
|
+
else
|
78
|
+
accept_from_named_application name, &block
|
79
|
+
end
|
78
80
|
end
|
79
81
|
|
80
82
|
def accepted_routes
|
81
|
-
|
83
|
+
routes = named_applications.values.map{|application| application.accepted_routes }.flatten
|
84
|
+
routes += catch_all_application.accepted_routes if catch_all_application.present?
|
85
|
+
routes
|
82
86
|
end
|
83
87
|
|
84
88
|
def handle_event event
|
85
|
-
application =
|
89
|
+
application = find_application event.application
|
86
90
|
raise RoutingError.new "No routing defined for application with name: #{event.application}" unless application.present?
|
87
91
|
application.handle_event event
|
88
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def accept_from_named_application name, &block
|
97
|
+
raise ConfigurationError.new "Routing has already been defined for the application with name: #{name}" if (named_applications.has_key? name)
|
98
|
+
application = Application.new name
|
99
|
+
application.instance_eval(&block)
|
100
|
+
named_applications[application.name] = application
|
101
|
+
end
|
102
|
+
|
103
|
+
def accept_from_any_application &block
|
104
|
+
raise ConfigurationError.new "Routing has already been defined for the application catch-all: :any" if catch_all_application.present?
|
105
|
+
application = Application.new '*'
|
106
|
+
application.instance_eval(&block)
|
107
|
+
@catch_all_application = application
|
108
|
+
end
|
109
|
+
|
110
|
+
def find_application name
|
111
|
+
named_applications[name] || catch_all_application
|
112
|
+
end
|
89
113
|
end
|
90
114
|
end
|
data/lib/rabbit_feed/producer.rb
CHANGED
@@ -2,13 +2,11 @@ module RabbitFeed
|
|
2
2
|
module TestingSupport
|
3
3
|
module RSpecMatchers
|
4
4
|
class PublishEvent
|
5
|
-
attr_reader :expected_event, :expected_payload
|
5
|
+
attr_reader :expected_event, :expected_payload
|
6
6
|
|
7
7
|
def initialize(expected_event, expected_payload)
|
8
8
|
@expected_event = expected_event
|
9
9
|
@expected_payload = expected_payload
|
10
|
-
@received_events = []
|
11
|
-
stub_publish
|
12
10
|
end
|
13
11
|
|
14
12
|
def matches?(given_proc, negative_expectation = false)
|
@@ -22,7 +20,7 @@ module RabbitFeed
|
|
22
20
|
rescue
|
23
21
|
end
|
24
22
|
|
25
|
-
actual_event =
|
23
|
+
actual_event = TestingSupport.published_events.detect do |event|
|
26
24
|
event.name == expected_event
|
27
25
|
end
|
28
26
|
|
@@ -31,7 +29,7 @@ module RabbitFeed
|
|
31
29
|
with_expected_payload = negative_expectation
|
32
30
|
if received_expected_event && !with_expected_payload
|
33
31
|
actual_payload = (strip_defaults_from actual_event.payload)
|
34
|
-
with_expected_payload = actual_payload == expected_payload
|
32
|
+
with_expected_payload = expected_payload.nil? || actual_payload == expected_payload
|
35
33
|
end
|
36
34
|
|
37
35
|
return received_expected_event && with_expected_payload
|
@@ -44,7 +42,7 @@ module RabbitFeed
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def failure_message
|
47
|
-
"expected #{expected_event} with #{expected_payload} but instead received #{received_events_message}"
|
45
|
+
"expected #{expected_event} with #{expected_payload || 'some payload'} but instead received #{received_events_message}"
|
48
46
|
end
|
49
47
|
|
50
48
|
def negative_failure_message
|
@@ -57,6 +55,10 @@ module RabbitFeed
|
|
57
55
|
"publish_event #{expected_event}"
|
58
56
|
end
|
59
57
|
|
58
|
+
def supports_block_expectations?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
60
62
|
private
|
61
63
|
|
62
64
|
def strip_defaults_from payload
|
@@ -66,23 +68,17 @@ module RabbitFeed
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def received_events_message
|
69
|
-
if
|
70
|
-
|
71
|
+
if TestingSupport.published_events.any?
|
72
|
+
TestingSupport.published_events.map do |received_event|
|
71
73
|
"#{received_event.name} with #{strip_defaults_from received_event.payload}"
|
72
74
|
end
|
73
75
|
else
|
74
76
|
'no events'
|
75
77
|
end
|
76
78
|
end
|
77
|
-
|
78
|
-
def stub_publish
|
79
|
-
ProducerConnection.stub(:publish) do |serialized_event, routing_key|
|
80
|
-
@received_events << (Event.deserialize serialized_event)
|
81
|
-
end
|
82
|
-
end
|
83
79
|
end
|
84
80
|
|
85
|
-
def publish_event(expected_event, expected_payload)
|
81
|
+
def publish_event(expected_event, expected_payload = nil)
|
86
82
|
PublishEvent.new(expected_event, expected_payload)
|
87
83
|
end
|
88
84
|
end
|