rservicebus 0.1.66 → 0.1.67

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,25 +13,25 @@ module RServiceBus
13
13
  #Host process for rservicebus
14
14
  class Host
15
15
  attr_accessor :sagaData
16
-
16
+
17
17
  @sagaData
18
-
18
+
19
19
  @handlerList
20
20
  @resourceListByHandlerName
21
-
21
+
22
22
  @subscriptions
23
-
23
+
24
24
  @mq
25
-
25
+
26
26
  @resourceManager
27
-
27
+
28
28
  @config
29
-
29
+
30
30
  @subscriptionManager
31
-
31
+
32
32
  @stats
33
-
34
-
33
+
34
+
35
35
  @queueForMsgsToBeSentOnComplete
36
36
 
37
37
 
@@ -49,8 +49,8 @@ module RServiceBus
49
49
  @resourceManager = ConfigureAppResource.new.getResources( ENV, self, @stateManager, @sagaStorage )
50
50
  return self;
51
51
  end
52
-
53
-
52
+
53
+
54
54
  #Thin veneer for Configuring SendAt
55
55
  #
56
56
  def configureSendAtManager
@@ -64,7 +64,7 @@ module RServiceBus
64
64
  @stateManager = StateManager.new
65
65
  return self;
66
66
  end
67
-
67
+
68
68
  #Thin veneer for Configuring state
69
69
  #
70
70
  def configureSagaStorage
@@ -84,20 +84,20 @@ module RServiceBus
84
84
  @circuitBreaker = CircuitBreaker.new( self )
85
85
  return self;
86
86
  end
87
-
88
-
87
+
88
+
89
89
  #Thin veneer for Configuring external resources
90
90
  #
91
91
  def configureMonitors
92
92
  @monitors = ConfigureMonitor.new( self, @resourceManager ).getMonitors( ENV )
93
93
  return self;
94
94
  end
95
-
95
+
96
96
  #Thin veneer for Configuring the Message Queue
97
97
  #
98
98
  def connectToMq
99
99
  @mq = MQ.get
100
-
100
+
101
101
  return self
102
102
  end
103
103
 
@@ -105,91 +105,91 @@ module RServiceBus
105
105
  #msg endpoint mapping
106
106
  def sendSubscriptions
107
107
  log "Send Subscriptions"
108
-
108
+
109
109
  @endpointMapping.getSubscriptionEndpoints.each { |eventName| self.Subscribe( eventName ) }
110
-
110
+
111
111
  return self
112
112
  end
113
-
113
+
114
114
  #Load and configure Message Handlers
115
115
  #
116
116
  def loadHandlers()
117
117
  log "Load Message Handlers"
118
118
  @handlerManager = HandlerManager.new( self, @resourceManager, @stateManager )
119
119
  @handlerLoader = HandlerLoader.new( self, @handlerManager )
120
-
120
+
121
121
  @config.handlerPathList.each do |path|
122
122
  @handlerLoader.loadHandlersFromPath(path)
123
123
  end
124
-
124
+
125
125
  return self
126
126
  end
127
-
127
+
128
128
  #Load and configure Sagas
129
129
  def loadSagas()
130
130
  log "Load Sagas"
131
131
  @sagaManager = Saga_Manager.new( self, @resourceManager, @sagaStorage )
132
132
  @sagaLoader = SagaLoader.new( self, @sagaManager )
133
-
133
+
134
134
  @config.sagaPathList.each do |path|
135
135
  @sagaLoader.loadSagasFromPath(path)
136
136
  end
137
-
137
+
138
138
  return self
139
139
  end
140
-
140
+
141
141
  #Thin veneer for Configuring Cron
142
142
  #
143
143
  def configureCronManager
144
144
  @cronManager = CronManager.new( self, @handlerManager.getListOfMsgNames )
145
145
  return self;
146
146
  end
147
-
147
+
148
148
  #Load Contracts
149
149
  #
