rservicebus 0.0.74 → 0.0.75

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.
@@ -39,32 +39,6 @@ module RServiceBus
39
39
  return value
40
40
  end
41
41
 
42
- #Marshals data for message end points
43
- #
44
- #Expected format;
45
- # <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
46
- def loadMessageEndpointMappings()
47
- mapping = self.getValue( "MESSAGE_ENDPOINT_MAPPINGS" )
48
-
49
- messageEndpointMappings=Hash.new
50
- if !mapping.nil? then
51
- mapping.split( ";" ).each do |line|
52
- match = line.match( /(.+):(.+)/ )
53
- if match.nil? then
54
- log "Mapping string provided is invalid"
55
- log "The entire mapping string is: #{mapping}"
56
- log "*** Could not find ':' in mapping entry, #{line}"
57
- exit()
58
- end
59
- messageEndpointMappings[match[1]] = match[2]
60
- end
61
- end
62
-
63
- @messageEndpointMappings=messageEndpointMappings
64
-
65
- return self
66
- end
67
-
68
42
  #Marshals paths for message handlers
69
43
  #
70
44
  #Note. trailing slashs will be stripped
@@ -62,6 +62,10 @@ module RServiceBus
62
62
  require "rservicebus/Monitor/Dir"
63
63
  monitor = Monitor_Dir.new( @host, name, uri )
64
64
 
65
+ when "dirnotifier"
66
+ require "rservicebus/Monitor/DirNotifier"
67
+ monitor = Monitor_DirNotifier.new( @host, name, uri )
68
+
65
69
  when "csvperlinedir"
66
70
  require "rservicebus/Monitor/CsvPerLine"
67
71
  monitor = Monitor_CsvPerLineDir.new( @host, name, uri )
@@ -0,0 +1,52 @@
1
+ module RServiceBus
2
+
3
+ #Marshals data for message end points
4
+ #
5
+ #Expected format;
6
+ # <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
7
+ class EndpointMapping
8
+
9
+ def configureMapping( mapping )
10
+ match = mapping.match( /(.+):(.+)/ )
11
+ if match.nil? then
12
+ log "Mapping string provided is invalid"
13
+ log "The entire mapping string is: #{mapping}"
14
+ log "*** Could not find ':' in mapping entry, #{line}"
15
+ exit()
16
+ end
17
+
18
+ RServiceBus.log( "EndpointMapping.configureMapping: #{match[1]}, #{match[2]}", true )
19
+ @endpoints[match[1]] = match[2]
20
+
21
+ end
22
+
23
+ def Configure
24
+ RServiceBus.log( "EndpointMapping.Configure" )
25
+ mappings = RServiceBus.getValue( "MESSAGE_ENDPOINT_MAPPINGS" )
26
+ return self if mappings.nil?
27
+
28
+ mappings.split( ";" ).each do |mapping|
29
+ self.configureMapping( mapping )
30
+ end
31
+
32
+ return self
33
+ end
34
+
35
+ def initialize
36
+ @endpoints=Hash.new
37
+ end
38
+
39
+ def get( msgName )
40
+ if @endpoints.has_key?( msgName ) then
41
+ return @endpoints[msgName]
42
+ end
43
+
44
+ return nil;
45
+ end
46
+
47
+ def getSubscriptionEndpoints
48
+ return @endpoints.keys.select { |el| el.end_with?( "Event" ) }
49
+ end
50
+ end
51
+
52
+ end
@@ -68,15 +68,9 @@ module RServiceBus
68
68
  #msg endpoint mapping
69
69
  def sendSubscriptions
70
70
  log "Send Subscriptions"
71
- @config.messageEndpointMappings.each do |eventName,queueName|
72
- log "Checking, " + eventName + " for Event", true
73
- if eventName.end_with?( "Event" ) then
74
- log eventName + ", is an event. About to send subscription to, " + queueName, true
75
- self.Subscribe( eventName )
76
- log "Subscribed to, " + eventName + " at, " + queueName
77
- end
78
- end
79
-
71
+
72
+ @endpointMapping.getSubscriptionEndpoints.each { |eventName| self.Subscribe( eventName ) }
73
+
80
74
  return self
81
75
  end
82
76
 
@@ -90,7 +84,7 @@ module RServiceBus
90
84
  @config.handlerPathList.each do |path|
91
85
  @handlerLoader.loadHandlersFromPath(path)
92
86
  end
93
-
87
+
94
88
  return self
95
89
  end
96
90
 
@@ -142,11 +136,12 @@ module RServiceBus
142
136
  .loadHostSection()
143
137
  .configureMq()
