rservicebus 0.0.54 → 0.0.55
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rservicebus/AppResource.rb +15 -0
- data/lib/rservicebus/AppResource/FluidDbPgsql.rb +16 -0
- data/lib/rservicebus/Host.rb +72 -21
- metadata +2 -2
@@ -8,5 +8,21 @@ module RServiceBus
|
|
8
8
|
def connect(uri)
|
9
9
|
return FluidDb::Pgsql.new( uri )
|
10
10
|
end
|
11
|
+
|
12
|
+
# Transaction Semantics
|
13
|
+
def Begin
|
14
|
+
@connection.execute( "BEGIN", [] )
|
15
|
+
end
|
16
|
+
|
17
|
+
# Transaction Semantics
|
18
|
+
def Commit
|
19
|
+
@connection.execute( "COMMIT", [] )
|
20
|
+
end
|
21
|
+
|
22
|
+
# Transaction Semantics
|
23
|
+
def Rollback
|
24
|
+
@connection.execute( "ROLLBACK", [] )
|
25
|
+
end
|
26
|
+
|
11
27
|
end
|
12
28
|
end
|
data/lib/rservicebus/Host.rb
CHANGED
@@ -22,6 +22,10 @@ module RServiceBus
|
|
22
22
|
|
23
23
|
@stats
|
24
24
|
|
25
|
+
|
26
|
+
@queueForMsgsToBeSentOnComplete
|
27
|
+
|
28
|
+
|
25
29
|
#Provides a thin logging veneer
|
26
30
|
#
|
27
31
|
# @param [String] string Log entry
|
@@ -33,21 +37,21 @@ module RServiceBus
|
|
33
37
|
puts "[#{type}] #{timestamp} :: #{string}"
|
34
38
|
end
|
35
39
|
end
|
36
|
-
|
40
|
+
|
37
41
|
#Thin veneer for Configuring external resources
|
38
42
|
#
|
39
43
|
def configureAppResource
|
40
44
|
@appResources = ConfigureAppResource.new.getResources( ENV )
|
41
45
|
return self;
|
42
46
|
end
|
43
|
-
|
47
|
+
|
44
48
|
#Thin veneer for Configuring external resources
|
45
49
|
#
|
46
50
|
def configureMonitors
|
47
51
|
@monitors = ConfigureMonitor.new( self, @appResources ).getMonitors( ENV )
|
48
52
|
return self;
|
49
53
|
end
|
50
|
-
|
54
|
+
|
51
55
|
#Thin veneer for Configuring the Message Queue
|
52
56
|
#
|
53
57
|
def connectToMq
|
@@ -55,7 +59,7 @@ module RServiceBus
|
|
55
59
|
|
56
60
|
return self
|
57
61
|
end
|
58
|
-
|
62
|
+
|
59
63
|
#Subscriptions are specified by adding events to the
|
60
64
|
#msg endpoint mapping
|
61
65
|
def sendSubscriptions
|
@@ -77,11 +81,11 @@ module RServiceBus
|
|
77
81
|
def loadHandlers()
|
78
82
|
log "Load Message Handlers"
|
79
83
|
@handlerLoader = HandlerLoader.new( self, @appResources )
|
80
|
-
|
84
|
+
|
81
85
|
@config.handlerPathList.each do |path|
|
82
86
|
@handlerLoader.loadHandlersFromPath(path)
|
83
87
|
end
|
84
|
-
|
88
|
+
|
85
89
|
@handlerList = @handlerLoader.handlerList
|
86
90
|
@resourceByHandlerNameList = @handlerLoader.resourceList
|
87
91
|
|
@@ -92,7 +96,7 @@ module RServiceBus
|
|
92
96
|
#
|
93
97
|
def loadContracts()
|
94
98
|
log "Load Contracts"
|
95
|
-
|
99
|
+
|
96
100
|
@config.contractList.each do |path|
|
97
101
|
require path
|
98
102
|
log "Loaded Contract: #{path}", true
|
@@ -210,8 +214,10 @@ module RServiceBus
|
|
210
214
|
rescue Exception => e
|
211
215
|
sleep 0.5
|
212
216
|
|
217
|
+
puts "*** Excepton occured"
|
213
218
|
puts e.message
|
214
219
|
puts e.backtrace
|
220
|
+
puts "***"
|
215
221
|
|
216
222
|
tempHandlerList = Hash.new
|
217
223
|
tempResourceList = Hash.new
|
@@ -244,7 +250,7 @@ module RServiceBus
|
|
244
250
|
|
245
251
|
errorString = e.message + ". " + e.backtrace.join( ". " )
|
246
252
|
# log errorString
|
247
|
-
|
253
|
+
|
248
254
|
@msg.addErrorMsg( @config.localQueueName, errorString )
|
249
255
|
serialized_object = YAML::dump(@msg)
|
250
256
|
self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
|
@@ -293,15 +299,53 @@ module RServiceBus
|
|
293
299
|
|
294
300
|
else
|
295
301
|
log "Handler found for: " + msgName, true
|
302
|
+
log "Prep app resources", true
|
303
|
+
tempResourceList = Hash.new
|
296
304
|
handlerList.each do |handler|
|
297
|
-
|
298
|
-
handler.
|
299
|
-
|
300
|
-
|
301
|
-
#log e.message + ". " + e.backtrace[0]
|
302
|
-
raise e
|
305
|
+
if !@resourceByHandlerNameList[handler.class.name].nil? then
|
306
|
+
@resourceByHandlerNameList[handler.class.name].each do |resource|
|
307
|
+
tempResourceList[resource.class.name] = resource
|
308
|
+
end
|
303
309
|
end
|
304
310
|
end
|
311
|
+
begin
|
312
|
+
@queueForMsgsToBeSentOnComplete = Array.new
|
313
|
+
|
314
|
+
tempResourceList.each do |name, resource|
|
315
|
+
log "Prep resource, #{name}", true
|
316
|
+
resource.Begin
|
317
|
+
end
|
318
|
+
|
319
|
+
handlerList.each do |handler|
|
320
|
+
begin
|
321
|
+
handler.Handle( @msg.msg )
|
322
|
+
rescue Exception => e
|
323
|
+
log "An error occured in Handler: " + handler.class.name
|
324
|
+
raise e
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
tempResourceList.each do |name, resource|
|
329
|
+
log "Commit resource, #{name}", true
|
330
|
+
resource.Commit
|
331
|
+
end
|
332
|
+
|
333
|
+
self.sendQueuedMsgs
|
334
|
+
|
335
|
+
rescue Exception => e
|
336
|
+
|
337
|
+
tempResourceList.each do |name, resource|
|
338
|
+
log "Rollback resource, #{name}", true
|
339
|
+
begin
|
340
|
+
resource.Rollback
|
341
|
+
rescue Exception => e1
|
342
|
+
log "Nested exception rolling back, #{resource.class.name}, for msg, #{msgName}"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
@queueForMsgsToBeSentOnComplete = nil
|
346
|
+
|
347
|
+
raise e
|
348
|
+
end
|
305
349
|
end
|
306
350
|
end
|
307
351
|
|
@@ -315,7 +359,7 @@ module RServiceBus
|
|
315
359
|
if !@config.forwardSentMessagesTo.nil? then
|
316
360
|
@mq.send( @config.forwardSentMessagesTo, serialized_object )
|
317
361
|
end
|
318
|
-
|
362
|
+
|
319
363
|
@mq.send( queueName, serialized_object )
|
320
364
|
end
|
321
365
|
|
@@ -332,6 +376,16 @@ module RServiceBus
|
|
332
376
|
self._SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
333
377
|
end
|
334
378
|
|
379
|
+
def sendQueuedMsgs
|
380
|
+
@queueForMsgsToBeSentOnComplete.each do |row|
|
381
|
+
self._SendNeedsWrapping( row["msg"], row["queueName"] )
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def queueMsgForSendOnComplete( msg, queueName )
|
386
|
+
@queueForMsgsToBeSentOnComplete << Hash["msg", msg, "queueName", queueName]
|
387
|
+
end
|
388
|
+
|
335
389
|
#Sends a msg back across the bus
|
336
390
|
#Reply queues are specified in each msg. It works like
|
337
391
|
#email, where the reply address can actually be anywhere
|
@@ -341,7 +395,7 @@ module RServiceBus
|
|
341
395
|
log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
|
342
396
|
@stats.incTotalReply
|
343
397
|
|
344
|
-
self.
|
398
|
+
self.queueMsgForSendOnComplete( msg, @msg.returnAddress )
|
345
399
|
end
|
346
400
|
|
347
401
|
|
@@ -364,8 +418,7 @@ module RServiceBus
|
|
364
418
|
raise "No end point mapping found for: " + msgName
|
365
419
|
end
|
366
420
|
|
367
|
-
|
368
|
-
self._SendNeedsWrapping( msg, queueName )
|
421
|
+
self.queueMsgForSendOnComplete( msg, queueName )
|
369
422
|
end
|
370
423
|
|
371
424
|
#Sends an event to all subscribers across the bus
|
@@ -377,7 +430,7 @@ module RServiceBus
|
|
377
430
|
|
378
431
|
subscriptions = @subscriptionManager.get(msg.class.name)
|
379
432
|
subscriptions.each do |subscriber|
|
380
|
-
self.
|
433
|
+
self.queueMsgForSendOnComplete( msg, subscriber )
|
381
434
|
end
|
382
435
|
|
383
436
|
end
|
@@ -388,11 +441,9 @@ module RServiceBus
|
|
388
441
|
def Subscribe( eventName )
|
389
442
|
log "Bus.Subscribe: " + eventName, true
|
390
443
|
|
391
|
-
|
392
444
|
queueName = @config.messageEndpointMappings[eventName]
|
393
445
|
subscription = Message_Subscription.new( eventName )
|
394
446
|
|
395
|
-
|
396
447
|
self._SendNeedsWrapping( subscription, queueName )
|
397
448
|
end
|
398
449
|
|
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.55
|
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-04-
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|