150
150
  def loadContracts()
151
151
  log "Load Contracts"
152
-
152
+
153
153
  @config.contractList.each do |path|
154
154
  require path
155
155
  RServiceBus.rlog "Loaded Contract: #{path}"
156
156
  end
157
-
157
+
158
158
  return self
159
159
  end
160
-
160
+
161
161
  #For each directory given, find and load all librarys
162
162
  #
163
163
  def loadLibs()
164
164
  log "Load Libs"
165
-
165
+
166
166
  @config.libList.each do |path|
167
167
  $:.unshift path
168
168
  end
169
-
169
+
170
170
  return self
171
171
  end
172
-
172
+
173
173
  #Load, configure and initialise Subscriptions
174
174
  #
175
175
  def configureSubscriptions
176
176
  subscriptionStorage = ConfigureSubscriptionStorage.new.get( @config.appName, @config.subscriptionUri )
177
177
  @subscriptionManager = SubscriptionManager.new( subscriptionStorage )
178
-
178
+
179
179
  return self
180
180
  end
181
-
181
+
182
182
  #Initialise statistics monitor
183
183
  #
184
184
  def configureStatistics
185
185
  @stats = StatisticManager.new( self )
186
-
186
+
187
187
  return self
188
188
  end
189
-
189
+
190
190
  def initialize()
191
191
  RServiceBus.rlog "Current directory: #{Dir.pwd}"
192
-
192
+
193
193
  @config = ConfigFromEnv.new
194
194
  .loadHostSection()
195
195
  .loadContracts()
@@ -197,11 +197,11 @@ module RServiceBus
197
197
  .loadSagaPathList()
198
198
  .loadLibs()
199
199
  .loadWorkingDirList();
200
-
200
+
201
201
  self.connectToMq()
202
-
202
+
203
203
  @endpointMapping = EndpointMapping.new.Configure( @mq.localQueueName )
204
-
204
+
205
205
  self.configureStatistics()
206
206
  .loadContracts()
207
207
  .loadLibs()
@@ -216,16 +216,16 @@ module RServiceBus
216
216
  .configureCronManager()
217
217
  .configureSubscriptions()
218
218
  .sendSubscriptions()
219
-
220
-
219
+
220
+
221
221
  return self
222
222
  end
223
-
223
+
224
224
  #Ignition
225
225
  #
226
226
  def run
227
227
  log "Starting the Host"
228
-
228
+
229
229
  log "Watching, #{@mq.localQueueName}"
230
230
  $0 = "rservicebus - #{@mq.localQueueName}"
231
231
  if !@config.forwardReceivedMessagesTo.nil? then
@@ -234,10 +234,10 @@ module RServiceBus
234
234
  if !@config.forwardSentMessagesTo.nil? then
235
235
  log "Forwarding all sent messages to: " + @config.forwardSentMessagesTo.to_s
236
236
  end
237
-
237
+
238
238
  self.StartListeningToEndpoints
239
239
  end
240
-
240
+
241
241
  #Receive a msg, prep it, and handle any errors that may occur
242
242
  # - Most of this should be queue independant
243
243
  def StartListeningToEndpoints
@@ -245,17 +245,17 @@ module RServiceBus
245
245
  # statOutputCountdown = 0
246
246
  messageLoop = true
247
247
  retries = @config.maxRetries
248
-
248
+
249
249
  while messageLoop do
250
250
  #Popping a msg off the queue should not be in the message handler, as it affects retry
251
251
  begin
252
252
  @stats.tick
253
-
253
+
254
254
  if @circuitBreaker.Broken then
255
255
  sleep 0.5
256
256
  next
257
257
  end
258
-
258
+
259
259
  body = @mq.pop
260
260
  begin
261
261
  @stats.incTotalProcessed
@@ -274,12 +274,12 @@ module RServiceBus
274
274
  elsif @msg.msg.class.name == "RServiceBus::Message_VerboseOutputOff" then
