rservicebus 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,15 +34,17 @@ proving to be a workable framework.
34
34
  * Queues specified by config, determined by message type
35
35
 
36
36
  ##Transport
37
- * RabbitMQ
37
+ * beanstalk
38
38
 
39
39
  ##MessageHandler
40
40
  * Name by convention - Handler name matchs filename
41
+ * Single handler for message is in top level file
42
+ * Multiple handlers for message are in files under top level directory
41
43
  * Handlers are dynamically loaded
42
44
  * If a handler fails to load, the service wont start - infrastructure problem
43
45
 
44
46
  ##MessageHandling
45
47
  * Transactions are good, use them
46
- * Given transactions, the first to do on error is retry
48
+ * Given transactions, the first thing to do on error is retry
47
49
  * Once we've used up retry, put the message on an error queue to process later - it's a logic problem
48
50
 
@@ -1,6 +1,6 @@
1
1
  module RServiceBus
2
2
 
3
- #Collects and reports configuration information for an rservicebus host
3
+ #Marshals configuration information for an rservicebus host
4
4
  class Config
5
5
  attr_reader :appName, :messageEndpointMappings, :handlerPathList, :localQueueName, :errorQueueName, :maxRetries, :forwardReceivedMessagesTo, :verbose, :beanstalkHost
6
6
 
@@ -24,12 +24,20 @@ class Config
24
24
  abort()
25
25
  end
26
26
 
27
+ def log( string )
28
+ puts string
29
+ end
30
+
27
31
  def getValue( name, default=nil )
28
- value = ENV["#{name}"].nil? ? default : ENV["#{name}"];
29
- puts "Env value: #{name}: #{value}"
32
+ value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
33
+ log "Env value: #{name}: #{value}"
30
34
  return value
31
35
  end
32
36
 
37
+ #Marshals data for message end points
38
+ #
39
+ #Expected format;
40
+ # <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
33
41
  def loadMessageEndpointMappings()
34
42
  mapping = self.getValue( "MESSAGE_ENDPOINT_MAPPINGS" )
35
43
 
@@ -37,6 +45,12 @@ class Config
37
45
  if !mapping.nil? then
38
46
  mapping.split( ";" ).each do |line|
39
47
  match = line.match( /(.+):(.+)/ )
48
+ if match.nil? then
49
+ log "Mapping string provided is invalid"
50
+ log "The entire mapping string is: #{mapping}"
51
+ log "*** Could not find ':' in mapping entry, #{line}"
52
+ exit()
53
+ end
40
54
  messageEndpointMappings[match[1]] = match[2]
41
55
  end
42
56
  end
@@ -46,6 +60,12 @@ class Config
46
60
  return self
47
61
  end
48
62
 
63
+ #Marshals paths for message handlers
64
+ #
65
+ #Note. trailing slashs will be stripped
66
+ #
67
+ #Expected format;
68
+ # <path 1>;<path 2>
49
69
  def loadHandlerPathList()
50
70
  path = self.getValue( "MSGHANDLERPATH", "./MessageHandler" )
51
71
  handlerPathList = Array.new
@@ -59,10 +79,9 @@ class Config
59
79
  return self
60
80
  end
61
81
 
62
-
63
82
  def loadHostSection()
64
83
  @appName = self.getValue( "APPNAME", "RServiceBus" )
65
- @localQueueName = @appName
84
+ @localQueueName = self.getValue( "LOCAL_QUEUE_NAME", @appName )
66
85
  @errorQueueName = self.getValue( "ERROR_QUEUE_NAME", "error" )
67
86
  @maxRetries = self.getValue( "MAX_RETRIES", "5" ).to_i
68
87
  @forwardReceivedMessagesTo = self.getValue( "FORWARD_RECEIVED_MESSAGES_TO" )
@@ -70,14 +89,34 @@ class Config
70
89
  return self
71
90
  end
72
91
 
92
+ def performRequire( path )
93
+ require path
94
+ end
95
+
96
+ def ensureContractFileExists( path )
97
+ if !( File.exists?( path ) ||
98
+ File.exists?( "#{path}.rb" ) ) then
99
+ puts "Error while processing contracts"
100
+ puts "*** path, #{path}, provided does not exist as a file"
101
+ abort()
102
+ end
103
+ if !( File.extname( path ) == "" ||
104
+ File.extname( path ) == ".rb" ) then
105
+ puts "Error while processing contracts"
106
+ puts "*** path, #{path}, should point to a ruby file, with extention .rb"
107
+ abort()
108
+ end
109
+ end
110
+
73
111
  def loadContracts()
74
112
  if self.getValue( "CONTRACTS", "./Contract" ).nil? then
75
113
  return self
76
114
  end
77
115
 
78
116
  self.getValue( "CONTRACTS", "./Contract" ).split( ";" ).each do |path|
79
- puts "Loading contracts from, #{path}"
80
- require path
117
+ log "Loading contracts from, #{path}"
118
+ self.ensureContractFileExists( path )
119
+ self.performRequire( path )
81
120
  end
82
121
  return self
83
122
  end
@@ -98,10 +98,24 @@ class Host
98
98
  log "Load subscriptions"
99
99
  @subscriptions = Hash.new
100
100
 
101
- redis = Redis.new
101
+ begin
102
+ redis = Redis.new
102
103
 
103
- prefix = @config.appName + ".Subscriptions."
104
- subscriptions = redis.keys prefix + "*Event"
104
+ prefix = @config.appName + ".Subscriptions."
105
+ subscriptions = redis.keys prefix + "*Event"
106
+ rescue Exception => e
107
+ puts "Error connecting to redis"
108
+ # puts "Host string, #{@config.beanstalkHost}"
109
+ if e.message == "Redis::CannotConnectError" ||
110
+ e.message == "Redis::ECONNREFUSED" then
111
+ puts "***Most likely, redis is not running. Start redis, and try running this again."
112
+ # puts "***If you still get this error, check redis is running at, " + beanstalkHost
113
+ else
114
+ puts e.message
115
+ puts e.backtrace
116
+ end
117
+ abort()
118
+ end
105
119
 
106
120
  subscriptions.each do |subscriptionName|
107
121
  log "Loading subscription: " + subscriptionName, true
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.7
4
+ version: 0.0.8
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: 2012-06-20 00:00:00.000000000 Z
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A ruby implementation of NServiceBus
15
15
  email: guy@guyirvine.com