144
138
  .loadContracts()
145
- .loadMessageEndpointMappings()
146
139
  .loadHandlerPathList()
147
140
  .loadLibs()
148
141
  .loadWorkingDirList();
149
142
 
143
+ @endpointMapping = EndpointMapping.new.Configure
144
+
150
145
  self.configureStatistics()
151
146
  .loadContracts()
152
147
  .loadLibs()
@@ -156,6 +151,7 @@ module RServiceBus
156
151
  .connectToMq()
157
152
  .configureSubscriptions()
158
153
  .sendSubscriptions()
154
+
159
155
 
160
156
  return self
161
157
  end
@@ -166,7 +162,7 @@ module RServiceBus
166
162
  log "Starting the Host"
167
163
 
168
164
  log "Watching, #{@config.localQueueName}"
169
- $0 = "rservicebus - #{@config.localQueueName}"
165
+ $0 = "rservicebus - #{@config.localQueueName}"
170
166
  if !@config.forwardReceivedMessagesTo.nil? then
171
167
  log "Forwarding all received messages to: " + @config.forwardReceivedMessagesTo.to_s
172
168
  end
@@ -270,11 +266,11 @@ module RServiceBus
270
266
  #This exception is just saying there are no messages to process
271
267
  statOutputCountdown = 0
272
268
  @queueForMsgsToBeSentOnComplete = Array.new
273
-
269
+
274
270
  @monitors.each do |o|
275
271
  o.Look
276
272
  end
277
-
273
+
278
274
  self.sendQueuedMsgs
279
275
  @queueForMsgsToBeSentOnComplete = nil
280
276
 
@@ -373,11 +369,22 @@ module RServiceBus
373
369
  def Reply( msg )
374
370
  log "Reply with: " + msg.class.name + " To: " + @msg.returnAddress, true
375
371
  @stats.incTotalReply
376
-
372
+
377
373
  self.queueMsgForSendOnComplete( msg, @msg.returnAddress )
378
374
  end
379
375
 
380
-
376
+ def getEndpointForMsg( msgName )
377
+ queueName = @endpointMapping.get( msgName )
378
+ return queueName unless queueName.nil?
379
+
380
+ return @config.localQueueName if @handlerManager.canMsgBeHandledLocally(msgName)
381
+
382
+ log "No end point mapping found for: " + msgName
383
+ log "**** Check environment variable MessageEndpointMappings contains an entry named : " + msgName
384
+ raise "No end point mapping found for: " + msgName
385
+ end
386
+
387
+
381
388
  #Send a msg across the bus
382
389
  #msg destination is specified at the infrastructure level
383
390
  #
@@ -385,17 +392,9 @@ module RServiceBus
385
392
  def Send( msg )
386
393
  log "Bus.Send", true
387
394
  @stats.incTotalSent
388
-
395
+
389
396
  msgName = msg.class.name
390
- if @config.messageEndpointMappings.has_key?( msgName ) then
391
- queueName = @config.messageEndpointMappings[msgName]
392
- elsif @handlerManager.canMsgBeHandledLocally(msgName) then
393
- queueName = @config.localQueueName
394
- else
395
- log "No end point mapping found for: " + msgName
396
- log "**** Check environment variable MessageEndpointMappings contains an entry named : " + msgName
397
- raise "No end point mapping found for: " + msgName
398
- end
397
+ queueName = self.getEndpointForMsg( msgName )
399
398
 
400
399
  self.queueMsgForSendOnComplete( msg, queueName )
401
400
  end
@@ -419,8 +418,8 @@ module RServiceBus
419
418
  # @param [String] eventName event to be subscribes to
420
419
  def Subscribe( eventName )
421
420
  log "Bus.Subscribe: " + eventName, true
422
-
423
- queueName = @config.messageEndpointMappings[eventName]
421
+
422
+ queueName = self.getEndpointForMsg( eventName )
424
423
  subscription = Message_Subscription.new( eventName )
425
424
 
426
425
  self._SendNeedsWrapping( subscription, queueName )
@@ -0,0 +1,47 @@
1
+ require 'cgi'
2
+ require 'zip/zip'
3
+ require 'zlib'
4
+
5
+ module RServiceBus
6
+
7
+ class Monitor_DirNotifier<Monitor
8
+
9
+ @Path
10
+
11
+ def connect(uri)
12
+ #Pass the path through the Dir object to check syntax on startup
13
+ begin
14
+ inputDir = Dir.new( uri.path )
15
+ if !File.writable?( uri.path ) then
16
+ puts "***** Directory is not writable, #{uri.path}."
17
+ puts "***** Make the directory, #{uri.path}, writable and try again."
18
+ abort()
19
+ end
20
+ rescue Errno::ENOENT => e
21
+ puts "***** Directory does not exist, #{uri.path}."
22
+ puts "***** Create the directory, #{uri.path}, and try again."
23
+ puts "***** eg, mkdir #{uri.path}"
24
+ abort();
25
+ rescue Errno::ENOTDIR => e
26
+ puts "***** The specified path does not point to a directory, #{uri.path}."
27
+ puts "***** Either repoint path to a directory, or remove, #{uri.path}, and create it as a directory."
28
+ puts "***** eg, rm #{uri.path} && mkdir #{uri.path}"
29
+ abort();
30
+ end
31
+
32
+ @Path = inputDir.path
33
+
34
+ end
35
+
36
+ def Look
37
+
38
+ fileList = Dir.glob( "#{@Path}/*" )
39
+ fileList.each do |filePath|
40
+ self.send( nil, URI.parse( "file://#{filePath}" ) )
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -36,11 +36,10 @@ module RServiceBus
36
36
  Object.const_set( name, newAnonymousClass )
37
37
  @MsgType = Object.const_get( name )
38
38
 
39
-
40
39
  @uri = uri
41
40
  self._connect
42
41
  end
43
-
42
+
44
43
  # A notification that allows cleanup
45
44
  def finished
46
45
  end
@@ -1,30 +1,37 @@
1
1
  module RServiceBus
2
-
2
+
3
3
  def RServiceBus.convertDTOToHash( obj )
4
- hash = {};
4
+ hash = {};
5
5
  obj.instance_variables.each {|var| hash[var.to_s.delete("@")] = obj.instance_variable_get(var) }
6
-
6
+
7
7
  return hash
8
8
  end
9
-
9
+
10
10
  def RServiceBus.convertDTOToJson( obj )
11
11
  hash = RServiceBus.convertDTOToHash(obj)
12
-
12
+
13
13
  return hash.to_json
14
14
  end
15
15
 
16
16
  def RServiceBus.log(string, ver=false)
17
17
  type = ver ? "VERB" : "INFO"
18
- # if @config.verbose || !ver then
19
- timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
20
- puts "[#{type}] #{timestamp} :: #{string}"
21
- # end
18
+ # if @config.verbose || !ver then
19
+ timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
20
+ puts "[#{type}] #{timestamp} :: #{string}"
21
+ # end
22
22
  end
23
-
23
+
24
24
  def RServiceBus.createAnonymousClass( name_for_class )
25
25
  newAnonymousClass = Class.new(Object)
26
26
  Object.const_set( name_for_class, newAnonymousClass )
27
27
  return Object.const_get( name_for_class ).new
28
28
  end
29
29
 
30
+ def RServiceBus.getValue( name, default=nil )
31
+ value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
32
+ log "Env value: #{name}: #{value}"
33
+ return value
34
+ end
35
+
36
+
30
37
  end
data/lib/rservicebus.rb CHANGED
@@ -19,6 +19,7 @@ require "rservicebus/ConfigureAppResource"
19
19
  require "rservicebus/ConfigureMQ"
20
20
  require "rservicebus/Host"
21
21
  require "rservicebus/Config"
22
+ require "rservicebus/EndpointMapping"
22
23
  require "rservicebus/Stats"
23
24
 
24
25
  require "rservicebus/Message"
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.74
4
+ version: 0.0.75
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-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby interpretation of NServiceBus
15
15
  email: guy@guyirvine.com
@@ -41,6 +41,7 @@ files:
41
41
  - lib/rservicebus/ConfigureMonitor.rb
42
42
  - lib/rservicebus/ConfigureMQ.rb
43
43
  - lib/rservicebus/ConfigureSubscriptionStorage.rb
44
+ - lib/rservicebus/EndpointMapping.rb
44
45
  - lib/rservicebus/ErrorMessage.rb
45
46
  - lib/rservicebus/HandlerLoader.rb
46
47
  - lib/rservicebus/HandlerManager.rb
@@ -51,6 +52,7 @@ files:
51
52
  - lib/rservicebus/Monitor/CsvDir.rb
52
53
  - lib/rservicebus/Monitor/CsvPerLine.rb
53
54
  - lib/rservicebus/Monitor/Dir.rb
55
+ - lib/rservicebus/Monitor/DirNotifier.rb
54
56
  - lib/rservicebus/Monitor/Message.rb
55
57
  - lib/rservicebus/Monitor/XmlDir.rb
56
58
  - lib/rservicebus/Monitor.rb