275
275
  ENV.delete( "VERBOSE" )
276
276
  log "Turn off Verbose logging"
277
-
278
-
277
+
278
+
279
279
  else
280
-
280
+
281
281
  self.HandleMessage()
282
-
282
+
283
283
  if !@config.forwardReceivedMessagesTo.nil? then
284
284
  self._SendAlreadyWrappedAndSerialised(body,@config.forwardReceivedMessagesTo)
285
285
  end
@@ -288,59 +288,59 @@ module RServiceBus
288
288
  rescue ClassNotFoundForMsg => e
289
289
  puts "*** Class not found for msg, #{e.message}"
290
290
  puts "*** Ensure, #{e.message}, is defined in Contract.rb, most likely as 'Class #{e.message} end"
291
-
291
+
292
292
  @msg.addErrorMsg( @mq.localQueueName, e.message )
293
293
  serialized_object = YAML::dump(@msg)
294
294
  self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
295
295
  @mq.ack
296
-
296
+
297
297
  rescue NoHandlerFound => e
298
298
  puts "*** Handler not found for msg, #{e.message}"
299
299
  puts "*** Ensure a handler named, #{e.message}, is present in the MessageHandler directory."
300
-
300
+
301
301
  @msg.addErrorMsg( @mq.localQueueName, e.message )
302
302
  serialized_object = YAML::dump(@msg)
303
303
  self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
304
304
  @mq.ack
305
-
305
+
306
306
  rescue PropertyNotSet => e
307
307
  #This has been re-rasied from a rescue in the handler
308
308
  puts "*** #{e.message}"
309
309
  #"Property, #{e.message}, not set for, #{handler.class.name}"
310
310
  propertyName = e.message[10, e.message.index(",", 10)-10]
311
- puts "*** Ensure the environemnt variable, RSB_#{propertyName}, has been set at startup."
312
-
311
+ puts "*** Ensure the environment variable, RSB_#{propertyName}, has been set at startup."
312
+
313
313
  rescue Exception => e
314
314
  sleep 0.5
315
-
315
+
316
316
  puts "*** Exception occurred"
317
317
  puts e.message
318
318
  puts e.backtrace
319
319
  puts "***"
320
-
320
+
321
321
  if retries > 0 then
322
322
  retries = retries - 1
323
323
  @mq.returnToQueue
324
324
  else
325
-
325
+
326
326
  @circuitBreaker.Failure
327
-
327
+
328
328
  @stats.incTotalErrored
329
329
  if e.class.name == "Beanstalk::NotConnected" then
330
330
  puts "Lost connection to beanstalkd."
331
331
  puts "*** Start or Restart beanstalkd and try again."
332
332
  abort();
333
333
  end
334
-
334
+
335
335
  if e.class.name == "Redis::CannotConnectError" then
336
336
  puts "Lost connection to redis."
337
337
  puts "*** Start or Restart redis and try again."
338
338
  abort();
339
339
  end
340
-
340
+
341
341
  errorString = e.message + ". " + e.backtrace.join( ". " )
342
342
  # log errorString
343
-
343
+
344
344
  @msg.addErrorMsg( @mq.localQueueName, errorString )
345
345
  serialized_object = YAML::dump(@msg)
346
346
  self._SendAlreadyWrappedAndSerialised(serialized_object, @config.errorQueueName)
@@ -351,7 +351,7 @@ module RServiceBus
351
351
  rescue SystemExit, Interrupt
352
352
  puts "Exiting on request ..."
353
353
  messageLoop = false
354
-
354
+
355
355
  rescue NoMsgToProcess => e
356
356
  #This exception is just saying there are no messages to process
357
357
  statOutputCountdown = 0
@@ -361,7 +361,7 @@ module RServiceBus
361
361
  end
362
362
  self.sendQueuedMsgs
363
363
  @queueForMsgsToBeSentOnComplete = nil
