rabbit_feed 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/DEVELOPING.md +6 -6
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +60 -52
  5. data/README.md +30 -14
  6. data/example/non_rails_app/Gemfile.lock +27 -23
  7. data/example/non_rails_app/bin/benchmark +3 -5
  8. data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +2 -4
  9. data/example/non_rails_app/spec/spec_helper.rb +3 -11
  10. data/example/rails_app/Gemfile +1 -1
  11. data/example/rails_app/Gemfile.lock +111 -94
  12. data/example/rails_app/config/environments/development.rb +1 -1
  13. data/example/rails_app/config/environments/test.rb +1 -1
  14. data/example/rails_app/config/initializers/rabbit_feed.rb +0 -7
  15. data/example/rails_app/spec/controllers/beavers_controller_spec.rb +1 -1
  16. data/example/rails_app/spec/event_routing_spec.rb +2 -5
  17. data/example/rails_app/spec/rails_helper.rb +52 -0
  18. data/example/rails_app/spec/spec_helper.rb +1 -44
  19. data/lib/rabbit_feed/client.rb +23 -11
  20. data/lib/rabbit_feed/configuration.rb +2 -0
  21. data/lib/rabbit_feed/event_routing.rb +31 -7
  22. data/lib/rabbit_feed/producer.rb +0 -4
  23. data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +11 -15
  24. data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +10 -0
  25. data/lib/rabbit_feed/testing_support/testing_helpers.rb +1 -7
  26. data/lib/rabbit_feed/testing_support.rb +32 -0
  27. data/lib/rabbit_feed/version.rb +1 -1
  28. data/lib/rabbit_feed.rb +5 -4
  29. data/rabbit_feed.gemspec +8 -8
  30. data/spec/lib/rabbit_feed/configuration_spec.rb +15 -7
  31. data/spec/lib/rabbit_feed/event_routing_spec.rb +41 -1
  32. data/spec/lib/rabbit_feed/producer_spec.rb +1 -1
  33. data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +17 -2
  34. data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +0 -3
  35. data/spec/spec_helper.rb +6 -1
  36. metadata +53 -19
@@ -1,16 +1,10 @@
1
1
  module RabbitFeed
2
2
  module TestingSupport
3
3
  module TestingHelpers
4
+
4
5
  def rabbit_feed_consumer
5
6
  TestRabbitFeedConsumer.new
6
7
  end
7
8
  end
8
-
9
- class TestRabbitFeedConsumer
10
- def consume_event(event)
11
- event = Event.new('no schema',event)
12
- RabbitFeed::Consumer.event_routing.handle_event(event)
13
- end
14
- end
15
9
  end
16
10
  end
@@ -0,0 +1,32 @@
1
+ require 'rabbit_feed/testing_support/rspec_matchers/publish_event'
2
+ require 'rabbit_feed/testing_support/test_rabbit_feed_consumer'
3
+ require 'rabbit_feed/testing_support/testing_helpers'
4
+
5
+ module RabbitFeed
6
+ module TestingSupport
7
+ extend self
8
+
9
+ attr_accessor :published_events
10
+
11
+ def setup rspec_config
12
+ capture_published_events rspec_config
13
+ include_support rspec_config
14
+ end
15
+
16
+ def capture_published_events rspec_config
17
+ rspec_config.before :each do
18
+
19
+ TestingSupport.published_events = []
20
+
21
+ allow(RabbitFeed::ProducerConnection).to receive(:publish) do |serialized_event, routing_key|
22
+ TestingSupport.published_events << (Event.deserialize serialized_event)
23
+ end
24
+ end
25
+ end
26
+
27
+ def include_support rspec_config
28
+ rspec_config.include(RabbitFeed::TestingSupport::RSpecMatchers)
29
+ rspec_config.include(RabbitFeed::TestingSupport::TestingHelpers)
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module RabbitFeed
2
- VERSION = '0.3.1'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/rabbit_feed.rb CHANGED
@@ -16,8 +16,7 @@ require 'rabbit_feed/event_routing'
16
16
  require 'rabbit_feed/producer_connection'
