rservicebus 0.1.58 → 0.1.59
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rservicebus.rb +3 -0
- data/lib/rservicebus/AppResource/SmbDir.rb +1 -1
- data/lib/rservicebus/Host.rb +40 -24
- data/lib/rservicebus/Message.rb +4 -1
- data/lib/rservicebus/ResourceManager.rb +1 -1
- data/lib/rservicebus/Saga/Manager.rb +2 -1
- data/lib/rservicebus/SendAtManager.rb +42 -0
- data/lib/rservicebus/SendAtStorage.rb +24 -0
- data/lib/rservicebus/SendAtStorage/File.rb +46 -0
- data/lib/rservicebus/SendAtStorage/InMemory.rb +26 -0
- metadata +16 -12
data/lib/rservicebus.rb
CHANGED
data/lib/rservicebus/Host.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module RServiceBus
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
|
4
4
|
class NoHandlerFound<StandardError
|
5
5
|
end
|
6
6
|
class ClassNotFoundForMsg<StandardError
|
@@ -9,7 +9,7 @@ module RServiceBus
|
|
9
9
|
end
|
10
10
|
class PropertyNotSet<StandardError
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
#Host process for rservicebus
|
14
14
|
class Host
|
15
15
|
attr_accessor :sagaData
|
@@ -42,7 +42,7 @@ module RServiceBus
|
|
42
42
|
def log(string, ver=false)
|
43
43
|
RServiceBus.log( string, ver )
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
#Thin veneer for Configuring external resources
|
47
47
|
#
|
48
48
|
def configureAppResource
|
@@ -50,6 +50,14 @@ module RServiceBus
|
|
50
50
|
return self;
|
51
51
|
end
|
52
52
|
|
53
|
+
|
54
|
+
#Thin veneer for Configuring SendAt
|
55
|
+
#
|
56
|
+
def configureSendAtManager
|
57
|
+
@sendAtManager = SendAtManager.new( self )
|
58
|
+
return self;
|
59
|
+
end
|
60
|
+
|
53
61
|
#Thin veneer for Configuring state
|
54
62
|
#
|
55
63
|
def configureStateManager
|
@@ -64,12 +72,12 @@ module RServiceBus
|
|
64
72
|
if string.nil? then
|
65
73
|
string = "dir:///tmp"
|
66
74
|
end
|
67
|
-
|
75
|
+
|
68
76
|
uri = URI.parse( string )
|
69
77
|
@sagaStorage = SagaStorage.Get( uri )
|
70
78
|
return self;
|
71
79
|
end
|
72
|
-
|
80
|
+
|
73
81
|
#Thin veneer for Configuring Cron
|
74
82
|
#
|
75
83
|
def configureCircuitBreaker
|
@@ -92,7 +100,7 @@ module RServiceBus
|
|
92
100
|
|
93
101
|
return self
|
94
102
|
end
|
95
|
-
|
103
|
+
|
96
104
|
#Subscriptions are specified by adding events to the
|
97
105
|
#msg endpoint mapping
|
98
106
|
def sendSubscriptions
|
@@ -195,6 +203,7 @@ module RServiceBus
|
|
195
203
|
self.configureStatistics()
|
196
204
|
.loadContracts()
|
197
205
|
.loadLibs()
|
206
|
+
.configureSendAtManager()
|
198
207
|
.configureStateManager()
|
199
208
|
.configureSagaStorage()
|
200
209
|
.configureAppResource()
|
@@ -355,8 +364,11 @@ module RServiceBus
|
|
355
364
|
@cronManager.Run
|
356
365
|
self.sendQueuedMsgs
|
357
366
|
@queueForMsgsToBeSentOnComplete = nil
|
358
|
-
|
359
|
-
|
367
|
+
|
368
|
+
|
369
|
+
@sendAtManager.Process
|
370
|
+
|
371
|
+
|
360
372
|
@circuitBreaker.Success
|
361
373
|
|
362
374
|
rescue Exception => e
|
@@ -401,8 +413,8 @@ module RServiceBus
|
|
401
413
|
end
|
402
414
|
|
403
415
|
|
404
|
-
if @sagaManager.Handle( @msg ) == false then
|
405
|
-
raise NoHandlerFound.new( msgName )
|
416
|
+
if @sagaManager.Handle( @msg ) == false && handlerList.length == 0 then
|
417
|
+
raise NoHandlerFound.new( msgName )
|
406
418
|
end
|
407
419
|
|
408
420
|
|
@@ -437,14 +449,14 @@ module RServiceBus
|
|
437
449
|
|
438
450
|
@mq.send( queueName, serialized_object )
|
439
451
|
end
|
440
|
-
|
452
|
+
|
441
453
|
#Sends a msg across the bus
|
442
454
|
#
|
443
455
|
# @param [RServiceBus::Message] msg msg to be sent
|
444
456
|
# @param [String] queueName endpoint to which the msg will be sent
|
445
457
|
def _SendNeedsWrapping( msg, queueName, correlationId )
|
446
458
|
RServiceBus.rlog "Bus._SendNeedsWrapping"
|
447
|
-
|
459
|
+
|
448
460
|
rMsg = RServiceBus::Message.new( msg, @mq.localQueueName, correlationId )
|
449
461
|
if queueName.index( "@" ).nil? then
|
450
462
|
q = queueName
|
@@ -460,19 +472,23 @@ module RServiceBus
|
|
460
472
|
serialized_object = YAML::dump(rMsg)
|
461
473
|
self._SendAlreadyWrappedAndSerialised( serialized_object, q )
|
462
474
|
end
|
463
|
-
|
475
|
+
|
464
476
|
def sendQueuedMsgs
|
465
477
|
@queueForMsgsToBeSentOnComplete.each do |row|
|
466
|
-
|
478
|
+
if row['timestamp'].nil? then
|
479
|
+
self._SendNeedsWrapping( row["msg"], row["queueName"], row["correlationId"] )
|
480
|
+
else
|
481
|
+
@sendAtManager.Add( row )
|
482
|
+
end
|
467
483
|
end
|
468
484
|
end
|
469
|
-
|
470
|
-
def queueMsgForSendOnComplete( msg, queueName )
|
485
|
+
|
486
|
+
def queueMsgForSendOnComplete( msg, queueName, timestamp=nil )
|
471
487
|
correlationId = sagaData.nil? ? nil : sagaData.correlationId
|
472
488
|
correlationId = @msg.correlationId.nil? ? correlationId : @msg.correlationId
|
473
|
-
@queueForMsgsToBeSentOnComplete << Hash["msg", msg, "queueName", queueName, "correlationId", correlationId]
|
489
|
+
@queueForMsgsToBeSentOnComplete << Hash["msg", msg, "queueName", queueName, "correlationId", correlationId, "timestamp",timestamp ]
|
474
490
|
end
|
475
|
-
|
491
|
+
|
476
492
|
#Sends a msg back across the bus
|
477
493
|
#Reply queues are specified in each msg. It works like
|
478
494
|
#email, where the reply address can actually be anywhere
|
@@ -501,16 +517,16 @@ module RServiceBus
|
|
501
517
|
#msg destination is specified at the infrastructure level
|
502
518
|
#
|
503
519
|
# @param [RServiceBus::Message] msg msg to be sent
|
504
|
-
def Send( msg )
|
520
|
+
def Send( msg, timestamp=nil )
|
505
521
|
RServiceBus.rlog "Bus.Send"
|
506
522
|
@stats.incTotalSent
|
507
|
-
|
523
|
+
|
508
524
|
msgName = msg.class.name
|
509
525
|
queueName = self.getEndpointForMsg( msgName )
|
510
526
|
|
511
|
-
self.queueMsgForSendOnComplete( msg, queueName )
|
527
|
+
self.queueMsgForSendOnComplete( msg, queueName, timestamp )
|
512
528
|
end
|
513
|
-
|
529
|
+
|
514
530
|
#Sends an event to all subscribers across the bus
|
515
531
|
#
|
516
532
|
# @param [RServiceBus::Message] msg msg to be sent
|
@@ -524,7 +540,7 @@ module RServiceBus
|
|
524
540
|
end
|
525
541
|
|
526
542
|
end
|
527
|
-
|
543
|
+
|
528
544
|
#Sends a subscription request across the Bus
|
529
545
|
#
|
530
546
|
# @param [String] eventName event to be subscribes to
|
data/lib/rservicebus/Message.rb
CHANGED
@@ -7,7 +7,7 @@ module RServiceBus
|
|
7
7
|
#This is the top level message that is passed around the bus
|
8
8
|
class Message
|
9
9
|
|
10
|
-
attr_reader :returnAddress, :msgId, :remoteQueueName, :remoteHostName, :lastErrorSourceQueue, :lastErrorString, :correlationId
|
10
|
+
attr_reader :returnAddress, :msgId, :remoteQueueName, :remoteHostName, :lastErrorSourceQueue, :lastErrorString, :correlationId, :sendAt
|
11
11
|
|
12
12
|
# Constructor
|
13
13
|
#
|
@@ -54,6 +54,9 @@ module RServiceBus
|
|
54
54
|
@remoteQueueName = queueName
|
55
55
|
end
|
56
56
|
|
57
|
+
def sendAt( timestamp )
|
58
|
+
@sendAt = timestamp
|
59
|
+
end
|
57
60
|
|
58
61
|
# @return [Object] The msg to be sent
|
59
62
|
def msg
|
@@ -31,7 +31,7 @@ module RServiceBus
|
|
31
31
|
r = @appResources[name]
|
32
32
|
r._connect
|
33
33
|
r.Begin
|
34
|
-
RServiceBus.rlog "Preparing resource: #{
|
34
|
+
RServiceBus.rlog "Preparing resource: #{name}. Begin"
|
35
35
|
end
|
36
36
|
@currentResources[name] = @appResources[name]
|
37
37
|
return @appResources[name]
|
@@ -2,7 +2,7 @@ module RServiceBus
|
|
2
2
|
|
3
3
|
|
4
4
|
class Saga_Manager
|
5
|
-
|
5
|
+
|
6
6
|
def initialize( host, resourceManager, sagaStorage )
|
7
7
|
@handler = Hash.new
|
8
8
|
@startWith = Hash.new
|
@@ -103,6 +103,7 @@ class Saga_Manager
|
|
103
103
|
return handled if handled == true
|
104
104
|
|
105
105
|
|
106
|
+
return false if rmsg.correlationId.nil?
|
106
107
|
data = @sagaStorage.Get( rmsg.correlationId )
|
107
108
|
return handled if data.nil?
|
108
109
|
methodName = "Handle_#{msg.class.name}"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
require 'rservicebus/SendAtStorage'
|
4
|
+
|
5
|
+
class SendAtManager
|
6
|
+
|
7
|
+
|
8
|
+
def initialize( bus )
|
9
|
+
#Check if the SendAt Dir has been specified
|
10
|
+
#If it has, make sure it exists, and is writable
|
11
|
+
|
12
|
+
string = RServiceBus.getValue( "SENDAT_URI" )
|
13
|
+
if string.nil? then
|
14
|
+
string = "file:///tmp/rservicebus-sendat"
|
15
|
+
end
|
16
|
+
|
17
|
+
uri = URI.parse( string )
|
18
|
+
@SendAtStorage = SendAtStorage.Get( uri )
|
19
|
+
|
20
|
+
@Bus = bus
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def Process
|
25
|
+
now = DateTime.now
|
26
|
+
@SendAtStorage.GetAll.each_with_index do |row,idx|
|
27
|
+
if row["timestamp"] > now then
|
28
|
+
@Bus._SendNeedsWrapping( row["msg"], row["queueName"], row["correlationId"] )
|
29
|
+
@SendAtStorage.Delete( idx )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def Add( row )
|
35
|
+
@SendAtStorage.Add( row )
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
require "rservicebus/SendAtStorage"
|
4
|
+
|
5
|
+
class SendAtStorage
|
6
|
+
|
7
|
+
def SendAtStorage.Get( uri )
|
8
|
+
case uri.scheme
|
9
|
+
when "file"
|
10
|
+
require "rservicebus/SendAtStorage/File"
|
11
|
+
return SendAtStorage_File.new( uri )
|
12
|
+
when "inmem"
|
13
|
+
require "rservicebus/SendAtStorage/InMemory"
|
14
|
+
return SendAtStorage_InMemory.new( uri )
|
15
|
+
else
|
16
|
+
abort("Scheme, #{uri.scheme}, not recognised when configuring SendAtStorage, #{uri.to_s}");
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
class SendAtStorage_File
|
4
|
+
|
5
|
+
def initialize( uri )
|
6
|
+
@list = self.load( uri.path )
|
7
|
+
end
|
8
|
+
def load( path )
|
9
|
+
return Array.new if !File.exists?( path )
|
10
|
+
|
11
|
+
content = IO.read( path )
|
12
|
+
|
13
|
+
return Array.new if content == ""
|
14
|
+
|
15
|
+
return YAML::load( content )
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#Add
|
20
|
+
def Add( msg )
|
21
|
+
@list << msg
|
22
|
+
self.Save
|
23
|
+
end
|
24
|
+
|
25
|
+
#GetAll
|
26
|
+
def GetAll
|
27
|
+
return @list
|
28
|
+
end
|
29
|
+
|
30
|
+
#Delete
|
31
|
+
def Delete( idx )
|
32
|
+
@list.delete_at( idx )
|
33
|
+
self.Save
|
34
|
+
end
|
35
|
+
|
36
|
+
#Finish
|
37
|
+
def Save
|
38
|
+
content = YAML::dump( @list )
|
39
|
+
IO.write( @uri.path, content )
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
|
3
|
+
class SendAtStorage_File
|
4
|
+
|
5
|
+
def initialize( uri )
|
6
|
+
@list = Array.new
|
7
|
+
end
|
8
|
+
|
9
|
+
#Add
|
10
|
+
def Add( msg )
|
11
|
+
@list << msg
|
12
|
+
end
|
13
|
+
|
14
|
+
#GetAll
|
15
|
+
def GetAll
|
16
|
+
return @list
|
17
|
+
end
|
18
|
+
|
19
|
+
#Delete
|
20
|
+
def Delete( idx )
|
21
|
+
@list.delete_at( idx )
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
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.1.
|
4
|
+
version: 0.1.59
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uuidtools
|
16
|
-
requirement: &
|
16
|
+
requirement: &70127104314700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70127104314700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70127104313880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70127104313880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: beanstalk-client
|
38
|
-
requirement: &
|
38
|
+
requirement: &70127104309180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70127104309180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fluiddb
|
49
|
-
requirement: &
|
49
|
+
requirement: &70127104307000 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70127104307000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: parse-cron
|
60
|
-
requirement: &
|
60
|
+
requirement: &70127104304900 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70127104304900
|
69
69
|
description: A Ruby interpretation of NServiceBus
|
70
70
|
email: guy@guyirvine.com
|
71
71
|
executables:
|
@@ -129,6 +129,10 @@ files:
|
|
129
129
|
- lib/rservicebus/SagaStorage/Dir.rb
|
130
130
|
- lib/rservicebus/SagaStorage/InMemory.rb
|
131
131
|
- lib/rservicebus/SagaStorage.rb
|
132
|
+
- lib/rservicebus/SendAtManager.rb
|
133
|
+
- lib/rservicebus/SendAtStorage/File.rb
|
134
|
+
- lib/rservicebus/SendAtStorage/InMemory.rb
|
135
|
+
- lib/rservicebus/SendAtStorage.rb
|
132
136
|
- lib/rservicebus/StateManager.rb
|
133
137
|
- lib/rservicebus/StateStorage/Dir.rb
|
134
138
|
- lib/rservicebus/StateStorage.rb
|