rabbit_feed 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ada150cba6130fe7df806147c44d20e72027c95
4
- data.tar.gz: 4ca751e89bf9e476fb622e6db31660b59faeca53
3
+ metadata.gz: c8b4cfaedb7bc8c46cdd3e688e2e056433bd890f
4
+ data.tar.gz: 70f7da80ecb2066defee294ddd9268769306045d
5
5
  SHA512:
6
- metadata.gz: 807446c806430a173ef49307e3a4ca7a1afc22f9bc041e724ec17f208dbd638fb38f0fb85b83d853e3f75fb5f1dd2126ced965f795b9fb849c06f39ffe774ebc
7
- data.tar.gz: cd35aefc408cebbe6e7094335d9d113c7fabbedb11420878a78782748ba6ab01f7c17649c15ef975571ef7964221959478a4c4a607d1eade1310a2f9fe6f761b
6
+ metadata.gz: 441226227941a4caf225cdf2ba70cae72d0dfbcbf0bf0460fc42920ab2384b79a94bf218e344d10eaa177260a9058f4f3e5896d617dcbcb757e72a1e6b41c31e
7
+ data.tar.gz: 310e32a94ebde5f1d6cac89841d677099e6f7705af33a11a7252ae74587d55d545448a320db546adabdfa0c897106e0e668b0c436f4d003accaf75f915ff3c85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbit_feed (2.0.0)
4
+ rabbit_feed (2.1.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)
data/README.md CHANGED
@@ -308,6 +308,26 @@ When the consumer is started, it will create its queue named using this pattern:
308
308
 
309
309
  _Note: The consumer queues will automatically expire (delete) after 7 days without any consumer connections. This is to prevent unused queues from hanging around once their associated consumer has been terminated._
310
310
 
311
+ ### Wildcards
312
+
313
+ Applications that wish to handle events from any application or wish to handle any event can achieve this using the `:any` key.
314
+
315
+ For example, the following would consume any event published by RabbitFeed:
316
+
317
+ ```ruby
318
+ EventRouting do
319
+ accept_from(:any) do
320
+ event(:any) do |event|
321
+ puts event.payload
322
+ end
323
+ end
324
+ end
325
+ ```
326
+
327
+ In this example, the consumer queue will bind to the specified exchange on the following routing keys:
328
+
329
+ environment.*.*
330
+
311
331
  ## Delivery Semantics
312
332
 
313
333
  RabbitFeed provides 'at least once' delivery semantics. There are two use-cases where an event may be delivered more than once:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.0.0)
4
+ rabbit_feed (2.1.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)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.0.0)
4
+ rabbit_feed (2.1.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)
@@ -33,39 +33,66 @@ module RabbitFeed
33
33
  class Application
34
34
  include ActiveModel::Validations
35
35
 
36
- attr_reader :events, :name
36
+ attr_reader :named_events, :catch_all_event, :name
37
37
  validates_presence_of :name
38
38
 
39
39
  def initialize name
40
- @name = name
41
- @events = {}
40
+ @name = name
41
+ @named_events = {}
42
42
 
43
43
  validate!
44
44
  end
45
45
 
46
46
  def event name, &block
47
- event = (Event.new name, block)
48
- events[event.name] = event
47
+ if name == :any
48
+ accept_any_event &block
49
+ else
50
+ accept_named_event name, &block
51
+ end
49
52
  end
50
53
 
51
54
  def accepted_routes
52
- events.values.map do |event|
55
+ all_events.map do |event|
53
56
  "#{RabbitFeed.environment}.#{name}.#{event.name}"
54
57
  end
55
58
  end
56
59
 
57
60
  def handle_event event
58
- event_rule = events[event.name]
61
+ event_rule = find_event event
59
62
  event_rule.handle_event event
60
63
  end
61
64
 
62
65
  def handles_event? event
63
- events.has_key? event.name
66
+ (find_event event).present?
64
67
  end
65
68
 
69
+ private
70
+
66
71
  def validate!
67
72
  raise ConfigurationError.new "Bad application specification for #{name}: #{errors.messages}" if invalid?
68
73
  end
74
+
75
+ def accept_named_event name, &block
76
+ raise ConfigurationError.new "Routing has already been defined for the event with name: #{name} in application: #{self.name}" if (named_events.has_key? name)
77
+ event = (Event.new name, block)
78
+ named_events[event.name] = event
79
+ end
80
+
81
+ def accept_any_event &block
82
+ raise ConfigurationError.new "Routing has already been defined for the event catch-all: :any in application: #{name}" if catch_all_event.present?
83
+ event = (Event.new '*', block)
84
+ @catch_all_event = event
85
+ end
86
+
87
+ def find_event event
88
+ [named_events[event.name], catch_all_event].compact.first
89
+ end
90
+
91
+ def all_events
92
+ events = named_events.values
93
+ events << catch_all_event if catch_all_event.present?
94
+ events
95
+ end
69
96
  end
70
97
 
71
98
  attr_reader :named_applications, :catch_all_application
@@ -1,3 +1,3 @@
1
1
  module RabbitFeed
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -25,6 +25,11 @@ module RabbitFeed
25
25
  event.payload
26
26
  end
27
27
  end
28
+ accept_from('dummy_3') do
29
+ event(:any) do |event|
30
+ event.payload
31
+ end
32
+ end
28
33
  end
29
34
  end
30
35
 
@@ -36,6 +41,7 @@ module RabbitFeed
36
41
  test.dummy_2.event_3
37
42
  test.*.event_3
38
43
  test.*.event_4
44
+ test.dummy_3.*
39
45
  }
40
46
  end
41
47
 
@@ -46,6 +52,8 @@ module RabbitFeed
46
52
  Event.new({application: 'dummy_1', name: 'event_4'}, {payload: 4}),
47
53
  Event.new({application: 'dummy_2', name: 'event_3'}, {payload: 3}),
48
54
  Event.new({application: 'none', name: 'event_4'}, {payload: 4}),
55
+ Event.new({application: 'dummy_3', name: 'event_1'}, {payload: 1}),
56
+ Event.new({application: 'dummy_3', name: 'event_2'}, {payload: 2}),
49
57
  ]
50
58
  events.each do |event|
51
59
  (RabbitFeed::Consumer.event_routing.handle_event event).should eq event.payload
@@ -112,7 +120,7 @@ module RabbitFeed
112
120
  context 'testing cumulative routing definitions' do
113
121
  before do
114
122
  EventRouting do
115
- accept_from('dummy_3') do
123
+ accept_from('dummy_4') do
116
124
  event('event_4') do |event|
117
125
  event.payload
118
126
  end
@@ -125,9 +133,10 @@ module RabbitFeed
125
133
  test.dummy_1.event_1
126
134
  test.dummy_1.event_2
127
135
  test.dummy_2.event_3
128
- test.dummy_3.event_4
136
+ test.dummy_4.event_4
129
137
  test.*.event_3
130
138
  test.*.event_4
139
+ test.dummy_3.*
131
140
  }
132
141
  end
133
142
  end
@@ -143,7 +152,7 @@ module RabbitFeed
143
152
  end
144
153
  end
145
154
  end
146
- end.to raise_error ConfigurationError
155
+ end.to raise_error 'Routing has already been defined for the application with name: dummy_2'
147
156
  end
148
157
 
149
158
  it 'raises an exception for the catch-all application' do
@@ -155,7 +164,40 @@ module RabbitFeed
155
164
  end
156
165
  end
157
166
  end
158
- end.to raise_error ConfigurationError
167
+ end.to raise_error 'Routing has already been defined for the application catch-all: :any'
168
+ end
169
+ end
170
+
171
+ context 'defining the same event twice' do
172
+
173
+ it 'raises an exception for a named event' do
174
+ expect do
175
+ EventRouting do
176
+ accept_from('dummy_5') do
177
+ event('event_3') do |event|
178
+ event.payload
179
+ end
180
+ event('event_3') do |event|
181
+ event.payload
182
+ end
183
+ end
184
+ end
185
+ end.to raise_error 'Routing has already been defined for the event with name: event_3 in application: dummy_5'
186
+ end
187
+
188
+ it 'raises an exception for the catch-all event' do
189
+ expect do
190
+ EventRouting do
191
+ accept_from('dummy_5') do
192
+ event(:any) do |event|
193
+ event.payload
194
+ end
195
+ event(:any) do |event|
196
+ event.payload
197
+ end
198
+ end
199
+ end
200
+ end.to raise_error 'Routing has already been defined for the event catch-all: :any in application: dummy_5'
159
201
  end
160
202
  end
161
203
  end
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: 2.0.0
4
+ version: 2.1.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: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny