rabbit_feed 2.4.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +81 -0
- data/README.md +39 -5
- data/Rakefile +3 -19
- data/bin/rabbit_feed +0 -1
- data/example/non_rails_app/Gemfile.lock +29 -32
- data/example/non_rails_app/Rakefile +1 -1
- data/example/non_rails_app/bin/benchmark +3 -3
- data/example/non_rails_app/lib/non_rails_app/event_handler.rb +1 -1
- data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +3 -4
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +3 -3
- data/example/rails_app/Gemfile +4 -16
- data/example/rails_app/Gemfile.lock +131 -137
- data/example/rails_app/app/assets/javascripts/application.js +0 -1
- data/example/rails_app/app/controllers/application_controller.rb +0 -3
- data/example/rails_app/app/controllers/beavers_controller.rb +14 -15
- data/example/rails_app/bin/rails +1 -1
- data/example/rails_app/config/environments/development.rb +1 -1
- data/example/rails_app/config/environments/test.rb +2 -2
- data/example/rails_app/config/initializers/cookies_serializer.rb +1 -1
- data/example/rails_app/config/unicorn.rb +1 -1
- data/example/rails_app/config.ru +1 -1
- data/example/rails_app/db/schema.rb +5 -7
- data/example/rails_app/lib/event_handler.rb +1 -1
- data/example/rails_app/spec/controllers/beavers_controller_spec.rb +9 -10
- data/example/rails_app/spec/event_routing_spec.rb +1 -2
- data/example/rails_app/test/controllers/beavers_controller_test.rb +12 -12
- data/lib/dsl.rb +4 -4
- data/lib/rabbit_feed/client.rb +17 -23
- data/lib/rabbit_feed/configuration.rb +10 -9
- data/lib/rabbit_feed/connection.rb +3 -3
- data/lib/rabbit_feed/console_consumer.rb +22 -24
- data/lib/rabbit_feed/consumer.rb +2 -2
- data/lib/rabbit_feed/consumer_connection.rb +21 -22
- data/lib/rabbit_feed/event.rb +8 -28
- data/lib/rabbit_feed/event_definitions.rb +14 -15
- data/lib/rabbit_feed/event_routing.rb +26 -27
- data/lib/rabbit_feed/json_log_formatter.rb +1 -1
- data/lib/rabbit_feed/producer.rb +13 -13
- data/lib/rabbit_feed/producer_connection.rb +8 -9
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +52 -89
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +1 -2
- data/lib/rabbit_feed/testing_support/testing_helpers.rb +0 -1
- data/lib/rabbit_feed/testing_support.rb +5 -6
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +12 -13
- data/rabbit_feed.gemspec +16 -14
- data/run_benchmark +4 -3
- data/run_example +1 -1
- data/spec/features/step_definitions/connectivity_steps.rb +6 -9
- data/spec/lib/rabbit_feed/client_spec.rb +8 -9
- data/spec/lib/rabbit_feed/configuration_spec.rb +20 -23
- data/spec/lib/rabbit_feed/console_consumer_spec.rb +11 -13
- data/spec/lib/rabbit_feed/consumer_connection_spec.rb +26 -28
- data/spec/lib/rabbit_feed/event_definitions_spec.rb +31 -31
- data/spec/lib/rabbit_feed/event_routing_spec.rb +35 -62
- data/spec/lib/rabbit_feed/event_spec.rb +40 -87
- data/spec/lib/rabbit_feed/producer_connection_spec.rb +11 -7
- data/spec/lib/rabbit_feed/producer_spec.rb +16 -19
- data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +82 -87
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -10
- metadata +67 -45
- data/example/rails_app/README.rdoc +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341e94f0f96334c74f5f14a9bd394cb076602342
|
4
|
+
data.tar.gz: d6a2b2fea2255493db135aec552d48493d2e35fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7975aa142d54f3c36880776842680d6b7c1b07c0d3a3973d2622149b2801d303b1b4d99bd26245483827fef0dad1470cdb081984e23dff57d43d03352c9c1f34
|
7
|
+
data.tar.gz: 396188946a955bd285ea5146e33652f171501e5f54a349431917df947a3e9e87c386ffb6c158a9b3993c460ae5c79c882424787c88ad3b732821600a1559f4f3
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
Lint/HandleExceptions:
|
2
|
+
Exclude:
|
3
|
+
- 'example/non_rails_app/bin/benchmark'
|
4
|
+
- 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
|
5
|
+
- 'spec/features/step_definitions/connectivity_steps.rb'
|
6
|
+
- 'spec/lib/rabbit_feed/consumer_connection_spec.rb'
|
7
|
+
- 'spec/lib/rabbit_feed/producer_connection_spec.rb'
|
8
|
+
|
9
|
+
Style/RescueModifier:
|
10
|
+
Exclude:
|
11
|
+
- 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/rabbit_feed/client.rb'
|
16
|
+
- 'lib/rabbit_feed/configuration.rb'
|
17
|
+
- 'lib/rabbit_feed/consumer_connection.rb'
|
18
|
+
- 'lib/rabbit_feed/producer.rb'
|
19
|
+
- 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/ClassLength:
|
25
|
+
Exclude:
|
26
|
+
- 'lib/rabbit_feed/client.rb'
|
27
|
+
|
28
|
+
Metrics/CyclomaticComplexity:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/rabbit_feed/configuration.rb'
|
31
|
+
- 'lib/rabbit_feed.rb'
|
32
|
+
- 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
|
33
|
+
|
34
|
+
Metrics/LineLength:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Max: 20
|
39
|
+
Exclude:
|
40
|
+
- 'lib/rabbit_feed/client.rb'
|
41
|
+
|
42
|
+
Metrics/ModuleLength:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Metrics/PerceivedComplexity:
|
46
|
+
Exclude:
|
47
|
+
- 'lib/rabbit_feed/configuration.rb'
|
48
|
+
- 'lib/rabbit_feed.rb'
|
49
|
+
- 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
|
50
|
+
|
51
|
+
Style/Documentation:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/DoubleNegation:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/ClassAndModuleChildren:
|
58
|
+
Exclude:
|
59
|
+
- 'example/rails_app/test/test_helper.rb'
|
60
|
+
- 'spec/features/step_definitions/connectivity_steps.rb'
|
61
|
+
- 'spec/lib/rabbit_feed/consumer_connection_spec.rb'
|
62
|
+
- 'spec/lib/rabbit_feed/producer_connection_spec.rb'
|
63
|
+
|
64
|
+
Style/FirstParameterIndentation:
|
65
|
+
Exclude:
|
66
|
+
- 'spec/lib/rabbit_feed/console_consumer_spec.rb'
|
67
|
+
|
68
|
+
Style/MethodName:
|
69
|
+
Exclude:
|
70
|
+
- 'lib/dsl.rb'
|
71
|
+
|
72
|
+
Style/ModuleFunction:
|
73
|
+
EnforcedStyle: 'extend_self'
|
74
|
+
|
75
|
+
Style/MultilineBlockChain:
|
76
|
+
Exclude:
|
77
|
+
- 'spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb'
|
78
|
+
|
79
|
+
Style/SymbolProc:
|
80
|
+
Exclude:
|
81
|
+
- 'spec/lib/rabbit_feed/event_routing_spec.rb'
|
data/README.md
CHANGED
@@ -151,7 +151,7 @@ RSpec.configure do |config|
|
|
151
151
|
end
|
152
152
|
```
|
153
153
|
|
154
|
-
|
154
|
+
Validating an event was published by event name:
|
155
155
|
|
156
156
|
```ruby
|
157
157
|
require 'spec_helper'
|
@@ -162,19 +162,53 @@ describe BeaversController do
|
|
162
162
|
it 'publishes a create event' do
|
163
163
|
expect{
|
164
164
|
post :create, beaver: { name: 'beaver' }
|
165
|
-
}.to publish_event('user_creates_beaver'
|
165
|
+
}.to publish_event('user_creates_beaver')
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
169
|
```
|
170
170
|
|
171
|
-
|
171
|
+
Validating an event was published by event name and payload:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
require 'spec_helper'
|
175
|
+
|
176
|
+
describe BeaversController do
|
177
|
+
|
178
|
+
describe 'POST create' do
|
179
|
+
it 'publishes a create event' do
|
180
|
+
expect{
|
181
|
+
post :create, beaver: { name: 'beaver' }
|
182
|
+
}.to publish_event('user_creates_beaver', 'beaver_name' => 'beaver')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
188
|
+
Validating an event was published by event name and partial payload match:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
require 'spec_helper'
|
192
|
+
|
193
|
+
describe BeaversController do
|
194
|
+
|
195
|
+
describe 'POST create' do
|
196
|
+
it 'publishes a create event' do
|
197
|
+
expect{
|
198
|
+
post :create, beaver: { name: 'beaver' }
|
199
|
+
}.to publish_event('user_creates_beaver').including('beaver_name' => 'beaver')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
You can also use the `.asserting` chain, allowing you to provide your own expectation on the event's payload:
|
172
206
|
|
173
207
|
```ruby
|
174
208
|
it 'publishes a create event' do
|
175
209
|
expect{
|
176
210
|
post :create, beaver: { name: 'beaver' }
|
177
|
-
}.to publish_event('user_creates_beaver', nil) do |payload|
|
211
|
+
}.to publish_event('user_creates_beaver', nil).asserting do |payload|
|
178
212
|
expect(payload['beaver_name']).to match(/ea/)
|
179
213
|
end
|
180
214
|
end
|
@@ -228,7 +262,7 @@ describe 'consuming events' do
|
|
228
262
|
|
229
263
|
before { define_route }
|
230
264
|
|
231
|
-
it '
|
265
|
+
it 'routes to the correct service' do
|
232
266
|
rabbit_feed_consumer.consume_event(event)
|
233
267
|
expect(accumulator.size).to eq(1)
|
234
268
|
end
|
data/Rakefile
CHANGED
@@ -1,30 +1,14 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
1
|
require 'rspec/core/rake_task'
|
3
2
|
|
4
3
|
desc 'Default: run specs and features'
|
5
|
-
task :
|
4
|
+
task default: [:all]
|
6
5
|
|
7
6
|
desc 'Run specs and features'
|
8
7
|
RSpec::Core::RakeTask.new(:all) do |t|
|
9
|
-
t.pattern =
|
8
|
+
t.pattern = 'spec/{**/*_spec.rb,features/**/*.feature}'
|
10
9
|
end
|
11
10
|
|
12
11
|
desc 'Run specs'
|
13
12
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
|
-
t.pattern =
|
13
|
+
t.pattern = 'spec/**/*_spec.rb'
|
15
14
|
end
|
16
|
-
|
17
|
-
def gemspec
|
18
|
-
@gemspec ||= eval(File.read('rabbit_feed.gemspec'))
|
19
|
-
end
|
20
|
-
|
21
|
-
desc 'Validate gemspec'
|
22
|
-
task :validate_gemspec do
|
23
|
-
gemspec.validate
|
24
|
-
end
|
25
|
-
|
26
|
-
desc 'Print version'
|
27
|
-
task :version do
|
28
|
-
puts gemspec.version
|
29
|
-
end
|
30
|
-
|
data/bin/rabbit_feed
CHANGED
@@ -1,51 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
rabbit_feed (
|
5
|
-
activemodel (>= 3.2.0, <
|
6
|
-
activesupport (>= 3.2.0, <
|
7
|
-
avro (>= 1.5.4, < 1.
|
8
|
-
bunny (>= 2.0.0, < 2.
|
9
|
-
pidfile
|
4
|
+
rabbit_feed (3.0.0)
|
5
|
+
activemodel (>= 3.2.0, < 6.0.0)
|
6
|
+
activesupport (>= 3.2.0, < 6.0.0)
|
7
|
+
avro (>= 1.5.4, < 1.9.0)
|
8
|
+
bunny (>= 2.0.0, < 2.7.0)
|
9
|
+
pidfile (~> 0.3)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activemodel (
|
15
|
-
activesupport (=
|
16
|
-
|
17
|
-
|
14
|
+
activemodel (5.0.1)
|
15
|
+
activesupport (= 5.0.1)
|
16
|
+
activesupport (5.0.1)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (~> 0.7)
|
19
|
-
json (~> 1.7, >= 1.7.7)
|
20
19
|
minitest (~> 5.1)
|
21
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
22
20
|
tzinfo (~> 1.1)
|
23
21
|
amq-protocol (2.0.1)
|
24
|
-
avro (1.
|
22
|
+
avro (1.8.1)
|
25
23
|
multi_json
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
bunny (2.6.2)
|
25
|
+
amq-protocol (>= 2.0.1)
|
26
|
+
concurrent-ruby (1.0.4)
|
29
27
|
diff-lcs (1.2.5)
|
30
28
|
i18n (0.7.0)
|
31
|
-
|
32
|
-
|
33
|
-
multi_json (1.12.0)
|
29
|
+
minitest (5.10.1)
|
30
|
+
multi_json (1.12.1)
|
34
31
|
pidfile (0.3.0)
|
35
|
-
rake (
|
36
|
-
rspec (3.
|
37
|
-
rspec-core (~> 3.
|
38
|
-
rspec-expectations (~> 3.
|
39
|
-
rspec-mocks (~> 3.
|
40
|
-
rspec-core (3.
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-expectations (3.
|
32
|
+
rake (12.0.0)
|
33
|
+
rspec (3.5.0)
|
34
|
+
rspec-core (~> 3.5.0)
|
35
|
+
rspec-expectations (~> 3.5.0)
|
36
|
+
rspec-mocks (~> 3.5.0)
|
37
|
+
rspec-core (3.5.4)
|
38
|
+
rspec-support (~> 3.5.0)
|
39
|
+
rspec-expectations (3.5.0)
|
43
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-mocks (3.
|
41
|
+
rspec-support (~> 3.5.0)
|
42
|
+
rspec-mocks (3.5.0)
|
46
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-support (3.
|
44
|
+
rspec-support (~> 3.5.0)
|
45
|
+
rspec-support (3.5.0)
|
49
46
|
thread_safe (0.3.5)
|
50
47
|
tzinfo (1.2.2)
|
51
48
|
thread_safe (~> 0.1)
|
@@ -59,4 +56,4 @@ DEPENDENCIES
|
|
59
56
|
rspec
|
60
57
|
|
61
58
|
BUNDLED WITH
|
62
|
-
1.
|
59
|
+
1.13.7
|
@@ -9,7 +9,7 @@ I18n.enforce_available_locales = true
|
|
9
9
|
|
10
10
|
RabbitFeed.environment = 'development'
|
11
11
|
|
12
|
-
payload = 'abc'*5000
|
12
|
+
payload = 'abc' * 5000
|
13
13
|
number_of_events = 5000
|
14
14
|
|
15
15
|
EventDefinitions do
|
@@ -25,14 +25,14 @@ end
|
|
25
25
|
|
26
26
|
puts "Publishing #{number_of_events} events..."
|
27
27
|
Benchmark.bm do |x|
|
28
|
-
x.report { number_of_events.times { RabbitFeed::Producer.publish_event 'test_event',
|
28
|
+
x.report { number_of_events.times { RabbitFeed::Producer.publish_event 'test_event', 'data' => payload } }
|
29
29
|
end
|
30
30
|
|
31
31
|
events_consumed = 0
|
32
32
|
|
33
33
|
EventRouting do
|
34
34
|
accept_from('non_rails_app') do
|
35
|
-
event('test_event') do |
|
35
|
+
event('test_event') do |_event|
|
36
36
|
events_consumed += 1
|
37
37
|
Thread.main.raise Interrupt if events_consumed >= number_of_events
|
38
38
|
end
|
@@ -2,7 +2,7 @@ module NonRailsApp
|
|
2
2
|
module EventHandler
|
3
3
|
extend self
|
4
4
|
|
5
|
-
def handle_event
|
5
|
+
def handle_event(event)
|
6
6
|
puts "NonRailsApp::EventHandler - Consumed event: #{event.name} with payload: #{event.payload}"
|
7
7
|
RabbitFeed::Producer.publish_event 'application_acknowledges_event', ({ 'event_name' => event.name }.merge event.payload)
|
8
8
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module NonRailsApp
|
2
2
|
describe EventHandler do
|
3
|
-
|
4
3
|
describe '#handle_event' do
|
5
4
|
it 'publishes an update event' do
|
6
|
-
expect
|
7
|
-
described_class.handle_event RabbitFeed::Event.new({'name' => 'user_updates_beaver', 'application' => 'rails_app'},
|
8
|
-
|
5
|
+
expect do
|
6
|
+
described_class.handle_event RabbitFeed::Event.new({ 'name' => 'user_updates_beaver', 'application' => 'rails_app' }, 'beaver_name' => 'beaver')
|
7
|
+
end.to publish_event('application_acknowledges_event', 'beaver_name' => 'beaver', 'event_name' => 'user_updates_beaver')
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module NonRailsApp
|
2
2
|
describe 'Event Routing' do
|
3
|
-
let(:payload) { {'field' => 'value'} }
|
4
|
-
let(:metadata) { {'application' => 'rails_app', 'name' => 'user_creates_beaver'} }
|
3
|
+
let(:payload) { { 'field' => 'value' } }
|
4
|
+
let(:metadata) { { 'application' => 'rails_app', 'name' => 'user_creates_beaver' } }
|
5
5
|
let(:event) { RabbitFeed::Event.new metadata, payload }
|
6
6
|
|
7
7
|
it 'routes events correctly' do
|
8
|
-
expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(payload)}
|
8
|
+
expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(payload) }
|
9
9
|
rabbit_feed_consumer.consume_event(event)
|
10
10
|
end
|
11
11
|
end
|
data/example/rails_app/Gemfile
CHANGED
@@ -1,30 +1,17 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
-
gem 'rails', '
|
4
|
+
gem 'rails', '~> 5.0'
|
5
5
|
# Use sqlite3 as the database for Active Record
|
6
6
|
gem 'sqlite3'
|
7
7
|
# Use SCSS for stylesheets
|
8
|
-
gem 'sass-rails'
|
8
|
+
gem 'sass-rails'
|
9
9
|
# Use Uglifier as compressor for JavaScript assets
|
10
10
|
gem 'uglifier', '>= 1.3.0'
|
11
11
|
# Use CoffeeScript for .js.coffee assets and views
|
12
|
-
gem 'coffee-rails'
|
13
|
-
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
14
|
-
# gem 'therubyracer', platforms: :ruby
|
15
|
-
|
12
|
+
gem 'coffee-rails'
|
16
13
|
# Use jquery as the JavaScript library
|
17
14
|
gem 'jquery-rails'
|
18
|
-
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
19
|
-
gem 'turbolinks'
|
20
|
-
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
21
|
-
gem 'jbuilder', '~> 2.0'
|
22
|
-
# bundle exec rake doc:rails generates the API under doc/api.
|
23
|
-
gem 'sdoc', '~> 0.4.0', group: :doc
|
24
|
-
|
25
|
-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
26
|
-
gem 'spring', group: :development
|
27
|
-
|
28
15
|
# Use unicorn as the app server
|
29
16
|
gem 'unicorn'
|
30
17
|
|
@@ -33,4 +20,5 @@ gem 'unicorn'
|
|
33
20
|
|
34
21
|
gem 'rabbit_feed', path: '../../'
|
35
22
|
|
23
|
+
gem 'rails-controller-testing', group: :test
|
36
24
|
gem 'rspec-rails', group: :test
|