rservicebus 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,42 @@
1
1
  module RServiceBus
2
-
3
- require "uri"
4
-
5
- # Wrapper base class for resources used by applications, allowing rservicebus to configure the resource
6
- # - dependency injection.
7
- #
8
- class AppResource
9
- @uri
10
-
11
- # Resources are attached resources, and can be specified using the URI syntax.
12
- #
13
- # @param [String] uri a location for the resource to which we will attach, eg redis://127.0.0.1/foo
14
- def initialize( uri )
15
- @uri = uri
16
- end
17
-
18
- # The method which actually configures the resource.
19
- #
20
- # @return [Object] the configured object.
21
- def getResource
22
- raise "Method, getResource, needs to be implemented for resource"
23
- end
24
- end
25
-
2
+
3
+ require "uri"
4
+
5
+ # Wrapper base class for resources used by applications, allowing rservicebus to configure the resource
6
+ # - dependency injection.
7
+ #
8
+ class AppResource
9
+ @uri
10
+
11
+ # Resources are attached resources, and can be specified using the URI syntax.
12
+ #
13
+ # @param [String] uri a location for the resource to which we will attach, eg redis://127.0.0.1/foo
14
+ def initialize( uri )
15
+ @uri = uri
16
+ end
17
+
18
+ # The method which actually configures the resource.
19
+ #
20
+ # @return [Object] the configured object.
21
+ def getResource
22
+ raise "Method, getResource, needs to be implemented for resource"
23
+ end
24
+
25
+ # A notification that ocurs after getResource, to allow cleanup
26
+ def finished
27
+ raise "Method, getResource, needs to be implemented for resource"
28
+ end
29
+
30
+ # At least called in the Host rescue block, to ensure all network links are healthy
31
+ def reconnect
32
+ begin
33
+ @connection.close
34
+ rescue
35
+ puts "AppResource. An error was raised while closing connection to, " + @uri.to_s
36
+ end
37
+
38
+ self.connect
39
+ end
40
+
41
+ end
26
42
  end
@@ -1,12 +1,12 @@
1
1
  module RServiceBus
2
2
 
3
3
  require "FluidDb/Mysql"
4
-
4
+
5
5
  #Implementation of an AppResource - Redis
6
6
  class AppResource_FluidDbMysql<AppResource
7
7
 
8
8
  @connection
9
-
9
+
10
10
  def initialize( uri )
11
11
  super(uri)
12
12
  host = uri.host
@@ -16,7 +16,7 @@ module RServiceBus
16
16
  @connection = FluidDb::Mysql.new( uri )
17
17
  puts "AppResource_Mysql. Connected to, " + uri.to_s
18
18
  end
19
-
19
+
20
20
  def getResource
21
21
  return @connection
22
22
  end
@@ -6,23 +6,30 @@ module RServiceBus
6
6
  class AppResource_Mysql<AppResource
7
7
 
8
8
  @connection
9
-
10
- def initialize( uri )
11
- super(uri)
9
+
10
+ def connect()
11
+ uri = self.uri
12
12
  host = uri.host
13
13
  database = uri.path.sub( "/", "" )
14
-
15
-
14
+
15
+
16
16
  @connection = Mysql2::Client.new(:host => uri.host,
17
- :database => uri.path.sub( "/", "" ),
18
- :username => uri.user )
17
+ :database => uri.path.sub( "/", "" ),
18
+ :username => uri.user )
19
19
  puts "AppResource_Mysql. Connected to, " + uri.to_s
20
20
  end
21
21
 
22
+ def initialize( uri )
23
+ super(uri)
24
+ self.connect
25
+ end
26
+
22
27
  def getResource
23
28
  return @connection
24
29
  end
25
-
30
+
26
31
  end
27
32
 
28
33
  end
34
+
35
+ end
@@ -21,6 +21,7 @@ class HandlerLoader
21
21
  @handler
22
22
 
23
23
  @handlerList
24
+ @resourceList
24
25
 
25
26
  # Constructor
26
27
  #
@@ -31,6 +32,7 @@ class HandlerLoader
31
32
  @appResources = appResources
32
33
 
33
34
  @handlerList = Hash.new
35
+ @resourceList = Hash.new
34
36
  end
35
37
 
36
38
  # Cleans the given path to ensure it can be used for as a parameter for the require statement.
@@ -93,6 +95,8 @@ class HandlerLoader
93
95
  appResources.each do |k,v|
94
96
  if handler.class.method_defined?( k ) then
95
97
  handler.instance_variable_set( "@#{k}", v.getResource() )
98
+ @resourceList[handler.class.name] = Array.new if @resourceList[handler.class.name].nil?
99
+ @resourceList[handler.class.name] << v.getResource()
96
100
  @host.log "App resource attribute, #{k}, set for: " + handler.class.name
97
101
  end
98
102
  end
@@ -1,129 +1,130 @@
1
1
  module RServiceBus
2
-
3
- #Host process for rservicebus
4
- class Host
5
-
6
- @handlerList
7
-
8
- @forwardReceivedMessagesToQueue
9
-
10
- @subscriptions
11
-
12
- @beanstalk
13
-
14
- @appResources
15
-
16
- @config
17
-
18
- @subscriptionManager
19
-
20
- @stats
21
-
22
- def log(string, ver=false)
23
- type = ver ? "VERB" : "INFO"
24
- if @config.verbose || !ver then
25
- timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
26
- puts "[#{type}] #{timestamp} :: #{string}"
27
- end
28
- end
29
-
30
- def configureAppResource
31
- @appResources = ConfigureAppResource.new.getResources( ENV )
32
- return self;
33
- end
34
-
35
- def connectToBeanstalk
36
- begin
37
- @beanstalk = Beanstalk::Pool.new([@config.beanstalkHost])
38
- rescue Exception => e
39
- puts "Error connecting to Beanstalk"
40
- puts "Host string, #{@config.beanstalkHost}"
41
- if e.message == "Beanstalk::NotConnected" then
42
- puts "***Most likely, beanstalk is not running. Start beanstalk, and try running this again."
43
- puts "***If you still get this error, check beanstalk is running at, " + @config.beanstalkHost
44
- else
45
- puts e.message
46
- puts e.backtrace
47
- end
48
- abort()
49
- end
50
-
51
- return self
52
- end
53
-
54
- #Subscriptions are specified by adding events to the
55
- #msg endpoint mapping
56
- def sendSubscriptions
57
- log "Send Subscriptions"
58
- @config.messageEndpointMappings.each do |eventName,queueName|
59
- log "Checking, " + eventName + " for Event", true
60
- if eventName.end_with?( "Event" ) then
61
- log eventName + ", is an event. About to send subscription to, " + queueName, true
62
- self.Subscribe( eventName )
63
- log "Subscribed to, " + eventName + " at, " + queueName
64
- end
65
- end
66
-
67
- return self
68
- end
69
-
70
- def loadHandlers()
71
- log "Load Message Handlers"
72
- handlerLoader = HandlerLoader.new( self, @appResources )
73
-
74
- @config.handlerPathList.each do |path|
75
- handlerLoader.loadHandlersFromPath(path)
76
- end
77
-
78
- @handlerList = handlerLoader.handlerList
79
-
80
- return self
81
- end
82
-
83
2
 
84
- def loadContracts()
85
- log "Load Contracts"
3
+ #Host process for rservicebus
4
+ class Host
86
5
 
87
- @config.contractList.each do |path|
88
- require path
89
- end
6
+ @handlerList
7
+ @resourceByHandlerNameList
90
8
 
91
- return self
92
- end
93
-
94
- def loadLibs()
95
- log "Load Libs"
9
+ @forwardReceivedMessagesToQueue
96
10
 
97
- @config.libList.each do |path|
98
- if Dir.exists?( path ) then
99
- path = path.strip.chomp( "/" )
100
- path = path + "/**/*.rb"
11
+ @subscriptions
12
+
13
+ @beanstalk
14
+
15
+ @appResources
16
+
17
+ @config
18
+
19
+ @subscriptionManager
20
+
21
+ @stats
22
+
23
+ def log(string, ver=false)
24
+ type = ver ? "VERB" : "INFO"
25
+ if @config.verbose || !ver then
26
+ timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
27
+ puts "[#{type}] #{timestamp} :: #{string}"
28
+ end
29
+ end
30
+
31
+ def configureAppResource
32
+ @appResources = ConfigureAppResource.new.getResources( ENV )
33
+ return self;
34
+ end
35
+
36
+ def connectToBeanstalk
37
+ begin
38
+ @beanstalk = Beanstalk::Pool.new([@config.beanstalkHost])
39
+ rescue Exception => e
40
+ puts "Error connecting to Beanstalk"
41
+ puts "Host string, #{@config.beanstalkHost}"
42
+ if e.message == "Beanstalk::NotConnected" then
43
+ puts "***Most likely, beanstalk is not running. Start beanstalk, and try running this again."
44
+ puts "***If you still get this error, check beanstalk is running at, " + @config.beanstalkHost
45
+ else
46
+ puts e.message
47
+ puts e.backtrace
48
+ end
49
+ abort()
101
50
  end
102
- Dir.glob( path ).each do |path|
51
+
52
+ return self
53
+ end
54
+
55
+ #Subscriptions are specified by adding events to the
56
+ #msg endpoint mapping
57
+ def sendSubscriptions
58
+ log "Send Subscriptions"
59
+ @config.messageEndpointMappings.each do |eventName,queueName|
60
+ log "Checking, " + eventName + " for Event", true
61
+ if eventName.end_with?( "Event" ) then
62
+ log eventName + ", is an event. About to send subscription to, " + queueName, true
63
+ self.Subscribe( eventName )
64
+ log "Subscribed to, " + eventName + " at, " + queueName
65
+ end
66
+ end
67
+
68
+ return self
69
+ end
70
+
71
+ def loadHandlers()
72
+ log "Load Message Handlers"
73
+ handlerLoader = HandlerLoader.new( self, @appResources )
74
+
75
+ @config.handlerPathList.each do |path|
76
+ handlerLoader.loadHandlersFromPath(path)
77
+ end
78
+
79
+ @handlerList = handlerLoader.handlerList
80
+
81
+ return self
82
+ end
83
+
84
+
85
+ def loadContracts()
86
+ log "Load Contracts"
87
+
88
+ @config.contractList.each do |path|
103
89
  require path
104
90
  end
105
- end
91
+
92
+ return self
93
+ end
94
+
95
+ def loadLibs()
96
+ log "Load Libs"
97
+
98
+ @config.libList.each do |path|
99
+ if Dir.exists?( path ) then
100
+ path = path.strip.chomp( "/" )
101
+ path = path + "/**/*.rb"
102
+ end
103
+ Dir.glob( path ).each do |path|
104
+ require path
105
+ end
106
+ end
107
+
108
+ return self
109
+ end
106
110
 
107
- return self
108
- end
109
-
110
- def configureSubscriptions
111
- subscriptionStorage = SubscriptionStorage_Redis.new( @config.appName, "uri" )
112
- @subscriptionManager = SubscriptionManager.new( subscriptionStorage )
113
-
114
- return self
115
- end
116
-
117
- def configureStatistics
118
- @stats = Stats.new
119
-
120
- return self
121
- end
122
-
123
-
124
- def initialize()
125
-
126
- @config = ConfigFromEnv.new
111
+ def configureSubscriptions
112
+ subscriptionStorage = SubscriptionStorage_Redis.new( @config.appName, "uri" )
113
+ @subscriptionManager = SubscriptionManager.new( subscriptionStorage )
114
+
115
+ return self
116
+ end
117
+
118
+ def configureStatistics
119
+ @stats = Stats.new
120
+
121
+ return self
122
+ end
123
+
124
+
125
+ def initialize()
126
+
127
+ @config = ConfigFromEnv.new
127
128
  .configureLogging()
128
129
  .loadHostSection()
129
130
  .configureBeanstalk()
@@ -132,8 +133,8 @@ class Host
132
133
  .loadHandlerPathList()
133
134
  .loadLibs()
134
135
  .loadWorkingDirList();
135
-
136
- self.configureStatistics()
136
+
137
+ self.configureStatistics()
137
138
  .configureAppResource()
138
139
  .connectToBeanstalk()
139
140
  .loadHandlers()
@@ -141,212 +142,221 @@ class Host
141
142
  .loadLibs()
142
143
  .configureSubscriptions()
143
144
  .sendSubscriptions()
144
-
145
- return self
146
- end
147
-
148
- def run
149
- log "Starting the Host"
150
-
151
- log "Watching, " + @config.localQueueName
152
- @beanstalk.watch( @config.localQueueName )
153
- if !@config.forwardReceivedMessagesTo.nil? then
154
- log "Forwarding all received messages to: " + @config.forwardReceivedMessagesTo.to_s
155
- end
156
-
157
- self.StartListeningToEndpoints
158
- end
159
-
160
- #Receive a msg, prep it, and handle any errors that may occur
161
- # - Most of this should be queue independant
162
- def StartListeningToEndpoints
163
- log "Waiting for messages. To exit press CTRL+C"
164
- statOutputCountdown = 0
165
- messageLoop = true
166
-
167
- while messageLoop do
168
- retries = @config.maxRetries
169
- #Popping a msg off the queue should not be in the message handler, as it affects retry
170
- begin
171
- if statOutputCountdown == 0 then
172
- log @stats.getForReporting
173
- statOutputCountdown = @config.statOutputCountdown-1
174
- else
175
- statOutputCountdown = statOutputCountdown - 1
176
- end
177
- job = @beanstalk.reserve @config.queueTimeout
178
- begin
179
- body = job.body
180
- @stats.incTotalProcessed
181
- @msg = YAML::load(body)
182
- if @msg.msg.class.name == "RServiceBus::Message_Subscription" then
183
- @subscriptionManager.add( @msg.msg.eventName, @msg.returnAddress )
184
-
185
- else
186
- self.HandleMessage()
187
- if !@config.forwardReceivedMessagesTo.nil? then
188
- self._SendAlreadyWrappedAndSerialised(body,@config.forwardReceivedMessagesTo)
189
- end
190
- end
191
- job.delete
192
- rescue Exception => e
193
- sleep 0.5
194
- retry if (retries -= 1) > 0
195
-
196
- @stats.incTotalErrored
197
- if e.class.name == "Beanstalk::NotConnected" then
198
- puts "Lost connection to beanstalkd."
199
- puts "*** Start or Restart beanstalkd and try again."
200
- abort();
201
- end
202
-
203
- if e.class.name == "Redis::CannotConnectError" then
204
- puts "Lost connection to redis."
205
- puts "*** Start or Restart redis and try again."
206
- abort();
207
- end
208
-
209
- errorString = e.message + ". " + e.backtrace[0]
210
- if e.backtrace.length > 1 then
211
- errorString = errorString + ". " + e.backtrace[1]
212
- end
213
- if e.backtrace.length > 2 then
214
- errorString = errorString + ". " + e.backtrace[2]
215
- end
216
- log errorString
217
-
218
- @msg.addErrorMsg( @config.localQueueName, errorString )
219
- serialized_object = YAML::dump(@msg)
220
- self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
221
- job.delete
222
- end
223
- rescue SystemExit, Interrupt
224
- puts "Exiting on request ..."
225
- messageLoop = false
226
- rescue Exception => e
227
- if e.message == "TIMED_OUT" then
228
- #This exception is just saying there are no messages to process
229
- statOutputCountdown = 0
230
- elsif e.message == "SIGTERM" then
231
- puts "Exiting on request ..."
232
- messageLoop = false
233
- else
234
- puts "*** This is really unexpected."
235
- messageLoop = false
236
- puts "Message: " + e.message
237
- puts e.backtrace
238
- end
239
- end
240
- end
241
- end
242
-
243
- #Send the current msg to the appropriate handlers
244
- def HandleMessage()
245
- msgName = @msg.msg.class.name
246
- handlerList = @handlerList[msgName]
247
-
248
- if handlerList == nil then
249
- log "No handler found for: " + msgName
250
- raise "No Handler Found"
251
- else
252
- log "Handler found for: " + msgName, true
253
- handlerList.each do |handler|
254
- begin
255
- handler.Handle( @msg.msg )
256
- rescue Exception => e
257
- log "An error occured in Handler: " + handler.class.name
258
- log e.message + ". " + e.backtrace[0]
259
- raise e
260
- end
261
- end
262
- 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
-
272
- @beanstalk.use( queueName )
273
- @beanstalk.put( serialized_object )
274
- end
275
-
276
- #Sends a msg across the bus
277
- #
278
- # @param [RServiceBus::Message] msg msg to be sent
279
- # @param [String] queueName endpoint to which the msg will be sent
280
- def _SendNeedsWrapping( msg, queueName )
281
- log "Bus._SendNeedsWrapping", true
282
-
283
- rMsg = RServiceBus::Message.new( msg, @config.localQueueName )
284
- serialized_object = YAML::dump(rMsg)
285
- log "Sending: " + msg.class.name + " to: " + queueName, true
286
- self._SendAlreadyWrappedAndSerialised( serialized_object, queueName )
287
- end
288
-
289
- #Sends a msg back across the bus
290
- #Reply queues are specified in each msg. It works like
291
- #email, where the reply address can actually be anywhere
292
- #
293
- # @param [RServiceBus::Message] msg msg to be sent
294
- def Reply( msg )
295
- log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
296
- @stats.incTotalReply
297
-
298
- self._SendNeedsWrapping( msg, @msg.returnAddress )
299
- end
300
-
301
-
302
- #Send a msg across the bus
303
- #msg destination is specified at the infrastructure level
304
- #
305
- # @param [RServiceBus::Message] msg msg to be sent
306
- def Send( msg )
307
- log "Bus.Send", true
308
- @stats.incTotalSent
309
-
310
- msgName = msg.class.name
311
- if !@config.messageEndpointMappings.has_key?( msgName ) then
312
- log "No end point mapping found for: " + msgName
313
- log "**** Check in RServiceBus.yml that the section MessageEndpointMappings contains an entry named : " + msgName
314
- raise "No end point mapping found for: " + msgName
315
- end
316
-
317
- queueName = @config.messageEndpointMappings[msgName]
318
-
319
- self._SendNeedsWrapping( msg, queueName )
320
- end
321
-
322
- #Sends an event to all subscribers across the bus
323
- #
324
- # @param [RServiceBus::Message] msg msg to be sent
325
- def Publish( msg )
326
- log "Bus.Publish", true
327
- @stats.incTotalPublished
328
-
329
- subscriptions = @subscriptionManager.get(msg.class.name)
330
- subscriptions.each do |subscriber|
331
- self._SendNeedsWrapping( msg, subscriber )
332
- end
333
-
334
- end
335
-
336
- #Sends a subscription request across the Bus
337
- #
338
- # @param [String] eventName event to be subscribes to
339
- def Subscribe( eventName )
340
- log "Bus.Subscribe: " + eventName, true
341
-
342
-
343
- queueName = @config.messageEndpointMappings[eventName]
344
- subscription = Message_Subscription.new( eventName )
345
-
346
-
347
- self._SendNeedsWrapping( subscription, queueName )
348
- end
349
-
350
- end
351
-
352
- end
145
+
146
+ return self
147
+ end
148
+
149
+ def run
150
+ log "Starting the Host"
151
+
152
+ log "Watching, " + @config.localQueueName
153
+ @beanstalk.watch( @config.localQueueName )
154
+ if !@config.forwardReceivedMessagesTo.nil? then
155
+ log "Forwarding all received messages to: " + @config.forwardReceivedMessagesTo.to_s
156
+ end
157
+
158
+ self.StartListeningToEndpoints
159
+ end
160
+
161
+ #Receive a msg, prep it, and handle any errors that may occur
162
+ # - Most of this should be queue independant
163
+ def StartListeningToEndpoints
164
+ log "Waiting for messages. To exit press CTRL+C"
165
+ statOutputCountdown = 0
166
+ messageLoop = true
167
+
168
+ while messageLoop do
169
+ retries = @config.maxRetries
170
+ #Popping a msg off the queue should not be in the message handler, as it affects retry
171
+ begin
172
+ if statOutputCountdown == 0 then
173
+ log @stats.getForReporting
174
+ statOutputCountdown = @config.statOutputCountdown-1
175
+ else
176
+ statOutputCountdown = statOutputCountdown - 1
177
+ end
178
+ job = @beanstalk.reserve @config.queueTimeout
179
+ begin
180
+ body = job.body
181
+ @stats.incTotalProcessed
182
+ @msg = YAML::load(body)
183
+ if @msg.msg.class.name == "RServiceBus::Message_Subscription" then
184
+ @subscriptionManager.add( @msg.msg.eventName, @msg.returnAddress )
185
+
186
+ else
187
+ self.HandleMessage()
188
+ if !@config.forwardReceivedMessagesTo.nil? then
189
+ self._SendAlreadyWrappedAndSerialised(body,@config.forwardReceivedMessagesTo)
190
+ end
191
+ end
192
+ job.delete
193
+ rescue Exception => e
194
+ sleep 0.5
195
+
196
+
197
+ @handlerList[@msg.msg.class.name].each do |handler|
198
+ resourceByHandlerNameList[handler.class.name].each do |resource|
199
+ resource.reconnect
200
+ end
201
+ end
202
+
203
+
204
+ retry if (retries -= 1) > 0
205
+
206
+ @stats.incTotalErrored
207
+ if e.class.name == "Beanstalk::NotConnected" then
208
+ puts "Lost connection to beanstalkd."
209
+ puts "*** Start or Restart beanstalkd and try again."
210
+ abort();
211
+ end
212
+
213
+ if e.class.name == "Redis::CannotConnectError" then
214
+ puts "Lost connection to redis."
215
+ puts "*** Start or Restart redis and try again."
216
+ abort();
217
+ end
218
+
219
+ errorString = e.message + ". " + e.backtrace[0]
220
+ if e.backtrace.length > 1 then
221
+ errorString = errorString + ". " + e.backtrace[1]
222
+ end
223
+ if e.backtrace.length > 2 then
224
+ errorString = errorString + ". " + e.backtrace[2]
225
+ end
226
+ log errorString
227
+
228
+ @msg.addErrorMsg( @config.localQueueName, errorString )
229
+ serialized_object = YAML::dump(@msg)
230
+ self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
231
+ job.delete
232
+ end
233
+ rescue SystemExit, Interrupt
234
+ puts "Exiting on request ..."
235
+ messageLoop = false
236
+ rescue Exception => e
237
+ if e.message == "TIMED_OUT" then
238
+ #This exception is just saying there are no messages to process
239
+ statOutputCountdown = 0
240
+ elsif e.message == "SIGTERM" then
241
+ puts "Exiting on request ..."
242
+ messageLoop = false
243
+ else
244
+ puts "*** This is really unexpected."
245
+ messageLoop = false
246
+ puts "Message: " + e.message
247
+ puts e.backtrace
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ #Send the current msg to the appropriate handlers
254
+ def HandleMessage()
255
+ msgName = @msg.msg.class.name
256
+ handlerList = @handlerList[msgName]
257
+
258
+ if handlerList == nil then
259
+ log "No handler found for: " + msgName
260
+ raise "No Handler Found"
261
+ else
262
+ log "Handler found for: " + msgName, true
263
+ handlerList.each do |handler|
264
+ begin
265
+ handler.Handle( @msg.msg )
266
+ rescue Exception => e
267
+ log "An error occured in Handler: " + handler.class.name
268
+ log e.message + ". " + e.backtrace[0]
269
+ raise e
270
+ end
271
+ end
272
+ end
273
+ end
274
+
275
+ #Sends a msg across the bus
276
+ #
277
+ # @param [String] serialized_object serialized RServiceBus::Message
278
+ # @param [String] queueName endpoint to which the msg will be sent
279
+ def _SendAlreadyWrappedAndSerialised( serialized_object, queueName )
280
+ log "Bus._SendAlreadyWrappedAndSerialised", true
281
+
282
+ @beanstalk.use( queueName )
283
+ @beanstalk.put( serialized_object )
284
+ end
285
+
286
+ #Sends a msg across the bus
287
+ #
288
+ # @param [RServiceBus::Message] msg msg to be sent
289
+ # @param [String] queueName endpoint to which the msg will be sent
290
+ def _SendNeedsWrapping( msg, queueName )
291
+ log "Bus._SendNeedsWrapping", true
292
+
293
+ rMsg = RServiceBus::Message.new( msg, @config.localQueueName )
294
+ serialized_object = YAML::dump(rMsg)
295
+ log "Sending: " + msg.class.name + " to: " + queueName, true
296
+ self._SendAlreadyWrappedAndSerialised( serialized_object, queueName )
297
+ end
298
+
299
+ #Sends a msg back across the bus
300
+ #Reply queues are specified in each msg. It works like
301
+ #email, where the reply address can actually be anywhere
302
+ #
303
+ # @param [RServiceBus::Message] msg msg to be sent
304
+ def Reply( msg )
305
+ log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
306
+ @stats.incTotalReply
307
+
308
+ self._SendNeedsWrapping( msg, @msg.returnAddress )
309
+ end
310
+
311
+
312
+ #Send a msg across the bus
313
+ #msg destination is specified at the infrastructure level
314
+ #
315
+ # @param [RServiceBus::Message] msg msg to be sent
316
+ def Send( msg )
317
+ log "Bus.Send", true
318
+ @stats.incTotalSent
319
+
320
+ msgName = msg.class.name
321
+ if !@config.messageEndpointMappings.has_key?( msgName ) then
322
+ log "No end point mapping found for: " + msgName
323
+ log "**** Check in RServiceBus.yml that the section MessageEndpointMappings contains an entry named : " + msgName
324
+ raise "No end point mapping found for: " + msgName
325
+ end
326
+
327
+ queueName = @config.messageEndpointMappings[msgName]
328
+
329
+ self._SendNeedsWrapping( msg, queueName )
330
+ end
331
+
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
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
359
+
360
+ end
361
+
362
+ 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.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: