rabbit_feed 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/DEVELOPING.md +14 -2
- data/Gemfile.lock +27 -26
- data/README.md +17 -11
- data/example/non_rails_app/Gemfile.lock +18 -17
- data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +1 -1
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +4 -2
- data/example/rails_app/Gemfile.lock +34 -33
- data/example/rails_app/spec/event_routing_spec.rb +3 -3
- data/lib/rabbit_feed/configuration.rb +25 -11
- data/lib/rabbit_feed/connection_concern.rb +4 -13
- data/lib/rabbit_feed/consumer_connection.rb +0 -6
- data/lib/rabbit_feed/event.rb +58 -18
- data/lib/rabbit_feed/event_definitions.rb +18 -6
- data/lib/rabbit_feed/producer.rb +12 -11
- data/lib/rabbit_feed/producer_connection.rb +1 -1
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +2 -8
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +3 -3
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +1 -0
- data/rabbit_feed.gemspec +2 -2
- data/spec/features/step_definitions/connectivity_steps.rb +1 -1
- data/spec/fixtures/configuration.yml +0 -1
- data/spec/lib/rabbit_feed/configuration_spec.rb +59 -12
- data/spec/lib/rabbit_feed/connection_concern_spec.rb +11 -0
- data/spec/lib/rabbit_feed/event_definitions_spec.rb +25 -11
- data/spec/lib/rabbit_feed/event_routing_spec.rb +7 -7
- data/spec/lib/rabbit_feed/event_spec.rb +119 -11
- data/spec/lib/rabbit_feed/producer_spec.rb +14 -0
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +6 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ada150cba6130fe7df806147c44d20e72027c95
|
4
|
+
data.tar.gz: 4ca751e89bf9e476fb622e6db31660b59faeca53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 807446c806430a173ef49307e3a4ca7a1afc22f9bc041e724ec17f208dbd638fb38f0fb85b83d853e3f75fb5f1dd2126ced965f795b9fb849c06f39ffe774ebc
|
7
|
+
data.tar.gz: cd35aefc408cebbe6e7094335d9d113c7fabbedb11420878a78782748ba6ab01f7c17649c15ef975571ef7964221959478a4c4a607d1eade1310a2f9fe6f761b
|
data/.rspec
CHANGED
data/DEVELOPING.md
CHANGED
@@ -57,9 +57,9 @@ You should see something similar to the following output:
|
|
57
57
|
Starting rails application...
|
58
58
|
Rails application started
|
59
59
|
Triggering event...
|
60
|
-
NonRailsApp::EventHandler - Consumed event: user_creates_beaver with payload: {"
|
60
|
+
NonRailsApp::EventHandler - Consumed event: user_creates_beaver with payload: {"beaver_name"=>"02/16/15 12:31:41"}
|
61
61
|
Event triggered
|
62
|
-
RailsApp::EventHandler - Consumed event: application_acknowledges_event with payload: {"
|
62
|
+
RailsApp::EventHandler - Consumed event: application_acknowledges_event with payload: {"beaver_name"=>"02/16/15 12:31:41", "event_name"=>"user_creates_beaver"}
|
63
63
|
Stopping non rails application consumer...
|
64
64
|
Non rails application consumer stopped
|
65
65
|
Stopping rails application consumer...
|
@@ -138,3 +138,15 @@ To simulate network connectivity problems, there is a recovery test script that
|
|
138
138
|
./run_recovery_test
|
139
139
|
|
140
140
|
The script will publish and then consume 5000 mesages with the network dropping out every half-second.
|
141
|
+
|
142
|
+
## Changing the event schema
|
143
|
+
|
144
|
+
Events are serialized when published and deserialized when consumed. In the case that the schema of the serialized event needs to change, backwards compatibility with the previous schema should be maintained for the susequent major version of the gem. To aid with this, the event schema is versioned. To modify the event structure, perform the following steps:
|
145
|
+
|
146
|
+
1. Define the new Avro schema in [`event_definitions.rb`](https://github.com/simplybusiness/rabbit_feed/blob/master/lib/rabbit_feed/event_definitions.rb)
|
147
|
+
1. Modify the serialization in [`event.rb`](https://github.com/simplybusiness/rabbit_feed/blob/master/lib/rabbit_feed/event.rb) to match the new schema
|
148
|
+
1. Modify the deserialization in [`event.rb`](https://github.com/simplybusiness/rabbit_feed/blob/master/lib/rabbit_feed/event.rb) to
|
149
|
+
1. match the new schema
|
150
|
+
1. maintain backwards compatibility to the previous schema if necessary
|
151
|
+
1. Increment the `SCHEMA_VERSION` variable in [`event.rb`](https://github.com/simplybusiness/rabbit_feed/blob/master/lib/rabbit_feed/event.rb) per [semantic versioning principles](http://semver.org/)
|
152
|
+
1. Remove backwards compatibility after the next major version release
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rabbit_feed (
|
4
|
+
rabbit_feed (2.0.0)
|
5
5
|
activemodel (>= 3.2.0, < 5.0.0)
|
6
6
|
activesupport (>= 3.2.0, < 5.0.0)
|
7
7
|
avro (>= 1.5.4, < 1.8.0)
|
8
|
-
bunny (>= 1.1.9, < 1.
|
8
|
+
bunny (>= 1.1.9, < 1.8.0)
|
9
9
|
connection_pool (< 2.2.0)
|
10
10
|
pidfile
|
11
11
|
|
@@ -28,20 +28,20 @@ GEM
|
|
28
28
|
debug_inspector (>= 0.0.1)
|
29
29
|
bond (0.5.1)
|
30
30
|
builder (3.2.2)
|
31
|
-
bunny (1.
|
31
|
+
bunny (1.7.0)
|
32
32
|
amq-protocol (>= 1.9.2)
|
33
|
-
codeclimate-test-reporter (0.4.
|
33
|
+
codeclimate-test-reporter (0.4.6)
|
34
34
|
simplecov (>= 0.7.1, < 1.0.0)
|
35
35
|
coderay (1.1.0)
|
36
36
|
columnize (0.9.0)
|
37
|
-
connection_pool (2.1.
|
37
|
+
connection_pool (2.1.1)
|
38
38
|
debug_inspector (0.0.2)
|
39
39
|
debugger (1.6.8)
|
40
40
|
columnize (>= 0.3.1)
|
41
41
|
debugger-linecache (~> 1.2.0)
|
42
42
|
debugger-ruby_core_source (~> 1.3.5)
|
43
43
|
debugger-linecache (1.2.0)
|
44
|
-
debugger-ruby_core_source (1.3.
|
44
|
+
debugger-ruby_core_source (1.3.8)
|
45
45
|
diff-lcs (1.2.5)
|
46
46
|
docile (1.1.5)
|
47
47
|
gherkin (2.12.2)
|
@@ -50,9 +50,9 @@ GEM
|
|
50
50
|
interception (0.5)
|
51
51
|
jist (1.5.1)
|
52
52
|
json
|
53
|
-
json (1.8.
|
53
|
+
json (1.8.2)
|
54
54
|
method_source (0.8.2)
|
55
|
-
minitest (5.5.
|
55
|
+
minitest (5.5.1)
|
56
56
|
multi_json (1.10.1)
|
57
57
|
pidfile (0.3.0)
|
58
58
|
pry (0.10.1)
|
@@ -79,35 +79,36 @@ GEM
|
|
79
79
|
pry-rescue (1.4.1)
|
80
80
|
interception (>= 0.5)
|
81
81
|
pry
|
82
|
-
pry-stack_explorer (0.4.9.
|
82
|
+
pry-stack_explorer (0.4.9.2)
|
83
83
|
binding_of_caller (>= 0.7)
|
84
84
|
pry (>= 0.9.11)
|
85
85
|
rake (10.4.2)
|
86
|
-
rspec (3.
|
87
|
-
rspec-core (~> 3.
|
88
|
-
rspec-expectations (~> 3.
|
89
|
-
rspec-mocks (~> 3.
|
90
|
-
rspec-core (3.
|
91
|
-
rspec-support (~> 3.
|
92
|
-
rspec-expectations (3.
|
86
|
+
rspec (3.2.0)
|
87
|
+
rspec-core (~> 3.2.0)
|
88
|
+
rspec-expectations (~> 3.2.0)
|
89
|
+
rspec-mocks (~> 3.2.0)
|
90
|
+
rspec-core (3.2.0)
|
91
|
+
rspec-support (~> 3.2.0)
|
92
|
+
rspec-expectations (3.2.0)
|
93
93
|
diff-lcs (>= 1.2.0, < 2.0)
|
94
|
-
rspec-support (~> 3.
|
95
|
-
rspec-its (1.
|
94
|
+
rspec-support (~> 3.2.0)
|
95
|
+
rspec-its (1.2.0)
|
96
96
|
rspec-core (>= 3.0.0)
|
97
97
|
rspec-expectations (>= 3.0.0)
|
98
|
-
rspec-mocks (3.
|
99
|
-
|
100
|
-
|
98
|
+
rspec-mocks (3.2.0)
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
+
rspec-support (~> 3.2.0)
|
101
|
+
rspec-support (3.2.1)
|
101
102
|
rutabaga (0.1.1)
|
102
103
|
turnip (>= 1.1.0, < 2.0)
|
103
|
-
simplecov (0.9.
|
104
|
+
simplecov (0.9.2)
|
104
105
|
docile (~> 1.1.0)
|
105
106
|
multi_json (~> 1.0)
|
106
|
-
simplecov-html (~> 0.
|
107
|
-
simplecov-html (0.
|
107
|
+
simplecov-html (~> 0.9.0)
|
108
|
+
simplecov-html (0.9.0)
|
108
109
|
slop (3.6.0)
|
109
110
|
thread_safe (0.3.4)
|
110
|
-
timecop (0.7.
|
111
|
+
timecop (0.7.3)
|
111
112
|
turnip (1.2.4)
|
112
113
|
gherkin (>= 2.5)
|
113
114
|
rspec (>= 2.14.0, < 4.0)
|
@@ -123,7 +124,7 @@ DEPENDENCIES
|
|
123
124
|
pry-plus
|
124
125
|
rabbit_feed!
|
125
126
|
rake
|
126
|
-
rspec (>= 2.14.0, < 3.
|
127
|
+
rspec (>= 2.14.0, < 3.3.0)
|
127
128
|
rspec-its
|
128
129
|
rutabaga
|
129
130
|
timecop
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ RabbitFeed::Producer.publish_event 'Event name', { 'payload_field' => 'payload f
|
|
87
87
|
|
88
88
|
**Event payload:** This is the data about the event. This should be a hash.
|
89
89
|
|
90
|
-
The event will be published to the configured exchange on RabbitMQ (`amq.topic` by default) with a routing key having the pattern of:
|
90
|
+
The event will be published to the configured exchange on RabbitMQ (`amq.topic` by default) with a routing key having the pattern of: `[environment].[producer application name].[event name]`.
|
91
91
|
|
92
92
|
### Returned Events
|
93
93
|
|
@@ -138,13 +138,15 @@ The consumer defines to which events it will subscribe as well as how it handles
|
|
138
138
|
|
139
139
|
An `Event` contains the following information:
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
141
|
+
- `metadata` Information about the event, including:
|
142
|
+
- `environment` The environment in which the event was created (e.g. development, test, production)
|
143
|
+
- `application` The name of the application that generated the event (as specified in rabbit_feed.yml)
|
144
|
+
- `version` The version of the event payload (as specified in the event definition)
|
145
|
+
- `name` The name of the event
|
146
|
+
- `host` The hostname of the server on which the event was generated
|
147
|
+
- `created_at_utc` The time (in UTC) that the event was created
|
148
|
+
- `schema_version` The version of the event schema
|
149
|
+
- `payload` The payload of the event
|
148
150
|
|
149
151
|
### Running the consumer
|
150
152
|
|
@@ -166,15 +168,15 @@ describe 'consuming events' do
|
|
166
168
|
|
167
169
|
let(:define_route) do
|
168
170
|
EventRouting do
|
169
|
-
accept_from('
|
170
|
-
event('
|
171
|
+
accept_from('application_name') do
|
172
|
+
event('event_name') do |event|
|
171
173
|
accumulator << event
|
172
174
|
end
|
173
175
|
end
|
174
176
|
end
|
175
177
|
end
|
176
178
|
|
177
|
-
let(:event) { {'application' => '
|
179
|
+
let(:event) { RabbitFeed::Event.new({'application' => 'application_name', 'name' => 'event_name'}, {'stuff' => 'some_stuff'}) }
|
178
180
|
|
179
181
|
before { define_route }
|
180
182
|
|
@@ -315,6 +317,10 @@ RabbitFeed provides 'at least once' delivery semantics. There are two use-cases
|
|
315
317
|
|
316
318
|
It is advisable to run RabbitFeed in a [clustered](https://www.rabbitmq.com/clustering.html) RabbitMQ environment to prevent the loss of messages in the case that a RabbitMQ node is lost. By default, RabbitFeed will declare queues to be mirrored across all nodes of the cluster.
|
317
319
|
|
320
|
+
## Thread Safety
|
321
|
+
|
322
|
+
RabbitFeed event publishing is thread-safe. This is achieved by only allowing one thread to publish an event at any given time.
|
323
|
+
|
318
324
|
## Developing
|
319
325
|
|
320
326
|
_See [./DEVELOPING.md](./DEVELOPING.md) for instructions on how to develop RabbitFeed_
|
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
rabbit_feed (
|
4
|
+
rabbit_feed (2.0.0)
|
5
5
|
activemodel (>= 3.2.0, < 5.0.0)
|
6
6
|
activesupport (>= 3.2.0, < 5.0.0)
|
7
7
|
avro (>= 1.5.4, < 1.8.0)
|
8
|
-
bunny (>= 1.1.9, < 1.
|
8
|
+
bunny (>= 1.1.9, < 1.8.0)
|
9
9
|
connection_pool (< 2.2.0)
|
10
10
|
pidfile
|
11
11
|
|
@@ -25,28 +25,29 @@ GEM
|
|
25
25
|
avro (1.7.7)
|
26
26
|
multi_json
|
27
27
|
builder (3.2.2)
|
28
|
-
bunny (1.
|
28
|
+
bunny (1.7.0)
|
29
29
|
amq-protocol (>= 1.9.2)
|
30
|
-
connection_pool (2.1.
|
30
|
+
connection_pool (2.1.1)
|
31
31
|
diff-lcs (1.2.5)
|
32
32
|
i18n (0.7.0)
|
33
|
-
json (1.8.
|
34
|
-
minitest (5.5.
|
33
|
+
json (1.8.2)
|
34
|
+
minitest (5.5.1)
|
35
35
|
multi_json (1.10.1)
|
36
36
|
pidfile (0.3.0)
|
37
37
|
rake (10.4.2)
|
38
|
-
rspec (3.
|
39
|
-
rspec-core (~> 3.
|
40
|
-
rspec-expectations (~> 3.
|
41
|
-
rspec-mocks (~> 3.
|
42
|
-
rspec-core (3.
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-expectations (3.
|
38
|
+
rspec (3.2.0)
|
39
|
+
rspec-core (~> 3.2.0)
|
40
|
+
rspec-expectations (~> 3.2.0)
|
41
|
+
rspec-mocks (~> 3.2.0)
|
42
|
+
rspec-core (3.2.0)
|
43
|
+
rspec-support (~> 3.2.0)
|
44
|
+
rspec-expectations (3.2.0)
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
48
|
-
|
49
|
-
|
46
|
+
rspec-support (~> 3.2.0)
|
47
|
+
rspec-mocks (3.2.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.2.0)
|
50
|
+
rspec-support (3.2.1)
|
50
51
|
thread_safe (0.3.4)
|
51
52
|
tzinfo (1.2.2)
|
52
53
|
thread_safe (~> 0.1)
|
@@ -6,7 +6,7 @@ module NonRailsApp
|
|
6
6
|
describe '#handle_event' do
|
7
7
|
it 'publishes an update event' do
|
8
8
|
expect{
|
9
|
-
described_class.handle_event
|
9
|
+
described_class.handle_event RabbitFeed::Event.new({'name' => 'user_updates_beaver', 'application' => 'rails_app'}, {'beaver_name' => 'beaver'})
|
10
10
|
}.to publish_event('application_acknowledges_event', { 'beaver_name' => 'beaver', 'event_name' => 'user_updates_beaver' })
|
11
11
|
end
|
12
12
|
end
|
@@ -2,10 +2,12 @@ require_relative '../../spec_helper'
|
|
2
2
|
|
3
3
|
module NonRailsApp
|
4
4
|
describe 'Event Routing' do
|
5
|
-
let(:
|
5
|
+
let(:payload) { {'field' => 'value'} }
|
6
|
+
let(:metadata) { {'application' => 'rails_app', 'name' => 'user_creates_beaver'} }
|
7
|
+
let(:event) { RabbitFeed::Event.new metadata, payload }
|
6
8
|
|
7
9
|
it 'routes events correctly' do
|
8
|
-
expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(
|
10
|
+
expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(payload)}
|
9
11
|
rabbit_feed_consumer.consume_event(event)
|
10
12
|
end
|
11
13
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
rabbit_feed (
|
4
|
+
rabbit_feed (2.0.0)
|
5
5
|
activemodel (>= 3.2.0, < 5.0.0)
|
6
6
|
activesupport (>= 3.2.0, < 5.0.0)
|
7
7
|
avro (>= 1.5.4, < 1.8.0)
|
8
|
-
bunny (>= 1.1.9, < 1.
|
8
|
+
bunny (>= 1.1.9, < 1.8.0)
|
9
9
|
connection_pool (< 2.2.0)
|
10
10
|
pidfile
|
11
11
|
|
@@ -52,7 +52,7 @@ GEM
|
|
52
52
|
avro (1.7.7)
|
53
53
|
multi_json
|
54
54
|
builder (3.2.2)
|
55
|
-
bunny (1.
|
55
|
+
bunny (1.7.0)
|
56
56
|
amq-protocol (>= 1.9.2)
|
57
57
|
coffee-rails (4.0.1)
|
58
58
|
coffee-script (>= 2.2.0)
|
@@ -60,37 +60,37 @@ GEM
|
|
60
60
|
coffee-script (2.3.0)
|
61
61
|
coffee-script-source
|
62
62
|
execjs
|
63
|
-
coffee-script-source (1.
|
64
|
-
connection_pool (2.1.
|
63
|
+
coffee-script-source (1.9.1)
|
64
|
+
connection_pool (2.1.1)
|
65
65
|
diff-lcs (1.2.5)
|
66
66
|
erubis (2.7.0)
|
67
|
-
execjs (2.
|
68
|
-
globalid (0.3.
|
67
|
+
execjs (2.3.0)
|
68
|
+
globalid (0.3.3)
|
69
69
|
activesupport (>= 4.1.0)
|
70
70
|
hike (1.2.3)
|
71
71
|
i18n (0.7.0)
|
72
|
-
jbuilder (2.2.
|
72
|
+
jbuilder (2.2.8)
|
73
73
|
activesupport (>= 3.0.0, < 5)
|
74
74
|
multi_json (~> 1.2)
|
75
|
-
jquery-rails (4.0.
|
75
|
+
jquery-rails (4.0.3)
|
76
76
|
rails-dom-testing (~> 1.0)
|
77
77
|
railties (>= 4.2.0)
|
78
78
|
thor (>= 0.14, < 2.0)
|
79
|
-
json (1.8.
|
80
|
-
kgio (2.9.
|
79
|
+
json (1.8.2)
|
80
|
+
kgio (2.9.3)
|
81
81
|
loofah (2.0.1)
|
82
82
|
nokogiri (>= 1.5.9)
|
83
83
|
mail (2.6.3)
|
84
84
|
mime-types (>= 1.16, < 3)
|
85
85
|
mime-types (2.4.3)
|
86
|
-
mini_portile (0.6.
|
87
|
-
minitest (5.5.
|
86
|
+
mini_portile (0.6.2)
|
87
|
+
minitest (5.5.1)
|
88
88
|
multi_json (1.10.1)
|
89
|
-
nokogiri (1.6.
|
89
|
+
nokogiri (1.6.6.2)
|
90
90
|
mini_portile (~> 0.6.0)
|
91
91
|
pidfile (0.3.0)
|
92
92
|
rack (1.6.0)
|
93
|
-
rack-test (0.6.
|
93
|
+
rack-test (0.6.3)
|
94
94
|
rack (>= 1.0)
|
95
95
|
rails (4.2.0)
|
96
96
|
actionmailer (= 4.2.0)
|
@@ -120,22 +120,23 @@ GEM
|
|
120
120
|
rake (10.4.2)
|
121
121
|
rdoc (4.2.0)
|
122
122
|
json (~> 1.4)
|
123
|
-
rspec-core (3.
|
124
|
-
rspec-support (~> 3.
|
125
|
-
rspec-expectations (3.
|
123
|
+
rspec-core (3.2.0)
|
124
|
+
rspec-support (~> 3.2.0)
|
125
|
+
rspec-expectations (3.2.0)
|
126
126
|
diff-lcs (>= 1.2.0, < 2.0)
|
127
|
-
rspec-support (~> 3.
|
128
|
-
rspec-mocks (3.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
rspec-
|
136
|
-
rspec-
|
137
|
-
rspec-
|
138
|
-
|
127
|
+
rspec-support (~> 3.2.0)
|
128
|
+
rspec-mocks (3.2.0)
|
129
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
130
|
+
rspec-support (~> 3.2.0)
|
131
|
+
rspec-rails (3.2.0)
|
132
|
+
actionpack (>= 3.0, <= 4.2)
|
133
|
+
activesupport (>= 3.0, <= 4.2)
|
134
|
+
railties (>= 3.0, <= 4.2)
|
135
|
+
rspec-core (~> 3.2.0)
|
136
|
+
rspec-expectations (~> 3.2.0)
|
137
|
+
rspec-mocks (~> 3.2.0)
|
138
|
+
rspec-support (~> 3.2.0)
|
139
|
+
rspec-support (3.2.1)
|
139
140
|
sass (3.2.19)
|
140
141
|
sass-rails (4.0.5)
|
141
142
|
railties (>= 4.0.0, < 5.0)
|
@@ -145,13 +146,13 @@ GEM
|
|
145
146
|
sdoc (0.4.1)
|
146
147
|
json (~> 1.7, >= 1.7.7)
|
147
148
|
rdoc (~> 4.0)
|
148
|
-
spring (1.2
|
149
|
+
spring (1.3.2)
|
149
150
|
sprockets (2.12.3)
|
150
151
|
hike (~> 1.2)
|
151
152
|
multi_json (~> 1.0)
|
152
153
|
rack (~> 1.0)
|
153
154
|
tilt (~> 1.1, != 1.3.0)
|
154
|
-
sprockets-rails (2.2.
|
155
|
+
sprockets-rails (2.2.4)
|
155
156
|
actionpack (>= 3.0)
|
156
157
|
activesupport (>= 3.0)
|
157
158
|
sprockets (>= 2.8, < 4.0)
|
@@ -163,7 +164,7 @@ GEM
|
|
163
164
|
coffee-rails
|
164
165
|
tzinfo (1.2.2)
|
165
166
|
thread_safe (~> 0.1)
|
166
|
-
uglifier (2.
|
167
|
+
uglifier (2.7.0)
|
167
168
|
execjs (>= 0.3.0)
|
168
169
|
json (>= 1.8.0)
|
169
170
|
unicorn (4.8.3)
|
@@ -2,11 +2,11 @@ require_relative 'rails_helper'
|
|
2
2
|
|
3
3
|
module RailsApp
|
4
4
|
describe 'Event Routing' do
|
5
|
-
let(:event) { {'application' => 'non_rails_app', 'name' => 'application_acknowledges_event'} }
|
6
5
|
|
7
6
|
it 'routes events correctly' do
|
8
|
-
expect
|
9
|
-
|
7
|
+
expect do
|
8
|
+
rabbit_feed_consumer.consume_event(RabbitFeed::Event.new({'application' => 'non_rails_app', 'name' => 'application_acknowledges_event'}))
|
9
|
+
end.to output("RailsApp::EventHandler - Consumed event: application_acknowledges_event with payload: {}\n").to_stdout
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -3,21 +3,20 @@ module RabbitFeed
|
|
3
3
|
include ActiveModel::Validations
|
4
4
|
|
5
5
|
attr_reader :host, :port, :user, :password, :application, :environment, :exchange, :pool_size, :pool_timeout, :heartbeat, :connect_timeout, :network_recovery_interval, :auto_delete_queue, :auto_delete_exchange
|
6
|
-
validates_presence_of :
|
6
|
+
validates_presence_of :application, :environment, :exchange, :pool_timeout
|
7
7
|
|
8
8
|
def initialize options
|
9
9
|
RabbitFeed.log.debug "RabbitFeed initialising with options: #{options}..."
|
10
10
|
|
11
|
-
@host = options[:host]
|
12
|
-
@port = options[:port]
|
13
|
-
@user = options[:user]
|
14
|
-
@password = options[:password]
|
15
|
-
@exchange = options[:exchange]
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@network_recovery_interval = options[:network_recovery_interval] || 1
|
11
|
+
@host = options[:host]
|
12
|
+
@port = options[:port]
|
13
|
+
@user = options[:user]
|
14
|
+
@password = options[:password]
|
15
|
+
@exchange = options[:exchange] || 'amq.topic'
|
16
|
+
@pool_timeout = options[:pool_timeout] || 120
|
17
|
+
@heartbeat = options[:heartbeat]
|
18
|
+
@connect_timeout = options[:connect_timeout]
|
19
|
+
@network_recovery_interval = options[:network_recovery_interval]
|
21
20
|
@auto_delete_queue = !!(options[:auto_delete_queue] || false)
|
22
21
|
@auto_delete_exchange = !!(options[:auto_delete_exchange] || false)
|
23
22
|
@application = options[:application]
|
@@ -38,6 +37,21 @@ module RabbitFeed
|
|
38
37
|
"#{environment}.#{application}"
|
39
38
|
end
|
40
39
|
|
40
|
+
def connection_options
|
41
|
+
Hash.new.tap do |options|
|
42
|
+
options[:heartbeat] = heartbeat if heartbeat
|
43
|
+
options[:connect_timeout] = connect_timeout if connect_timeout
|
44
|
+
options[:host] = host if host
|
45
|
+
options[:user] = user if user
|
46
|
+
options[:password] = password if password
|
47
|
+
options[:port] = port if port
|
48
|
+
options[:network_recovery_interval] = network_recovery_interval if network_recovery_interval
|
49
|
+
options[:logger] = RabbitFeed.log
|
50
|
+
options[:recover_from_connection_close] = true
|
51
|
+
options[:threaded] = true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
private
|
42
56
|
|
43
57
|
def self.read_configuration_file file_path, environment
|
@@ -4,17 +4,8 @@ module RabbitFeed
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
heartbeat: RabbitFeed.configuration.heartbeat,
|
10
|
-
connect_timeout: RabbitFeed.configuration.connect_timeout,
|
11
|
-
host: RabbitFeed.configuration.host,
|
12
|
-
user: RabbitFeed.configuration.user,
|
13
|
-
password: RabbitFeed.configuration.password,
|
14
|
-
port: RabbitFeed.configuration.port,
|
15
|
-
network_recovery_interval: RabbitFeed.configuration.network_recovery_interval,
|
16
|
-
logger: RabbitFeed.log,
|
17
|
-
}
|
7
|
+
def connection_options
|
8
|
+
RabbitFeed.configuration.connection_options
|
18
9
|
end
|
19
10
|
|
20
11
|
def with_connection &block
|
@@ -41,7 +32,7 @@ module RabbitFeed
|
|
41
32
|
RabbitFeed.log.warn "Closed connection exception encountered; #{tries - 1} tries remaining. #{self.to_s}: #{e.message} #{e.backtrace}"
|
42
33
|
unless (tries -= 1).zero?
|
43
34
|
unset_connection
|
44
|
-
sleep
|
35
|
+
sleep 1
|
45
36
|
retry
|
46
37
|
end
|
47
38
|
raise
|
@@ -70,7 +61,7 @@ module RabbitFeed
|
|
70
61
|
|
71
62
|
def connection_pool
|
72
63
|
@connection_pool ||= ConnectionPool.new(
|
73
|
-
size:
|
64
|
+
size: 1,
|
74
65
|
timeout: RabbitFeed.configuration.pool_timeout
|
75
66
|
) do
|
76
67
|
new bunny_connection.create_channel
|
@@ -55,12 +55,6 @@ module RabbitFeed
|
|
55
55
|
}.merge QUEUE_OPTIONS
|
56
56
|
end
|
57
57
|
|
58
|
-
def self.connection_options
|
59
|
-
default_connection_options.merge({
|
60
|
-
threaded: true,
|
61
|
-
})
|
62
|
-
end
|
63
|
-
|
64
58
|
def bind_on_accepted_routes
|
65
59
|
if RabbitFeed::Consumer.event_routing.present?
|
66
60
|
RabbitFeed::Consumer.event_routing.accepted_routes.each do |accepted_route|
|