rservicebus 0.0.22 → 0.0.23

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.
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "amqp"
4
3
  require "yaml"
5
4
 
5
+ require "beanstalk-client"
6
+
6
7
  require "rservicebus"
7
8
 
8
9
  host = 'localhost:11300'
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml"
4
+
5
+ require "bunny"
6
+
7
+ require "rservicebus"
8
+
9
+ host = 'localhost:11300'
10
+ errorQueueName = "error"
11
+
12
+ bunny = Bunny.new(:host=>host)
13
+ bunny.start
14
+ direct_exchange = @bunny.exchange('rservicebus.agent')
15
+
16
+ q = @bunny.queue(errorQueueName)
17
+
18
+ number_of_messages = 0
19
+ loop = true
20
+ while loop do
21
+ msg = q.pop[:payload]
22
+ if msg == :queue_empty then
23
+ loop = false
24
+ else
25
+ number_of_messages++
26
+
27
+ msg = YAML::load(msg)
28
+
29
+ queueName = msg.getLastErrorMsg.sourceQueue
30
+ sq = bunny.queue(queueName)
31
+ sq.bind(@direct_exchange)
32
+ #q.publish( serialized_object )
33
+
34
+ @direct_exchange.publish(msg)
35
+ end
36
+ end
37
+
38
+
39
+ if count == 0 then
40
+ puts "Nothing waiting on the error queue"
41
+ else
42
+
43
+ puts "Returned #{number_of_messages} to their source queue"
44
+
45
+ end
46
+
@@ -0,0 +1,20 @@
1
+ module RServiceBus
2
+
3
+ #A means for a stand-alone process to interact with the bus, without being a full
4
+ #rservicebus application
5
+ class Agent
6
+
7
+ def getAgent( uri )
8
+ if uri.scheme == "beanstalk" then
9
+ require "rservicebus/Agent/Beanstalk"
10
+ return Agent_Beanstalk.new()
11
+ elsif uri.scheme == "bunny" then
12
+ require "rservicebus/Agent/Bunny"
13
+ return Agent_Bunny.new()
14
+ else
15
+ raise StandardError.new( "Scheme not recognised" )
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,7 +5,7 @@ require 'bunny'
5
5
  #rservicebus application
6
6
  class Agent_Bunny
7
7
  @bunny
8
-
8
+
9
9
  def initialize(host='localhost')
10
10
  @bunny = Bunny.new(:host=>host)
11
11
  @bunny.start
@@ -20,7 +20,6 @@ class Agent_Bunny
20
20
  def sendMsg(messageObj, queueName, returnAddress=nil)
21
21
  msg = RServiceBus::Message.new( messageObj, returnAddress )
22
22
  serialized_object = YAML::dump(msg)
23
-
24
23
 
25
24
  q = @bunny.queue(queueName)
26
25
  q.bind(@direct_exchange)
@@ -39,4 +39,4 @@ module RServiceBus
39
39
  end
40
40
 
41
41
  end
42
- end
42
+ end
@@ -0,0 +1,141 @@
1
+ module RServiceBus
2
+
3
+ #Requirements for Saga.
4
+ #
5
+ #Technicalities
6
+ #correlation: how to tie two independant msgs together in a single saga
7
+ #
8
+ #Multiple messages - Any of which can start the saga
9
+ #Timeouts
10
+ #Persistent Data between calls
11
+ #Ability to "complete" a saga, but not compulsory to do so.
12
+
13
+
14
+ require "uri"
15
+
16
+
17
+ class Saga_Data_InMemory
18
+
19
+ attr_reader :data_hash
20
+
21
+ @data_hash
22
+
23
+ def initialize
24
+ @data_hash = Hash.new
25
+ end
26
+
27
+ def get( saga, msg, mapping )
28
+ @data_hash[saga.class.name] = Hash.new if @data_hash[saga.class.name].nil?
29
+ @data_hash[saga.class.name][msg.class.name] = Array.new if @data_hash[saga.class.name][msg.class.name].nil?
30
+
31
+ if !mapping[msg.class.name].nil? then
32
+ mapping[msg.class.name].each do |msgFieldName,sagaFieldName|
33
+
34
+ @data_hash[saga.class.name][msg.class.name].each do |data|
35
+ if !data[sagaFieldName].nil? then
36
+ return data if msg.instance_variable_get(msgFieldName) == data[sagaFieldName]
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ hash = Hash.new
43
+ @data_hash[saga.class.name][msg.class.name].push( hash )
44
+ return hash;
45
+ end
46
+
47
+ end
48
+
49
+ # Wrapper base class for resources used by applications, allowing rservicebus to configure the resource
50
+ # - dependency injection.
51
+ #
52
+ class Saga_Manager
53
+
54
+ #correlation strategy
55
+ # correlation strategy return an instance of the saga.
56
+ # that way, we can return an existing one, or create a new one
57
+
58
+ # Start with sagaid
59
+
60
+ # def Handle_MsgName( msg, data )
61
+
62
+ # end
63
+
64
+ def initialize
65
+ @sagas = Hash.new
66
+ @saga_data = Saga_Data_InMemory.new
67
+ end
68
+
69
+ def getMsgNames( sagaClass )
70
+ list = []
71
+ sagaClass.instance_methods.each do |name|
72
+ list.push name.to_s.sub( "Handle_", "" ) if name.to_s.slice( 0,7 ) == "Handle_"
73
+ end
74
+
75
+ return list
76
+ end
77
+
78
+ def addSaga( sagaClass )
79
+ saga = sagaClass.new
80
+ hash = Hash["saga", saga, "mapping", saga.mapping]
81
+ self.getMsgNames( sagaClass ).each do |name|
82
+ sagas[name] = Array.new if sagas[name].nil?
83
+ @sagas[name].push( hash )
84
+ end
85
+ end
86
+
87
+ def Handle( msg )
88
+ return if @sagas[msg.class.name].nil?
89
+
90
+ @sagas[msg.class.name].each do |hash|
91
+ saga = hash["saga"]
92
+
93
+ data = @saga_data.get( saga, msg, hash["mapping"] )
94
+
95
+ saga.data = data
96
+ saga.Handle( msg )
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+
103
+ class Saga
104
+ attr_accessor :data, :mapping
105
+ attr_reader :data
106
+
107
+ @data
108
+ @mapping
109
+
110
+ def initialize
111
+ @mapping = Hash.new
112
+ self.ConfigureHowToFindSaga
113
+ end
114
+
115
+ def ConfigureHowToFindSaga()
116
+ throw StandardError.new( "ConfigureHowToFindSaga needs to be implemented" );
117
+ end
118
+
119
+ def ConfigureMapping( msg, sagaFieldName, msgFieldName);
120
+ # if !msg.has_attribute?( msgFieldName ) then
121
+ # raise StandardError.new( "Msg, #{msg.name}, doesn't have a field named, #{msgFieldName}" )
122
+ #end
123
+ @mapping[msg.name] = Hash.new if @mapping[msg.name].nil?
124
+ @mapping[msg.name]["@" + msgFieldName] = sagaFieldName
125
+ end
126
+
127
+ def complete
128
+ end
129
+
130
+ def Handle( msg )
131
+ methodName = "Handle_#{msg.class.name}"
132
+
133
+ self.send methodName, msg
134
+ end
135
+ end
136
+
137
+ class Saga_Manager
138
+
139
+
140
+ end
141
+ end
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.22
4
+ version: 0.0.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,18 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby interpretation of NServiceBus
15
15
  email: guy@guyirvine.com
16
16
  executables:
17
17
  - rservicebus
18
- - ReturnErroredMessagesToSourceQueue
18
+ - ReturnErroredMessagesToSourceQueueBeanstalk
19
+ - ReturnErroredMessagesToSourceQueueBunny
19
20
  extensions: []
20
21
  extra_rdoc_files: []
21
22
  files:
22
23
  - lib/rservicebus/Agent/Beanstalk.rb
23
24
  - lib/rservicebus/Agent/Bunny.rb
25
+ - lib/rservicebus/Agent.rb
24
26
  - lib/rservicebus/AppResource/FluidDbMysql.rb
25
27
  - lib/rservicebus/AppResource/FluidDbMysql2.rb
26
28
  - lib/rservicebus/AppResource/FluidDbPgsql.rb
@@ -39,6 +41,7 @@ files:
39
41
  - lib/rservicebus/MQ/Beanstalk.rb
40
42
  - lib/rservicebus/MQ/Bunny.rb
41
43
  - lib/rservicebus/MQ.rb
44
+ - lib/rservicebus/Saga.rb
42
45
  - lib/rservicebus/Stats.rb
43
46
  - lib/rservicebus/SubscriptionManager.rb
44
47
  - lib/rservicebus/SubscriptionStorage/Redis.rb
@@ -47,7 +50,8 @@ files:
47
50
  - lib/rservicebus/Test/Redis.rb
48
51
  - lib/rservicebus/Test.rb
49
52
  - lib/rservicebus.rb
50
- - bin/ReturnErroredMessagesToSourceQueue
53
+ - bin/ReturnErroredMessagesToSourceQueueBeanstalk
54
+ - bin/ReturnErroredMessagesToSourceQueueBunny
51
55
  - bin/rservicebus
52
56
  - LICENSE
53
57
  - README.md