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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b89c207774f809ccb829ba29d9b11299dc2872b0
4
- data.tar.gz: 9ff5943d611beed002969fcad6b62e9d75b4f1c2
3
+ metadata.gz: 64fedeb5c96ffd2d48c0f6f0d09067303cfb9a10
4
+ data.tar.gz: 3da6624dc2bc0e772600af8a8ad5791ebfd0ade3
5
5
  SHA512:
6
- metadata.gz: 2e612b191caae6071e6e5df07e0fc45f081353a68eae365be1ed5548a41d7b23ac82395436ca7e494d3f53d94724e4941041edd9986ed706d48b0e3e26e949ca
7
- data.tar.gz: d76e833bf491449b3b641dd2346aa1f7b76de28acf7e1ff02d3f63416af311ec1d464a7a8f84f8fff3509251b0edc1c4150118b1318256a45e642a71b598c0f5
6
+ metadata.gz: 754014379239da761351fc1d8cba7650cf9bf965f12964b614ef5932780ec179c74f78bab33fe8f7976039a87a1a3d9399b87b06145339cb4f00599adeb7e328
7
+ data.tar.gz: 2d051848279f928e5bd9de87fc1c732a854d93c776dd080069877065b98765d905c22d90ac081b806431199d43c48c5ba79943ce07bd2f5e3b433c54bfaddf57
data/DEVELOPING.md CHANGED
@@ -100,15 +100,15 @@ Results in this output:
100
100
 
101
101
  Transactions: 200 hits
102
102
  Availability: 100.00 %
103
- Elapsed time: 1.33 secs
103
+ Elapsed time: 1.11 secs
104
104
  Data transferred: 0.16 MB
105
- Response time: 0.06 secs
106
- Transaction rate: 150.38 trans/sec
107
- Throughput: 0.12 MB/sec
108
- Concurrency: 8.76
105
+ Response time: 0.05 secs
106
+ Transaction rate: 180.18 trans/sec
107
+ Throughput: 0.14 MB/sec
108
+ Concurrency: 9.37
109
109
  Successful transactions: 100
110
110
  Failed transactions: 0
111
- Longest transaction: 0.36
111
+ Longest transaction: 0.57
112
112
  Shortest transaction: 0.00
113
113
 
114
114
  Stopping rails application...
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ end
10
10
 
11
11
  group :test do
12
12
  gem 'codeclimate-test-reporter'
13
+ gem 'rspec-its'
13
14
  gem 'rutabaga'
14
15
  gem 'timecop'
15
16
  end