364
-
364
+
365
365
  @queueForMsgsToBeSentOnComplete = Array.new
366
366
  @cronManager.Run
367
367
  self.sendQueuedMsgs
@@ -372,9 +372,9 @@ module RServiceBus
372
372
 
373
373
 
374
374
  @circuitBreaker.Success
375
-
375
+
376
376
  rescue Exception => e
377
- if e.message == "SIGTERM" then
377
+ if e.message == "SIGTERM" || e.message == "SIGINT" then
378
378
  puts "Exiting on request ..."
379
379
  messageLoop = false
380
380
  else
@@ -386,19 +386,19 @@ module RServiceBus
386
386
  end
387
387
  end
388
388
  end
389
-
389
+
390
390
  #Send the current msg to the appropriate handlers
391
391
  #
392
392
  def HandleMessage()
393
393
  @resourceManager.Begin
394
394
  msgName = @msg.msg.class.name
395
395
  handlerList = @handlerManager.getHandlerListForMsg(msgName)
396
-
397
-
396
+
397
+
398
398
  RServiceBus.rlog "Handler found for: " + msgName
399
399
  begin
400
400
  @queueForMsgsToBeSentOnComplete = Array.new
401
-
401
+
402
402
  log "Started processing msg, #{msgName}"
403
403
  handlerList.each do |handler|
404
404
  begin
@@ -413,42 +413,42 @@ module RServiceBus
413
413
  raise e
414
414
  end
415
415
  end
416
-
417
-
416
+
417
+
418
418
  if @sagaManager.Handle( @msg ) == false && handlerList.length == 0 then
419
419
  raise NoHandlerFound.new( msgName )
420
420
  end
421
-
422
-
423
-
421
+
422
+
423
+
424
424
  @resourceManager.Commit( msgName )
425
-
425
+
426
426
  self.sendQueuedMsgs
427
427
  log "Finished processing msg, #{msgName}"
428
-
428
+
429
429
  rescue Exception => e
430
-
430
+
431
431
  @resourceManager.Rollback( msgName )
432
432
  @queueForMsgsToBeSentOnComplete = nil
433
-
433
+
434
434
  raise e
435
435
  end
436
436
  end
437
-
437
+
438
438
  #######################################################################################################
439
439
  # All msg sending Methods
440
-
440
+
441
441
  #Sends a msg across the bus
442
442
  #
443
443
  # @param [String] serialized_object serialized RServiceBus::Message
444
444
  # @param [String] queueName endpoint to which the msg will be sent
445
445
  def _SendAlreadyWrappedAndSerialised( serialized_object, queueName )
446
446
  RServiceBus.rlog "Bus._SendAlreadyWrappedAndSerialised"
447
-
447
+
448
448
  if !@config.forwardSentMessagesTo.nil? then
449
449
  @mq.send( @config.forwardSentMessagesTo, serialized_object )
450
450
  end
451
-
451
+
452
452
  @mq.send( queueName, serialized_object )
453
453
  end
454
454
 
@@ -470,7 +470,7 @@ module RServiceBus
470
470
  q = 'transport-out'
471
471
  RServiceBus.rlog "Sending, #{msg.class.name} to, #{queueName}, via #{q}"
472
472
  end
473
-
473
+
474
474
  serialized_object = YAML::dump(rMsg)
475
475
  self._SendAlreadyWrappedAndSerialised( serialized_object, q )
476
476
  end
@@ -499,22 +499,22 @@ module RServiceBus
499
499
  def Reply( msg )
500
500
  RServiceBus.rlog "Reply with: " + msg.class.name + " To: " + @msg.returnAddress
501
501
  @stats.incTotalReply
502
-
502
+
503
503
  self.queueMsgForSendOnComplete( msg, @msg.returnAddress )
504
504
  end
505
-
505
+
506
506
  def getEndpointForMsg( msgName )
507
507
  queueName = @endpointMapping.get( msgName )
508
508
  return queueName unless queueName.nil?
509
-
509
+
510
510
  return @mq.localQueueName if @handlerManager.canMsgBeHandledLocally(msgName)
511
-
511
+
512
512
  log "No end point mapping found for: " + msgName
513
513
  log "**** Check environment variable MessageEndpointMappings contains an entry named : " + msgName
514
514
  raise "No end point mapping found for: " + msgName
515
515
  end
516
-
517
-
516
+
517
+
518
518
  #Send a msg across the bus
519
519
  #msg destination is specified at the infrastructure level
520
520
  #
@@ -525,7 +525,7 @@ module RServiceBus
525
525
 
526
526
  msgName = msg.class.name
527
527
  queueName = self.getEndpointForMsg( msgName )
528
-
528
+
529
529
  self.queueMsgForSendOnComplete( msg, queueName, timestamp )
530
530
  end
531
531
 
@@ -535,12 +535,12 @@ module RServiceBus
535
535
  def Publish( msg )
536
536
  RServiceBus.rlog "Bus.Publish"
537
537
  @stats.incTotalPublished
538
-
538
+
539
539
  subscriptions = @subscriptionManager.get(msg.class.name)
540
540
  subscriptions.each do |subscriber|
541
541
  self.queueMsgForSendOnComplete( msg, subscriber )
542
542
  end
543
-
543
+
544
544
  end
545
545
 
546
546
  #Sends a subscription request across the Bus
@@ -548,13 +548,13 @@ module RServiceBus
548
548
  # @param [String] eventName event to be subscribes to
549
549
  def Subscribe( eventName )
550
550
  RServiceBus.rlog "Bus.Subscribe: " + eventName
551
-
551
+
552
552
  queueName = self.getEndpointForMsg( eventName )
553
553
  subscription = Message_Subscription.new( eventName )
554
-
554
+
555
555
  self._SendNeedsWrapping( subscription, queueName, nil )
556
556
  end
557
-
557
+
558
558
  end
559
-
559
+
560
560
  end
@@ -3,8 +3,9 @@ require 'csv'
3
3
 
4
4
  module RServiceBus
5
5
 
6
+
6
7
  class Monitor_CsvDir<Monitor_Dir
7
-
8
+
8
9
 
9
10
  def checkPayloadForNumberOfColumns( payload )
10
11
  return if @QueryStringParts.nil?
@@ -145,7 +145,6 @@ module RServiceBus
145
145
 
146
146
  fileProcessed = fileProcessed + 1
147
147
  RServiceBus.log "Processed #{fileProcessed} of #{fileList.length}."
148
- RServiceBus.log "Allow system tick #{self.class.name}"
149
148
  return if fileProcessed >= maxFilesProcessed
150
149
  end
151
150
 
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.66
4
+ version: 0.1.67
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-02-06 00:00:00.000000000 Z
12
+ date: 2014-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
16
- requirement: &70249047240880 !ruby/object:Gem::Requirement
16
+ requirement: &70158534691240 !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: *70249047240880
24
+ version_requirements: *70158534691240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70249047258580 !ruby/object:Gem::Requirement
27
+ requirement: &70158534690800 !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: *70249047258580
35
+ version_requirements: *70158534690800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: beanstalk-client
38
- requirement: &70249047255440 !ruby/object:Gem::Requirement
38
+ requirement: &70158534690380 !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: *70249047255440
46
+ version_requirements: *70158534690380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fluiddb
49
- requirement: &70249047252340 !ruby/object:Gem::Requirement
49
+ requirement: &70158534689960 !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: *70249047252340
57
+ version_requirements: *70158534689960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: parse-cron
60
- requirement: &70249047265180 !ruby/object:Gem::Requirement
60
+ requirement: &70158534689540 !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: *70249047265180
68
+ version_requirements: *70158534689540
69
69
  description: A Ruby interpretation of NServiceBus
70
70
  email: guy@guyirvine.com
71
71
  executables: