dispatch-rider 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/LICENSE.txt +22 -0
  2. data/README.md +270 -0
  3. data/bin/dispatch_rider +17 -0
  4. data/lib/dispatch-rider.rb +21 -0
  5. data/lib/dispatch-rider/demultiplexer.rb +36 -0
  6. data/lib/dispatch-rider/dispatcher.rb +21 -0
  7. data/lib/dispatch-rider/errors.rb +34 -0
  8. data/lib/dispatch-rider/message.rb +33 -0
  9. data/lib/dispatch-rider/notification_services.rb +9 -0
  10. data/lib/dispatch-rider/notification_services/aws_sns.rb +23 -0
  11. data/lib/dispatch-rider/notification_services/base.rb +57 -0
  12. data/lib/dispatch-rider/notification_services/file_system.rb +22 -0
  13. data/lib/dispatch-rider/notification_services/file_system/channel.rb +16 -0
  14. data/lib/dispatch-rider/notification_services/file_system/notifier.rb +17 -0
  15. data/lib/dispatch-rider/publisher.rb +65 -0
  16. data/lib/dispatch-rider/queue_services.rb +10 -0
  17. data/lib/dispatch-rider/queue_services/aws_sqs.rb +39 -0
  18. data/lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb +17 -0
  19. data/lib/dispatch-rider/queue_services/base.rb +74 -0
  20. data/lib/dispatch-rider/queue_services/file_system.rb +39 -0
  21. data/lib/dispatch-rider/queue_services/file_system/queue.rb +42 -0
  22. data/lib/dispatch-rider/queue_services/simple.rb +30 -0
  23. data/lib/dispatch-rider/registrars.rb +13 -0
  24. data/lib/dispatch-rider/registrars/base.rb +39 -0
  25. data/lib/dispatch-rider/registrars/file_system_channel.rb +11 -0
  26. data/lib/dispatch-rider/registrars/handler.rb +10 -0
  27. data/lib/dispatch-rider/registrars/notification_service.rb +10 -0
  28. data/lib/dispatch-rider/registrars/publishing_destination.rb +9 -0
  29. data/lib/dispatch-rider/registrars/queue_service.rb +10 -0
  30. data/lib/dispatch-rider/registrars/sns_channel.rb +10 -0
  31. data/lib/dispatch-rider/subscriber.rb +41 -0
  32. data/lib/dispatch-rider/version.rb +4 -0
  33. metadata +236 -0
@@ -0,0 +1,30 @@
1
+ # This is a simple implementation of an in memory queue using an array.
2
+ module DispatchRider
3
+ module QueueServices
4
+ class Simple < Base
5
+ def assign_storage(attrs)
6
+ []
7
+ end
8
+
9
+ def insert(item)
10
+ queue << item
11
+ end
12
+
13
+ def raw_head
14
+ queue.first
15
+ end
16
+
17
+ def construct_message_from(item)
18
+ deserialize(item)
19
+ end
20
+
21
+ def delete(item)
22
+ queue.delete(item)
23
+ end
24
+
25
+ def size
26
+ queue.size
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # The namespace that holds the registrars
2
+ module DispatchRider
3
+ module Registrars
4
+ end
5
+ end
6
+
7
+ require "dispatch-rider/registrars/base"
8
+ require "dispatch-rider/registrars/notification_service"
9
+ require "dispatch-rider/registrars/sns_channel"
10
+ require "dispatch-rider/registrars/publishing_destination"
11
+ require "dispatch-rider/registrars/file_system_channel"
12
+ require "dispatch-rider/registrars/queue_service"
13
+ require "dispatch-rider/registrars/handler"
@@ -0,0 +1,39 @@
1
+ # This is the base class for the registrars.
2
+ # It defines the interface that other registrars inherit.
3
+ # This is an abstract class.
4
+ # The child classes inheriting this interface must define the 'value' method.
5
+ module DispatchRider
6
+ module Registrars
7
+ class Base
8
+ attr_reader :store
9
+
10
+ def initialize
11
+ @store = {}
12
+ end
13
+
14
+ def register(name, options = {})
15
+ store[name.to_sym] = value(name, options)
16
+ self
17
+ rescue NameError
18
+ raise NotFound.new(name)
19
+ end
20
+
21
+ def value(name, options = {})
22
+ raise NotImplementedError
23
+ end
24
+
25
+ def unregister(name)
26
+ store.delete(name.to_sym)
27
+ self
28
+ end
29
+
30
+ def fetch(name)
31
+ begin
32
+ store.fetch(name.to_sym)
33
+ rescue IndexError
34
+ raise NotRegistered.new(name)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ # This is the registrar for FileSystem channels, basically storing paths
2
+
3
+ module DispatchRider
4
+ module Registrars
5
+ class FileSystemChannel < Base
6
+ def value(name, options = {})
7
+ File.expand_path(options[:path])
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # This is the registrar for the handlers.
2
+ module DispatchRider
3
+ module Registrars
4
+ class Handler < Base
5
+ def value(name, options = {})
6
+ name.to_s.camelize.constantize
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # This registrar handles the registration of various notification services.
2
+ module DispatchRider
3
+ module Registrars
4
+ class NotificationService < Base
5
+ def value(name, options = {})
6
+ "DispatchRider::NotificationServices::#{name.to_s.camelize}".constantize.new(options)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module DispatchRider
2
+ module Registrars
3
+ class PublishingDestination < Base
4
+ def value(name, options = {})
5
+ OpenStruct.new(:service => options[:service], :channel => options[:channel])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # This si the registrar for queue services.
2
+ module DispatchRider
3
+ module Registrars
4
+ class QueueService < Base
5
+ def value(name, options = {})
6
+ "DispatchRider::QueueServices::#{name.to_s.camelize}".constantize.new(options)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # This is the registrar for the AWS SNS channels.
2
+ module DispatchRider
3
+ module Registrars
4
+ class SnsChannel < Base
5
+ def value(name, options = {})
6
+ "arn:aws:sns:#{options[:region]}:#{options[:account]}:#{options[:topic]}"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ # This class takes care of the subscribing side of the messaging system.
2
+ module DispatchRider
3
+ class Subscriber
4
+ attr_reader :queue_service_registrar, :dispatcher, :demultiplexer
5
+
6
+ def initialize
7
+ @queue_service_registrar = DispatchRider::Registrars::QueueService.new
8
+ @dispatcher = DispatchRider::Dispatcher.new
9
+ end
10
+
11
+ def register_queue(name, options = {})
12
+ queue_service_registrar.register(name, options)
13
+ self
14
+ end
15
+
16
+ def register_handler(name)
17
+ dispatcher.register(name)
18
+ self
19
+ end
20
+
21
+ def register_handlers(*names)
22
+ names.each {|name| register_handler(name)}
23
+ self
24
+ end
25
+
26
+ def setup_demultiplexer(queue_name)
27
+ queue = queue_service_registrar.fetch(queue_name)
28
+ @demultiplexer ||= DispatchRider::Demultiplexer.new(queue, dispatcher)
29
+ self
30
+ end
31
+
32
+ def process
33
+ interuption_count = 0
34
+ Signal.trap("INT") do
35
+ interuption_count += 1
36
+ interuption_count < 2 ? demultiplexer.stop : exit(0)
37
+ end
38
+ demultiplexer.start
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ # This file specifies the current version of the gem.
2
+ module DispatchRider
3
+ VERSION = "0.0.3"
4
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dispatch-rider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Suman Mukherjee
9
+ - Ronald Maravilla
10
+ - Piotr Banasik
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-05-30 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: activemodel
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: daemons
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: bundler
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.8.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 1.8.4
96
+ - !ruby/object:Gem::Dependency
97
+ name: rake
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: travis-lint
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ - !ruby/object:Gem::Dependency
129
+ name: rspec
130
+ requirement: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ - !ruby/object:Gem::Dependency
145
+ name: debugger
146
+ requirement: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ description: Messaging system that is customizable based on which queueing system
161
+ we are using.
162
+ email:
163
+ - sumanmukherjee03@gmail.com
164
+ - more.ron.too@gmail.com
165
+ - piotr.banasik@gmail.com
166
+ executables:
167
+ - dispatch_rider
168
+ extensions: []
169
+ extra_rdoc_files:
170
+ - LICENSE.txt
171
+ - README.md
172
+ files:
173
+ - bin/dispatch_rider
174
+ - lib/dispatch-rider.rb
175
+ - lib/dispatch-rider/demultiplexer.rb
176
+ - lib/dispatch-rider/dispatcher.rb
177
+ - lib/dispatch-rider/errors.rb
178
+ - lib/dispatch-rider/message.rb
179
+ - lib/dispatch-rider/notification_services.rb
180
+ - lib/dispatch-rider/notification_services/aws_sns.rb
181
+ - lib/dispatch-rider/notification_services/base.rb
182
+ - lib/dispatch-rider/notification_services/file_system.rb
183
+ - lib/dispatch-rider/notification_services/file_system/channel.rb
184
+ - lib/dispatch-rider/notification_services/file_system/notifier.rb
185
+ - lib/dispatch-rider/publisher.rb
186
+ - lib/dispatch-rider/queue_services.rb
187
+ - lib/dispatch-rider/queue_services/aws_sqs.rb
188
+ - lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb
189
+ - lib/dispatch-rider/queue_services/base.rb
190
+ - lib/dispatch-rider/queue_services/file_system.rb
191
+ - lib/dispatch-rider/queue_services/file_system/queue.rb
192
+ - lib/dispatch-rider/queue_services/simple.rb
193
+ - lib/dispatch-rider/registrars.rb
194
+ - lib/dispatch-rider/registrars/base.rb
195
+ - lib/dispatch-rider/registrars/file_system_channel.rb
196
+ - lib/dispatch-rider/registrars/handler.rb
197
+ - lib/dispatch-rider/registrars/notification_service.rb
198
+ - lib/dispatch-rider/registrars/publishing_destination.rb
199
+ - lib/dispatch-rider/registrars/queue_service.rb
200
+ - lib/dispatch-rider/registrars/sns_channel.rb
201
+ - lib/dispatch-rider/subscriber.rb
202
+ - lib/dispatch-rider/version.rb
203
+ - LICENSE.txt
204
+ - README.md
205
+ homepage: https://github.com/payrollhero/dispatch-rider
206
+ licenses:
207
+ - MIT
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ segments:
219
+ - 0
220
+ hash: -3605041447060429079
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ! '>='
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubyforge_project:
229
+ rubygems_version: 1.8.25
230
+ signing_key:
231
+ specification_version: 3
232
+ summary: Messaging system based on the reactor patter. You can publish messages to
233
+ a queue and then a demultiplexer runs an event loop which pops items from the queue
234
+ and hands it over to a dispatcher. The dispatcher hands over the message to the
235
+ appropriate handler. You can choose your own queueing service.
236
+ test_files: []