data/Gemfile.lock CHANGED
@@ -1,70 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbit_feed (0.3.1)
5
- activemodel
6
- activesupport
7
- avro
8
- bunny
9
- connection_pool
4
+ rabbit_feed (1.0.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
- activemodel (4.1.6)
16
- activesupport (= 4.1.6)
15
+ activemodel (4.2.0)
16
+ activesupport (= 4.2.0)
17
17
  builder (~> 3.1)
18
- activesupport (4.1.6)
19
- i18n (~> 0.6, >= 0.6.9)
18
+ activesupport (4.2.0)
19
+ i18n (~> 0.7)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
22
- thread_safe (~> 0.1)
22
+ thread_safe (~> 0.3, >= 0.3.4)
23
23
  tzinfo (~> 1.1)
24
24
  amq-protocol (1.9.2)
25
25
  avro (1.7.7)
26
26
  multi_json
27
27
  binding_of_caller (0.7.2)
28
28
  debug_inspector (>= 0.0.1)
29
- bond (0.4.3)
29
+ bond (0.5.1)
30
30
  builder (3.2.2)
31
31
  bunny (1.6.3)
32
32
  amq-protocol (>= 1.9.2)
33
- codeclimate-test-reporter (0.2.0)
33
+ codeclimate-test-reporter (0.4.3)
34
34
  simplecov (>= 0.7.1, < 1.0.0)
35
35
  coderay (1.1.0)
36
- columnize (0.3.6)
37
- connection_pool (2.0.0)
36
+ columnize (0.9.0)
37
+ connection_pool (2.1.0)
38
38
  debug_inspector (0.0.2)
39
- debugger (1.6.6)
39
+ debugger (1.6.8)
40
40
  columnize (>= 0.3.1)
41
41
  debugger-linecache (~> 1.2.0)
42
- debugger-ruby_core_source (~> 1.3.2)
42
+ debugger-ruby_core_source (~> 1.3.5)
43
43
  debugger-linecache (1.2.0)
44
- debugger-ruby_core_source (1.3.2)
44
+ debugger-ruby_core_source (1.3.7)
45
45
  diff-lcs (1.2.5)
46
- docile (1.1.2)
46
+ docile (1.1.5)
47
47
  gherkin (2.12.2)
48
48
  multi_json (~> 1.3)
49
- i18n (0.6.11)
50
- interception (0.3)
49
+ i18n (0.7.0)
50
+ interception (0.5)
51
51
  jist (1.5.1)
52
52
  json
53
53
  json (1.8.1)
54
54
  method_source (0.8.2)
55
- minitest (5.4.2)
56
- multi_json (1.9.2)
55
+ minitest (5.5.0)
56
+ multi_json (1.10.1)
57
57
  pidfile (0.3.0)
58
- pry (0.9.12.4)
59
- coderay (~> 1.0)
60
- method_source (~> 0.8)
58
+ pry (0.10.1)
59
+ coderay (~> 1.1.0)
60
+ method_source (~> 0.8.1)
61
61
  slop (~> 3.4)
62
- pry-debugger (0.2.2)
62
+ pry-debugger (0.2.3)
63
63
  debugger (~> 1.3)
64
- pry (~> 0.9.10)
65
- pry-doc (0.4.6)
66
- pry (>= 0.9)
67
- yard (>= 0.8)
64
+ pry (>= 0.9.10, < 0.11.0)
65
+ pry-doc (0.6.0)
66
+ pry (~> 0.9)
67
+ yard (~> 0.8)
68
68
  pry-docmore (0.1.1)
69
69
  pry
70
70
  pry-doc
@@ -76,37 +76,44 @@ GEM
76
76
  pry-docmore
77
77
  pry-rescue
78
78
  pry-stack_explorer
79
- pry-rescue (1.2.0)
80
- interception (>= 0.3)
79
+ pry-rescue (1.4.1)
80
+ interception (>= 0.5)
81
81
  pry
82
82
  pry-stack_explorer (0.4.9.1)
83
83
  binding_of_caller (>= 0.7)
84
84
  pry (>= 0.9.11)
85
- rake (10.2.2)
86
- rspec (2.14.1)
87
- rspec-core (~> 2.14.0)
88
- rspec-expectations (~> 2.14.0)
89
- rspec-mocks (~> 2.14.0)
90
- rspec-core (2.14.8)
91
- rspec-expectations (2.14.5)
92
- diff-lcs (>= 1.1.3, < 2.0)
93
- rspec-mocks (2.14.6)
94
- rutabaga (0.0.4)
95
- turnip (>= 1.1.0)
96
- simplecov (0.8.2)
85
+ rake (10.4.2)
86
+ rspec (3.1.0)
87
+ rspec-core (~> 3.1.0)
88
+ rspec-expectations (~> 3.1.0)
89
+ rspec-mocks (~> 3.1.0)
90
+ rspec-core (3.1.7)
91
+ rspec-support (~> 3.1.0)
92
+ rspec-expectations (3.1.2)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.1.0)
95
+ rspec-its (1.1.0)
96
+ rspec-core (>= 3.0.0)
97
+ rspec-expectations (>= 3.0.0)
98
+ rspec-mocks (3.1.3)
99
+ rspec-support (~> 3.1.0)
100
+ rspec-support (3.1.2)
101
+ rutabaga (0.1.1)
102
+ turnip (>= 1.1.0, < 2.0)
103
+ simplecov (0.9.1)
97
104
  docile (~> 1.1.0)
98
- multi_json
105
+ multi_json (~> 1.0)
99
106
  simplecov-html (~> 0.8.0)
100
107
  simplecov-html (0.8.0)
101
- slop (3.4.7)
108
+ slop (3.6.0)
102
109
  thread_safe (0.3.4)
103
- timecop (0.4.4)
104
- turnip (1.2.1)
110
+ timecop (0.7.1)
111
+ turnip (1.2.4)
105
112
  gherkin (>= 2.5)
106
- rspec (>= 2.0, < 4.0)
113
+ rspec (>= 2.14.0, < 4.0)
107
114
  tzinfo (1.2.2)
108
115
  thread_safe (~> 0.1)
109
- yard (0.8.7.3)
116
+ yard (0.8.7.6)
110
117
 
111
118
  PLATFORMS
112
119
  ruby
@@ -116,6 +123,7 @@ DEPENDENCIES
116
123
  pry-plus
117
124
  rabbit_feed!
118
125
  rake
119
- rspec
126
+ rspec (>= 2.14.0, < 3.2.0)
127
+ rspec-its
120
128
  rutabaga
121
129
  timecop
data/README.md CHANGED
@@ -41,11 +41,6 @@ Sample:
41
41
  If installing in a rails application, the following should be defined in `config/initializers/rabbit_feed.rb`:
42
42
 
43
43
  ```ruby
44
- RabbitFeed.instance_eval do
45
- self.log = Logger.new (Rails.root.join 'log', 'rabbit_feed.log')
46
- self.environment = Rails.env
47
- self.configuration_file_path = Rails.root.join 'config', 'rabbit_feed.yml'
48
- end
49
44
  # Define the events (if producing)
50
45
  EventDefinitions do
51
46
  define_event('user_creates_beaver', version: '1.0.0') do
@@ -67,6 +62,16 @@ EventRouting do
67
62
  end
68
63
  ```
69
64
 
65
+ You may also override the log location (defaults to `STDOUT`), the environment (defaults to the `RAILS_ENV`), and the path to the RabbitFeed config file (defaults to `config/rabbit_feed.yml`) in the initializer, like this:
66
+
67
+ ```ruby
68
+ RabbitFeed.instance_eval do
69
+ self.log = Logger.new (Rails.root.join 'log', 'rabbit_feed.log')
70
+ self.environment = Rails.env
71
+ self.configuration_file_path = Rails.root.join 'config', 'rabbit_feed.yml'
72
+ end
73
+ ```
74
+
70
75
  ## Producing events
71
76
 
72
77
  The producer defines the events and their payloads using the [Event Definitions DSL](https://github.com/simplybusiness/rabbit_feed#event-definitions-dsl). In a rails app, this can be defined in the [initialiser](https://github.com/simplybusiness/rabbit_feed#initialisation).
@@ -90,11 +95,11 @@ In the case that there are no consumers configured to subscribe to an event, the
90
95
 
91
96
  ### Testing the Producer
92
97
 
93
- To prevent RabbitFeed from firing events during tests, add the following to `spec_helper.rb`:
98
+ To prevent RabbitFeed from publishing events to RabbitMQ during tests, add the following to `spec_helper.rb`:
94
99
 
95
100
  ```ruby
96
- config.before :each do
97
- RabbitFeed::Producer.stub!
101
+ RSpec.configure do |config|
102
+ RabbitFeed::TestingSupport.capture_published_events(config)
98
103
  end
99
104
  ```
100
105
 
@@ -102,11 +107,11 @@ end
102
107
 
103
108
  To verify that your application publishes an event, use the custom RSpec matcher provided with this application.
104
109
 
105
- Add the following RSpec configuration to `spec_helper.rb`:
110
+ To make the custom RSpec matcher available to your tests, add the following to `spec_helper.rb`:
106
111
 
107
112
  ```ruby
108
113
  RSpec.configure do |config|
109
- config.include(RabbitFeed::TestingSupport::RSpecMatchers)
114
+ RabbitFeed::TestingSupport.setup(config)
110
115
  end
111
116
  ```
112
117
 
@@ -153,13 +158,10 @@ In the case that your consumer raises an error whilst processing an event, the e
153
158
 
154
159
  ### Testing the Consumer
155
160
 
156
- If you want to test that your routes are behaving as expected without actually using RabbitMQ, you can include the module `TestHelpers` in your tests and then invoke `rabbit_feed_consumer.consume_event(event)`. Following is an example:
161
+ If you want to test that your routes are behaving as expected without actually using RabbitMQ, you can invoke `rabbit_feed_consumer.consume_event(event)`. The following is an example:
157
162
 
158
163
  ```ruby
159
164
  describe 'consuming events' do
160
-
161
- include RabbitFeed::TestingSupport::TestingHelpers
162
-
163
165
  accumulator = []
164
166
 
165
167
  let(:define_route) do
@@ -183,6 +185,14 @@ describe 'consuming events' do
183
185
  end
184
186
  ```
185
187
 
188
+ To make the `rabbit_feed_consumer` method available to your tests, add the following to `spec_helper.rb`:
189
+
190
+ ```ruby
191
+ RSpec.configure do |config|
192
+ RabbitFeed::TestingSupport.setup(config)
193
+ end
194
+ ```
195
+
186
196
  ## Command Line Tools
187
197
 
188
198
  ### Event Publish
@@ -215,6 +225,12 @@ Starts a consumer. Note: until you've specified the [event routing](https://gith
215
225
  --daemon Run the consumer as a daemon
216
226
  --help Print the available options
217
227
 
228
+ ### Stopping the consumer
229
+
230
+ bundle exec bin/rabbit_feed shutdown
231
+
232
+ _This only applies if you've started the consumer with the `--daemon` option._
233
+
218
234
  ## Event Definitions DSL
219
235
 
220
236
  Provides a means to define all events that are published by an application. Defines the event names and the payload associated with each event. The DSL is converted into a schema that is serialized along with the event payload, meaning the events are self-describing. This is accomplished using Apache [Avro](http://avro.apache.org/docs/current/). This also validates the event payload against its schema before it is published.
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (0.3.1)
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
- activemodel (4.1.6)
16
- activesupport (= 4.1.6)
15
+ activemodel (4.2.0)
16
+ activesupport (= 4.2.0)
17
17
  builder (~> 3.1)
18
- activesupport (4.1.6)
19
- i18n (~> 0.6, >= 0.6.9)
18
+ activesupport (4.2.0)
19
+ i18n (~> 0.7)
20
20
  json (~> 1.7, >= 1.7.7)
21
21
  minitest (~> 5.1)
22
- thread_safe (~> 0.1)
22
+ thread_safe (~> 0.3, >= 0.3.4)
23
23
  tzinfo (~> 1.1)
24
24
  amq-protocol (1.9.2)
25
25
  avro (1.7.7)
@@ -27,22 +27,26 @@ GEM
27
27
  builder (3.2.2)
28
28
  bunny (1.6.3)
29
29
  amq-protocol (>= 1.9.2)
30
- connection_pool (2.0.0)
30
+ connection_pool (2.1.0)
31
31
  diff-lcs (1.2.5)
32
- i18n (0.6.11)
32
+ i18n (0.7.0)
33
33
  json (1.8.1)
34
- minitest (5.4.2)
34
+ minitest (5.5.0)
35
35
  multi_json (1.10.1)
36
36
  pidfile (0.3.0)
37
- rake (10.3.1)
38
- rspec (2.14.1)
39
- rspec-core (~> 2.14.0)
40
- rspec-expectations (~> 2.14.0)
41
- rspec-mocks (~> 2.14.0)
42
- rspec-core (2.14.8)
43
- rspec-expectations (2.14.5)
44
- diff-lcs (>= 1.1.3, < 2.0)
45
- rspec-mocks (2.14.6)
37
+ rake (10.4.2)
38
+ rspec (3.1.0)
39
+ rspec-core (~> 3.1.0)
40
+ rspec-expectations (~> 3.1.0)
41
+ rspec-mocks (~> 3.1.0)
42
+ rspec-core (3.1.7)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-expectations (3.1.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.1.0)
47
+ rspec-mocks (3.1.3)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-support (3.1.2)
46
50
  thread_safe (0.3.4)
47
51
  tzinfo (1.2.2)
48
52
  thread_safe (~> 0.1)
@@ -2,16 +2,14 @@
2
2
 
3
3
  require 'benchmark'
4
4
  require 'bundler/setup'
5
- require_relative '../lib/non_rails_app'
5
+ require 'rabbit_feed'
6
6
 
7
7
  # Prevent deprecation warnings
8
8
  I18n.enforce_available_locales = true
9
9
 
10
10
  RabbitFeed.instance_eval do
11
- self.log = Logger.new 'log/rabbit_feed.log'
12
- self.log.level = Logger::DEBUG
13
- self.environment = 'development'
14
- self.configuration_file_path = 'config/rabbit_feed.yml'
11
+ self.log = Logger.new 'log/rabbit_feed.log'
12
+ self.environment = 'development'
15
13
  end
16
14
 
17
15
  payload = 'abc'*5000
@@ -2,12 +2,10 @@ require_relative '../../spec_helper'
2
2
 
3
3
  module NonRailsApp
4
4
  describe 'Event Routing' do
5
-
6
- include RabbitFeed::TestingSupport::TestingHelpers
7
-
8
5
  let(:event) { {'application' => 'rails_app', 'name' => 'user_creates_beaver'} }
6
+
9
7
  it 'routes events correctly' do
10
- expect(NonRailsApp::EventHandler).to receive(:handle_event).with { |full_event| expect(full_event.payload).to eq(event)}
8
+ expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(event)}
11
9
  rabbit_feed_consumer.consume_event(event)
12
10
  end
13
11
  end
@@ -13,19 +13,11 @@ RSpec.configure do |config|
13
13
  # order dependency and want to debug it, you can fix the order by providing
14
14
  # the seed, which is printed after each run.
15
15
  # --seed 1234
16
- config.order = "random"
16
+ config.order = 'random'
17
17
 
18
- config.mock_with :rspec do |c|
19
- c.syntax = [:should, :expect]
20
- end
21
-
22
- config.before :each do
23
- RabbitFeed::Producer.stub!
24
- end
25
-
26
- config.include(RabbitFeed::TestingSupport::RSpecMatchers)
18
+ RabbitFeed::TestingSupport.setup(config)
27
19
  end
28
20
 
29
- RabbitFeed.log = Logger.new('test.log')
21
+ RabbitFeed.log = Logger.new('log/rabbit_feed.log')
30
22
  RabbitFeed.environment = 'test'
31
23
  RabbitFeed.configuration_file_path = 'config/rabbit_feed.yml'
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
- gem 'rails', '4.1.0'
4
+ gem 'rails', '4.2.0'
5
5
  # Use sqlite3 as the database for Active Record
6
6
  gem 'sqlite3'
7
7
  # Use SCSS for stylesheets