rservicebus 0.0.39 → 0.0.40
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/lib/rservicebus/Host.rb +151 -147
- data/lib/rservicebus/MQ/Beanstalk.rb +6 -1
- metadata +2 -2
data/lib/rservicebus/Host.rb
CHANGED
@@ -6,16 +6,16 @@ module RServiceBus
|
|
6
6
|
|
7
7
|
#Host process for rservicebus
|
8
8
|
class Host
|
9
|
-
|
9
|
+
|
10
10
|
@handlerList
|
11
11
|
@resourceByHandlerNameList
|
12
|
-
|
12
|
+
|
13
13
|
@subscriptions
|
14
|
-
|
14
|
+
|
15
15
|
@mq
|
16
|
-
|
16
|
+
|
17
17
|
@appResources
|
18
|
-
|
18
|
+
|
19
19
|
@config
|
20
20
|
|
21
21
|
@subscriptionManager
|
@@ -34,13 +34,13 @@ module RServiceBus
|
|
34
34
|
@appResources = ConfigureAppResource.new.getResources( ENV )
|
35
35
|
return self;
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def connectToMq
|
39
39
|
@mq = ConfigureMQ.new.get( @config.mqHost + "/" + @config.localQueueName, @config.queueTimeout )
|
40
|
-
|
40
|
+
|
41
41
|
return self
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
#Subscriptions are specified by adding events to the
|
45
45
|
#msg endpoint mapping
|
46
46
|
def sendSubscriptions
|
@@ -100,7 +100,7 @@ module RServiceBus
|
|
100
100
|
def configureSubscriptions
|
101
101
|
subscriptionStorage = ConfigureSubscriptionStorage.new.get( @config.appName, @config.subscriptionUri )
|
102
102
|
@subscriptionManager = SubscriptionManager.new( subscriptionStorage )
|
103
|
-
|
103
|
+
|
104
104
|
return self
|
105
105
|
end
|
106
106
|
|
@@ -121,7 +121,7 @@ module RServiceBus
|
|
121
121
|
.loadHandlerPathList()
|
122
122
|
.loadLibs()
|
123
123
|
.loadWorkingDirList();
|
124
|
-
|
124
|
+
|
125
125
|
self.configureStatistics()
|
126
126
|
.configureAppResource()
|
127
127
|
.connectToMq()
|
@@ -151,9 +151,9 @@ module RServiceBus
|
|
151
151
|
log "Waiting for messages. To exit press CTRL+C"
|
152
152
|
statOutputCountdown = 0
|
153
153
|
messageLoop = true
|
154
|
-
|
154
|
+
retries = @config.maxRetries
|
155
|
+
|
155
156
|
while messageLoop do
|
156
|
-
retries = @config.maxRetries
|
157
157
|
#Popping a msg off the queue should not be in the message handler, as it affects retry
|
158
158
|
begin
|
159
159
|
if statOutputCountdown == 0 then
|
@@ -178,10 +178,10 @@ module RServiceBus
|
|
178
178
|
@mq.ack
|
179
179
|
rescue Exception => e
|
180
180
|
sleep 0.5
|
181
|
-
|
181
|
+
|
182
182
|
puts e.message
|
183
183
|
puts e.backtrace
|
184
|
-
|
184
|
+
|
185
185
|
tempHandlerList = Hash.new
|
186
186
|
tempResourceList = Hash.new
|
187
187
|
@handlerList[@msg.msg.class.name].each do |handler|
|
@@ -192,167 +192,171 @@ module RServiceBus
|
|
192
192
|
end
|
193
193
|
tempResourceList.each {|k,resource| resource.reconnect }
|
194
194
|
tempHandlerList.each {|k,handler| @handlerLoader.setAppResources( handler ) }
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
195
|
+
|
196
|
+
if retries > 0 then
|
197
|
+
retries = retries - 1
|
198
|
+
@mq.returnToQueue
|
199
|
+
else
|
200
|
+
|
201
|
+
@stats.incTotalErrored
|
202
|
+
if e.class.name == "Beanstalk::NotConnected" then
|
203
|
+
puts "Lost connection to beanstalkd."
|
204
|
+
puts "*** Start or Restart beanstalkd and try again."
|
205
|
+
abort();
|
206
|
+
end
|
207
|
+
|
208
|
+
if e.class.name == "Redis::CannotConnectError" then
|
209
|
+
puts "Lost connection to redis."
|
210
|
+
puts "*** Start or Restart redis and try again."
|
211
|
+
abort();
|
212
|
+
end
|
213
|
+
|
214
|
+
errorString = e.message + ". " + e.backtrace.join( ". " )
|
215
|
+
log errorString
|
216
|
+
|
217
|
+
@msg.addErrorMsg( @config.localQueueName, errorString )
|
218
|
+
serialized_object = YAML::dump(@msg)
|
219
|
+
self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
|
220
|
+
@mq.ack
|
221
|
+
retries = @config.maxRetries
|
210
222
|
end
|
211
|
-
|
212
|
-
errorString = e.message + ". " + e.backtrace.join( ". " )
|
213
|
-
log errorString
|
214
|
-
|
215
|
-
@msg.addErrorMsg( @config.localQueueName, errorString )
|
216
|
-
serialized_object = YAML::dump(@msg)
|
217
|
-
self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
|
218
|
-
@mq.ack
|
219
223
|
end
|
220
224
|
rescue SystemExit, Interrupt
|
221
225
|
puts "Exiting on request ..."
|
222
226
|
messageLoop = false
|
223
|
-
|
227
|
+
|
224
228
|
rescue NoMsgToProcess => e
|
225
229
|
#This exception is just saying there are no messages to process
|
226
230
|
statOutputCountdown = 0
|
227
231
|
rescue Exception => e
|
228
232
|
if e.message == "SIGTERM" then
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
233
|
+
puts "Exiting on request ..."
|
234
|
+
messageLoop = false
|
235
|
+
else
|
236
|
+
puts "*** This is really unexpected."
|
237
|
+
messageLoop = false
|
238
|
+
puts "Message: " + e.message
|
239
|
+
puts e.backtrace
|
240
|
+
end
|
236
241
|
end
|
237
242
|
end
|
238
243
|
end
|
239
|
-
end
|
240
|
-
|
241
|
-
#Send the current msg to the appropriate handlers
|
242
|
-
def HandleMessage()
|
243
|
-
msgName = @msg.msg.class.name
|
244
|
-
handlerList = @handlerList[msgName]
|
245
244
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
245
|
+
#Send the current msg to the appropriate handlers
|
246
|
+
def HandleMessage()
|
247
|
+
msgName = @msg.msg.class.name
|
248
|
+
handlerList = @handlerList[msgName]
|
249
|
+
|
250
|
+
if handlerList == nil then
|
251
|
+
log "No handler found for: " + msgName
|
252
|
+
puts "No handler found for: " + msgName
|
253
|
+
puts YAML::dump(@msg)
|
254
|
+
raise "No Handler Found"
|
255
|
+
else
|
256
|
+
log "Handler found for: " + msgName, true
|
257
|
+
handlerList.each do |handler|
|
258
|
+
begin
|
259
|
+
handler.Handle( @msg.msg )
|
260
|
+
rescue Exception => e
|
261
|
+
log "An error occured in Handler: " + handler.class.name
|
262
|
+
log e.message + ". " + e.backtrace[0]
|
263
|
+
raise e
|
264
|
+
end
|
260
265
|
end
|
261
266
|
end
|
262
267
|
end
|
263
|
-
end
|
264
|
-
|
265
|
-
#Sends a msg across the bus
|
266
|
-
#
|
267
|
-
# @param [String] serialized_object serialized RServiceBus::Message
|
268
|
-
# @param [String] queueName endpoint to which the msg will be sent
|
269
|
-
def _SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
270
|
-
log "Bus._SendAlreadyWrappedAndSerialised", true
|
271
268
|
|
272
|
-
|
273
|
-
|
269
|
+
#Sends a msg across the bus
|
270
|
+
#
|
271
|
+
# @param [String] serialized_object serialized RServiceBus::Message
|
272
|
+
# @param [String] queueName endpoint to which the msg will be sent
|
273
|
+
def _SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
274
|
+
log "Bus._SendAlreadyWrappedAndSerialised", true
|
275
|
+
|
276
|
+
if !@config.forwardSentMessagesTo.nil? then
|
277
|
+
@mq.send( @config.forwardSentMessagesTo, serialized_object )
|
278
|
+
end
|
279
|
+
|
280
|
+
@mq.send( queueName, serialized_object )
|
274
281
|
end
|
275
282
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
serialized_object = YAML::dump(rMsg)
|
288
|
-
log "Sending: " + msg.class.name + " to: " + queueName, true
|
289
|
-
self._SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
290
|
-
end
|
291
|
-
|
292
|
-
#Sends a msg back across the bus
|
293
|
-
#Reply queues are specified in each msg. It works like
|
294
|
-
#email, where the reply address can actually be anywhere
|
295
|
-
#
|
296
|
-
# @param [RServiceBus::Message] msg msg to be sent
|
297
|
-
def Reply( msg )
|
298
|
-
log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
|
299
|
-
@stats.incTotalReply
|
300
|
-
|
301
|
-
self._SendNeedsWrapping( msg, @msg.returnAddress )
|
302
|
-
end
|
303
|
-
|
304
|
-
|
305
|
-
#Send a msg across the bus
|
306
|
-
#msg destination is specified at the infrastructure level
|
307
|
-
#
|
308
|
-
# @param [RServiceBus::Message] msg msg to be sent
|
309
|
-
def Send( msg )
|
310
|
-
log "Bus.Send", true
|
311
|
-
@stats.incTotalSent
|
312
|
-
|
313
|
-
msgName = msg.class.name
|
314
|
-
if @config.messageEndpointMappings.has_key?( msgName ) then
|
315
|
-
queueName = @config.messageEndpointMappings[msgName]
|
316
|
-
elsif !@handlerList[msgName].nil? then
|
317
|
-
queueName = @config.localQueueName
|
318
|
-
else
|
319
|
-
log "No end point mapping found for: " + msgName
|
320
|
-
log "**** Check environment variable MessageEndpointMappings contains an entry named : " + msgName
|
321
|
-
raise "No end point mapping found for: " + msgName
|
283
|
+
#Sends a msg across the bus
|
284
|
+
#
|
285
|
+
# @param [RServiceBus::Message] msg msg to be sent
|
286
|
+
# @param [String] queueName endpoint to which the msg will be sent
|
287
|
+
def _SendNeedsWrapping( msg, queueName )
|
288
|
+
log "Bus._SendNeedsWrapping", true
|
289
|
+
|
290
|
+
rMsg = RServiceBus::Message.new( msg, @config.localQueueName )
|
291
|
+
serialized_object = YAML::dump(rMsg)
|
292
|
+
log "Sending: " + msg.class.name + " to: " + queueName, true
|
293
|
+
self._SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
322
294
|
end
|
323
295
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
subscriptions = @subscriptionManager.get(msg.class.name)
|
336
|
-
subscriptions.each do |subscriber|
|
337
|
-
self._SendNeedsWrapping( msg, subscriber )
|
296
|
+
#Sends a msg back across the bus
|
297
|
+
#Reply queues are specified in each msg. It works like
|
298
|
+
#email, where the reply address can actually be anywhere
|
299
|
+
#
|
300
|
+
# @param [RServiceBus::Message] msg msg to be sent
|
301
|
+
def Reply( msg )
|
302
|
+
log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
|
303
|
+
@stats.incTotalReply
|
304
|
+
|
305
|
+
self._SendNeedsWrapping( msg, @msg.returnAddress )
|
338
306
|
end
|
339
307
|
|
340
|
-
end
|
341
|
-
|
342
|
-
#Sends a subscription request across the Bus
|
343
|
-
#
|
344
|
-
# @param [String] eventName event to be subscribes to
|
345
|
-
def Subscribe( eventName )
|
346
|
-
log "Bus.Subscribe: " + eventName, true
|
347
308
|
|
309
|
+
#Send a msg across the bus
|
310
|
+
#msg destination is specified at the infrastructure level
|
311
|
+
#
|
312
|
+
# @param [RServiceBus::Message] msg msg to be sent
|
313
|
+
def Send( msg )
|
314
|
+
log "Bus.Send", true
|
315
|
+
@stats.incTotalSent
|
316
|
+
|
317
|
+
msgName = msg.class.name
|
318
|
+
if @config.messageEndpointMappings.has_key?( msgName ) then
|
319
|
+
queueName = @config.messageEndpointMappings[msgName]
|
320
|
+
elsif !@handlerList[msgName].nil? then
|
321
|
+
queueName = @config.localQueueName
|
322
|
+
else
|
323
|
+
log "No end point mapping found for: " + msgName
|
324
|
+
log "**** Check environment variable MessageEndpointMappings contains an entry named : " + msgName
|
325
|
+
raise "No end point mapping found for: " + msgName
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
self._SendNeedsWrapping( msg, queueName )
|
330
|
+
end
|
348
331
|
|
349
|
-
|
350
|
-
|
332
|
+
#Sends an event to all subscribers across the bus
|
333
|
+
#
|
334
|
+
# @param [RServiceBus::Message] msg msg to be sent
|
335
|
+
def Publish( msg )
|
336
|
+
log "Bus.Publish", true
|
337
|
+
@stats.incTotalPublished
|
338
|
+
|
339
|
+
subscriptions = @subscriptionManager.get(msg.class.name)
|
340
|
+
subscriptions.each do |subscriber|
|
341
|
+
self._SendNeedsWrapping( msg, subscriber )
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
351
345
|
|
346
|
+
#Sends a subscription request across the Bus
|
347
|
+
#
|
348
|
+
# @param [String] eventName event to be subscribes to
|
349
|
+
def Subscribe( eventName )
|
350
|
+
log "Bus.Subscribe: " + eventName, true
|
351
|
+
|
352
|
+
|
353
|
+
queueName = @config.messageEndpointMappings[eventName]
|
354
|
+
subscription = Message_Subscription.new( eventName )
|
355
|
+
|
356
|
+
|
357
|
+
self._SendNeedsWrapping( subscription, queueName )
|
358
|
+
end
|
352
359
|
|
353
|
-
self._SendNeedsWrapping( subscription, queueName )
|
354
360
|
end
|
355
361
|
|
356
362
|
end
|
357
|
-
|
358
|
-
end
|
@@ -12,7 +12,7 @@ module RServiceBus
|
|
12
12
|
def connect( host, port )
|
13
13
|
port ||= 11300
|
14
14
|
string = "#{host}:#{port}"
|
15
|
-
|
15
|
+
|
16
16
|
begin
|
17
17
|
@beanstalk = Beanstalk::Pool.new([string])
|
18
18
|
rescue Exception => e
|
@@ -47,6 +47,11 @@ module RServiceBus
|
|
47
47
|
end
|
48
48
|
return @job.body
|
49
49
|
end
|
50
|
+
|
51
|
+
def returnToQueue
|
52
|
+
@job.release
|
53
|
+
|
54
|
+
end
|
50
55
|
|
51
56
|
# "Commit" queue
|
52
57
|
def ack
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rservicebus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.40
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|