17
17
  require 'rabbit_feed/producer'
18
18
  require 'rabbit_feed/event_definitions'
19
- require 'rabbit_feed/testing_support/rspec_matchers/publish_event'
20
- require 'rabbit_feed/testing_support/testing_helpers'
19
+ require 'rabbit_feed/testing_support'
21
20
 
22
21
  module RabbitFeed
23
22
  extend self
@@ -29,8 +28,10 @@ module RabbitFeed
29
28
  attr_accessor :log, :environment, :configuration_file_path
30
29
 
31
30
  def configuration
32
- raise ConfigurationError.new 'rabbit feed log is not set' unless log.present?
33
- @configuration ||= (Configuration.load RabbitFeed.configuration_file_path, RabbitFeed.environment)
31
+ RabbitFeed.log ||= (Logger.new STDOUT)
32
+ RabbitFeed.configuration_file_path ||= 'config/rabbit_feed.yml'
33
+ RabbitFeed.environment ||= ENV['RAILS_ENV'] || ENV['RACK_ENV']
34
+ @configuration ||= (Configuration.load RabbitFeed.configuration_file_path, RabbitFeed.environment)
34
35
  end
35
36
 
36
37
  def exception_notify exception
data/rabbit_feed.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RabbitFeed::VERSION
9
9
  spec.authors = ['Simply Business']
10
10
  spec.email = ['tech@simplybusiness.co.uk']
11
- spec.description = %q{A gem allowing your application to publish messages to RabbitMQ}
12
- spec.summary = %q{This will enable your application to publish messages to a bus to be processed by other services}
11
+ spec.description = %q{A gem providing asynchronous event publish and subscribe capabilities with RabbitMQ.}
12
+ spec.summary = %q{Enables your Ruby applications to perform centralized event logging with RabbitMq}
13
13
  spec.homepage = 'https://github.com/simplybusiness/rabbit_feed'
14
14
  spec.license = 'MIT'
15
15
 
@@ -19,17 +19,17 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  # Gem for interfacing with RabbitMq
22
- spec.add_dependency 'bunny'
22
+ spec.add_dependency 'bunny', '>= 1.1.9', '< 1.7.0'
23
23
  # We use some helpers from ActiveSupport
24
- spec.add_dependency 'activesupport'
24
+ spec.add_dependency 'activesupport', '>= 3.2.0', '< 5.0.0'
25
25
  # We use validations from ActiveModel
26
- spec.add_dependency 'activemodel'
26
+ spec.add_dependency 'activemodel', '>= 3.2.0', '< 5.0.0'
27
27
  # Provides connection pooling for the producer connections
28
- spec.add_dependency 'connection_pool'
28
+ spec.add_dependency 'connection_pool', '< 2.2.0'
29
29
  # Manages process pidfile
30
30
  spec.add_dependency 'pidfile'
31
31
  # Schema definitions and serialization for events
32
- spec.add_dependency 'avro'
32
+ spec.add_dependency 'avro', '>= 1.5.4', '< 1.8.0'
33
33
  # For stubbing and custom matchers
34
- spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'rspec', '>=2.14.0', '< 3.2.0'
35
35
  end
@@ -23,7 +23,15 @@ module RabbitFeed
23
23
  context 'with missing configuration' do
24
24
  let(:environment) { 'production' }
25
25
 
26
- it 'should raise an error' do
26
+ it 'raises an error' do
27
+ expect{ subject }.to raise_error ConfigurationError
28
+ end
29
+ end
30
+
31
+ context 'with missing configuration file' do
32
+ let(:file_path) { 'I do not exist' }
33
+
34
+ it 'raises an error' do
27
35
  expect{ subject }.to raise_error ConfigurationError
28
36
  end
29
37
  end
@@ -42,8 +50,8 @@ module RabbitFeed
42
50
  its(:heartbeat) { should eq 60 }
43
51
  its(:connect_timeout) { should eq 1 }
44
52
  its(:network_recovery_interval) { should eq 0.1 }
45
- its(:auto_delete_queue) { should be_true }
46
- its(:auto_delete_exchange) { should be_true }
53
+ its(:auto_delete_queue) { should be_truthy }
54
+ its(:auto_delete_exchange) { should be_truthy }
47
55
  end
48
56
 
49
57
  end
@@ -70,8 +78,8 @@ module RabbitFeed
70
78
  its(:heartbeat) { should eq 5 }
71
79
  its(:connect_timeout) { should eq 10 }
72
80
  its(:network_recovery_interval) { should eq 1 }
73
- its(:auto_delete_queue) { should be_false }
74
- its(:auto_delete_exchange) { should be_false }
81
+ its(:auto_delete_queue) { should be_falsey }
82
+ its(:auto_delete_exchange) { should be_falsey }
75
83
  end
76
84
 
77
85
  context 'with provided options' do
@@ -106,8 +114,8 @@ module RabbitFeed
106
114
  its(:heartbeat) { should eq 3 }
107
115
  its(:connect_timeout) { should eq 4 }
108
116
  its(:network_recovery_interval) { should eq 2 }
109
- its(:auto_delete_queue) { should be_true }
110
- its(:auto_delete_exchange) { should be_true }
117
+ its(:auto_delete_queue) { should be_truthy }
118
+ its(:auto_delete_exchange) { should be_truthy }
111
119
  end
112
120
 
113
121
  context 'with empty options' do
@@ -17,6 +17,14 @@ module RabbitFeed
17
17
  event.payload
18
18
  end
19
19
  end
20
+ accept_from(:any) do
21
+ event('event_3') do |event|
22
+ raise 'event_3 from any app'
23
+ end
24
+ event('event_4') do |event|
25
+ event.payload
26
+ end
27
+ end
20
28
  end
21
29
  end
22
30
 
@@ -26,14 +34,17 @@ module RabbitFeed
26
34
  test.dummy_1.event_1
27
35
  test.dummy_1.event_2
28
36
  test.dummy_2.event_3
37
+ test.*.event_3
38
+ test.*.event_4
29
39
  }
30
40
  end
31
41
 
32
- it 'routes the event to the correct action' do
42
+ it 'routes the event to the correct action, preferring named applications' do
33
43
  events = [
34
44
  double(:event, application: 'dummy_1', name: 'event_1', payload: 1),
35
45
  double(:event, application: 'dummy_1', name: 'event_2', payload: 2),
36
46
  double(:event, application: 'dummy_2', name: 'event_3', payload: 3),
47
+ double(:event, application: 'none', name: 'event_4', payload: 4),
37
48
  ]
38
49
  events.each do |event|
39
50
  (RabbitFeed::Consumer.event_routing.handle_event event).should eq event.payload
@@ -114,8 +125,37 @@ module RabbitFeed
114
125
  test.dummy_1.event_2
115
126
  test.dummy_2.event_3
116
127
  test.dummy_3.event_4
128
+ test.*.event_3
129
+ test.*.event_4
117
130
  }
118
131
  end
119
132
  end
133
+
134
+ context 'defining the same application twice' do
135
+
136
+ it 'raises an exception for a named application' do
137
+ expect do
138
+ EventRouting do
139
+ accept_from('dummy_2') do
140
+ event('event_4') do |event|
141
+ event.payload
142
+ end
143
+ end
144
+ end
145
+ end.to raise_error ConfigurationError
146
+ end
147
+
148
+ it 'raises an exception for the catch-all application' do
149
+ expect do
150
+ EventRouting do
151
+ accept_from(:any) do
152
+ event('event_4') do |event|
153
+ event.payload
154
+ end
155
+ end
156
+ end
157
+ end.to raise_error ConfigurationError
158
+ end
159
+ end
120
160
  end
121
161
  end
@@ -5,7 +5,7 @@ module RabbitFeed
5
5
  describe '.publish' do
6
6
  let(:event_name) { 'event_name' }
7
7
  before do
8
- RabbitFeed::Producer.stub!
8
+ allow(RabbitFeed::ProducerConnection).to receive(:publish)
9
9
  EventDefinitions do
10
10
  define_event('event_name', version: '1.0.0') do
11
11
  defined_as do
@@ -6,6 +6,7 @@ module RabbitFeed
6
6
  describe PublishEvent do
7
7
  let(:event_name) { 'test_event' }
8
8
  let(:event_payload) { {'field' => 'value'} }
9
+ TestingSupport.capture_published_events self
9
10
  before do
10
11
  EventDefinitions do
11
12
  define_event('test_event', version: '1.0.0') do
@@ -41,18 +42,32 @@ module RabbitFeed
41
42
  raise 'this hurts me more than it hurts you'
42
43
  }.to_not publish_event(event_name, {})
43
44
  end
45
+
46
+ context 'when not validating the payload' do
47
+ it 'validates' do
48
+ expect {
49
+ RabbitFeed::Producer.publish_event event_name, event_payload
50
+ }.to publish_event(event_name)
51
+ end
52
+
53
+ it 'validates the negation' do
54
+ expect {
55
+ RabbitFeed::Producer.publish_event 'different name', {}
56
+ }.to_not publish_event(event_name)
57
+ end
58
+ end
44
59
  end
45
60
 
46
61
  it 'validates the event name' do
47
62
  matcher = described_class.new(event_name, {})
48
63
  block = Proc.new { RabbitFeed::Producer.publish_event 'different name', {} }
49
- (matcher.matches? block).should be_false
64
+ (matcher.matches? block).should be_falsey
50
65
  end
51
66
 
52
67
  it 'validates the event payload' do
53
68
  matcher = described_class.new(event_name, event_payload)
54
69
  block = Proc.new { RabbitFeed::Producer.publish_event event_name, {'field' => 'different value'} }
55
- (matcher.matches? block).should be_false
70
+ (matcher.matches? block).should be_falsey
56
71
  end
57
72
  end
58
73
  end
@@ -4,9 +4,6 @@ module RabbitFeed
4
4
  module TestingSupport
5
5
  describe TestingHelpers do
6
6
  describe 'consuming events' do
7
-
8
- include TestingHelpers
9
-
10
7
  accumulator = []
11
8
 
12
9
  let(:define_route) do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'codeclimate-test-reporter'
2
2
  require 'rabbit_feed'
3
+ require 'rspec/its'
3
4
  require 'timecop'
4
5
  require 'timeout'
5
6
 
@@ -21,6 +22,10 @@ Dir.glob('spec/features/step_definitions/**/*_steps.rb') { |f| load f, true }
21
22
 
22
23
  RSpec.configure do |config|
23
24
 
25
+ config.expect_with :rspec do |expects|
26
+ expects.syntax = [:should, :expect]
27
+ end
28
+
24
29
  config.before do
25
30
  reset_environment
26
31
  end
@@ -37,7 +42,7 @@ RSpec.configure do |config|
37
42
  RabbitFeed::Producer.event_definitions = nil
38
43
  end
39
44
 
40
- config.include(RabbitFeed::TestingSupport::RSpecMatchers)
45
+ RabbitFeed::TestingSupport.include_support config
41
46
  end
42
47
 
43
48
  def kill_consumer_thread
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbit_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -16,56 +16,74 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.1.9
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: 1.1.9
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.7.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: 3.2.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 5.0.0
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
47
  - - ">="
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: 3.2.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 5.0.0
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: activemodel
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
57
  - - ">="
46
58
  - !ruby/object:Gem::Version
47
- version: '0'
59
+ version: 3.2.0
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: 5.0.0
48
63
  type: :runtime
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
67
  - - ">="
53
68
  - !ruby/object:Gem::Version
54
- version: '0'
69
+ version: 3.2.0
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: 5.0.0
55
73
  - !ruby/object:Gem::Dependency
56
74
  name: connection_pool
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
59
- - - ">="
77
+ - - "<"
60
78
  - !ruby/object:Gem::Version
61
- version: '0'
79
+ version: 2.2.0
62
80
  type: :runtime
63
81
  prerelease: false
64
82
  version_requirements: !ruby/object:Gem::Requirement
65
83
  requirements:
66
- - - ">="
84
+ - - "<"
67
85
  - !ruby/object:Gem::Version
68
- version: '0'
86
+ version: 2.2.0
69
87
  - !ruby/object:Gem::Dependency
70
88
  name: pidfile
71
89
  requirement: !ruby/object:Gem::Requirement
@@ -86,29 +104,42 @@ dependencies:
86
104
  requirements:
87
105
  - - ">="
88
106
  - !ruby/object:Gem::Version
89
- version: '0'
107
+ version: 1.5.4
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.0
90
111
  type: :runtime
91
112
  prerelease: false
92
113
  version_requirements: !ruby/object:Gem::Requirement
93
114
  requirements:
94
115
  - - ">="
95
116
  - !ruby/object:Gem::Version
96
- version: '0'
117
+ version: 1.5.4
118
+ - - "<"
119
+ - !ruby/object:Gem::Version
120
+ version: 1.8.0
97
121
  - !ruby/object:Gem::Dependency
98
122
  name: rspec
99
123
  requirement: !ruby/object:Gem::Requirement
100
124
  requirements:
101
125
  - - ">="
102
126
  - !ruby/object:Gem::Version
103
- version: '0'
127
+ version: 2.14.0
128
+ - - "<"
129
+ - !ruby/object:Gem::Version
130
+ version: 3.2.0
104
131
  type: :development
105
132
  prerelease: false
106
133
  version_requirements: !ruby/object:Gem::Requirement
107
134
  requirements:
108
135
  - - ">="
109
136
  - !ruby/object:Gem::Version
110
- version: '0'
111
- description: A gem allowing your application to publish messages to RabbitMQ
137
+ version: 2.14.0
138
+ - - "<"
139
+ - !ruby/object:Gem::Version
140
+ version: 3.2.0
141
+ description: A gem providing asynchronous event publish and subscribe capabilities
142
+ with RabbitMQ.
112
143
  email:
113
144
  - tech@simplybusiness.co.uk
114
145
  executables:
@@ -209,6 +240,7 @@ files:
209
240
  - example/rails_app/public/robots.txt
210
241
  - example/rails_app/spec/controllers/beavers_controller_spec.rb
211
242
  - example/rails_app/spec/event_routing_spec.rb
243
+ - example/rails_app/spec/rails_helper.rb
212
244
  - example/rails_app/spec/spec_helper.rb
213
245
  - example/rails_app/test/controllers/.keep
214
246
  - example/rails_app/test/controllers/beavers_controller_test.rb
@@ -236,7 +268,9 @@ files:
236
268
  - lib/rabbit_feed/event_routing.rb
237
269
  - lib/rabbit_feed/producer.rb
238
270
  - lib/rabbit_feed/producer_connection.rb
271
+ - lib/rabbit_feed/testing_support.rb
239
272
  - lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb
273
+ - lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb
240
274
  - lib/rabbit_feed/testing_support/testing_helpers.rb
241
275
  - lib/rabbit_feed/version.rb
242
276
  - logo.png
@@ -283,8 +317,8 @@ rubyforge_project:
283
317
  rubygems_version: 2.0.14
284
318
  signing_key:
285
319
  specification_version: 4
286
- summary: This will enable your application to publish messages to a bus to be processed
287
- by other services
320
+ summary: Enables your Ruby applications to perform centralized event logging with
321
+ RabbitMq
288
322
  test_files:
289
323
  - spec/features/connectivity.feature
290
324
  - spec/features/step_definitions/connectivity_steps.rb