dispatch-rider 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -29,6 +29,36 @@ Or install it yourself as:
29
29
 
30
30
  Setting up a publisher is simple.
31
31
 
32
+ ### Hash Based Configuration
33
+
34
+ All configuration can be loaded from a hash instead of being done like the examples below.
35
+ (currently only implemented for the publisher)
36
+
37
+ eg:
38
+
39
+ ```ruby
40
+ publisher = DispatchRider::Publisher.new
41
+ publisher.configure({
42
+ notification_services: {
43
+ file_system: {}
44
+ },
45
+ destinations: {
46
+ file_foo: {
47
+ service: :file_system,
48
+ channel: :foo,
49
+ options: {
50
+ path: "test/channel",
51
+ }
52
+ }
53
+ }
54
+ })
55
+ ```
56
+
57
+ You can load this configuration hash from a YAML file or something, whatever works
58
+ well for your environment.
59
+
60
+ #### The old way ...
61
+
32
62
  To publish using the filesystem register the path where to publish the message files.
33
63
 
34
64
  ```ruby
@@ -175,6 +205,31 @@ Sample subscriber setup:
175
205
 
176
206
  ```
177
207
 
208
+ Sample subscriber dispatch error handling (optional):
209
+
210
+ ```ruby
211
+
212
+ # using blocks
213
+
214
+ subscriber.on_dispatch_error do |message, exception|
215
+ # put your error handling code here
216
+
217
+ return false # or return true to permanently remove the message
218
+ end
219
+
220
+ # using methods
221
+
222
+ def handle_dispatch_error(message, exception)
223
+ # put your error handling code here
224
+
225
+ return false # or return true to permanently remove the message
226
+ end
227
+
228
+ subscriber.on_dispatch_error &method(:handle_dispatch_error)
229
+
230
+ ```
231
+
232
+
178
233
  Sample Rails application rake task:
179
234
 
180
235
  ```ruby
@@ -12,10 +12,23 @@ module DispatchRider
12
12
 
13
13
  def initialize
14
14
  @handler_registrar = Registrars::Handler.new
15
+ @error_handler = method(:default_error_handler)
16
+ end
17
+
18
+ def on_error(&block)
19
+ @error_handler = block
15
20
  end
16
21
 
17
22
  def dispatch(message)
18
23
  handler_registrar.fetch(message.subject).process(message.body)
24
+ rescue Exception => exception
25
+ @error_handler.call(message, exception)
26
+ end
27
+
28
+ private
29
+
30
+ def default_error_handler(message, exception)
31
+ raise exception
19
32
  end
20
33
  end
21
34
  end
@@ -9,7 +9,7 @@ module DispatchRider
9
9
  end
10
10
 
11
11
  def publish(message)
12
- @file_system_queue.add(message.to_json)
12
+ @file_system_queue.add(message)
13
13
  end
14
14
  end
15
15
  end
@@ -1,8 +1,14 @@
1
+ require "active_support/core_ext/hash/indifferent_access"
2
+
1
3
  # This class takes care of the publishing side of the messaging system.
2
4
  module DispatchRider
3
5
  class Publisher
4
6
  attr_reader :service_channel_mapper, :notification_service_registrar, :publishing_destination_registrar, :sns_channel_registrar
5
7
 
8
+ def configure(configuration_hash = {})
9
+ ConfigurationReader.parse(configuration_hash.with_indifferent_access, self)
10
+ end
11
+
6
12
  def initialize
7
13
  @notification_service_registrar = DispatchRider::Registrars::NotificationService.new
8
14
  @publishing_destination_registrar = DispatchRider::Registrars::PublishingDestination.new
@@ -63,3 +69,5 @@ module DispatchRider
63
69
  end
64
70
  end
65
71
  end
72
+
73
+ require_relative "publisher/configuration_reader"
@@ -0,0 +1,32 @@
1
+ module DispatchRider
2
+
3
+ class Publisher
4
+
5
+ module ConfigurationReader
6
+
7
+ class << self
8
+ def parse(configuration_hash, publisher)
9
+ configure_notification_services(configuration_hash[:notification_services], publisher) if configuration_hash[:notification_services]
10
+ configure_destinations(configuration_hash[:destinations], publisher) if configuration_hash[:destinations]
11
+ end
12
+
13
+ private
14
+
15
+ def configure_notification_services(notification_services, publisher)
16
+ notification_services.each do |(service_name, service_options)|
17
+ publisher.register_notification_service(service_name, service_options)
18
+ end
19
+ end
20
+
21
+ def configure_destinations(destinations, publisher)
22
+ destinations.each do |(destination_name, info)|
23
+ publisher.register_destination(destination_name, info[:service], info[:channel], info[:options])
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -23,6 +23,10 @@ module DispatchRider
23
23
  self
24
24
  end
25
25
 
26
+ def on_dispatch_error(&block)
27
+ dispatcher.on_error &block
28
+ end
29
+
26
30
  def setup_demultiplexer(queue_name)
27
31
  queue = queue_service_registrar.fetch(queue_name)
28
32
  @demultiplexer ||= DispatchRider::Demultiplexer.new(queue, dispatcher)
@@ -1,4 +1,4 @@
1
1
  # This file specifies the current version of the gem.
2
2
  module DispatchRider
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
metadata CHANGED
@@ -1,17 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatch-rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Suman Mukherjee
9
- - Ronald Maravilla
10
- - Piotr Banasik
11
9
  autorequire:
12
10
  bindir: bin
13
11
  cert_chain: []
14
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-06-06 00:00:00.000000000 Z
15
13
  dependencies:
16
14
  - !ruby/object:Gem::Dependency
17
15
  name: activesupport
@@ -161,8 +159,6 @@ description: Messaging system that is customizable based on which queueing syste
161
159
  we are using.
162
160
  email:
163
161
  - sumanmukherjee03@gmail.com
164
- - more.ron.too@gmail.com
165
- - piotr.banasik@gmail.com
166
162
  executables:
167
163
  - dispatch_rider
168
164
  extensions: []
@@ -183,6 +179,7 @@ files:
183
179
  - lib/dispatch-rider/notification_services/file_system/channel.rb
184
180
  - lib/dispatch-rider/notification_services/file_system/notifier.rb
185
181
  - lib/dispatch-rider/publisher.rb
182
+ - lib/dispatch-rider/publisher/configuration_reader.rb
186
183
  - lib/dispatch-rider/queue_services.rb
187
184
  - lib/dispatch-rider/queue_services/aws_sqs.rb
188
185
  - lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb
@@ -202,7 +199,7 @@ files:
202
199
  - lib/dispatch-rider/version.rb
203
200
  - LICENSE.txt
204
201
  - README.md
205
- homepage: https://github.com/payrollhero/dispatch-rider
202
+ homepage: ''
206
203
  licenses:
207
204
  - MIT
208
205
  post_install_message:
@@ -217,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
214
  version: '0'
218
215
  segments:
219
216
  - 0
220
- hash: -3605041447060429079
217
+ hash: -3484049687612647062
221
218
  required_rubygems_version: !ruby/object:Gem::Requirement
222
219
  none: false
223
220
  requirements: