rservicebus 0.0.52 → 0.0.53
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.
- data/lib/rservicebus/Config.rb +222 -215
- data/lib/rservicebus/Host.rb +4 -1
- metadata +2 -2
data/lib/rservicebus/Config.rb
CHANGED
@@ -1,223 +1,230 @@
|
|
1
1
|
module RServiceBus
|
2
|
-
|
3
|
-
#Marshals configuration information for an rservicebus host
|
4
|
-
class Config
|
5
|
-
attr_reader :appName, :messageEndpointMappings, :handlerPathList, :localQueueName, :errorQueueName, :maxRetries, :forwardReceivedMessagesTo, :subscriptionUri, :verbose, :queueTimeout, :statOutputCountdown, :contractList, :libList, :forwardSentMessagesTo, :mqHost
|
6
|
-
|
7
|
-
@appName
|
8
|
-
@messageEndpointMappings
|
9
|
-
@handlerPathList
|
10
|
-
@contractList
|
11
|
-
|
12
|
-
@localQueueName
|
13
|
-
@errorQueueName
|
14
|
-
@forwardSentMessagesTo
|
15
|
-
@maxRetries
|
16
|
-
@forwardReceivedMessagesTo
|
17
|
-
@subscriptionUri
|
18
|
-
|
19
|
-
@verbose
|
20
|
-
|
21
|
-
@mq
|
22
|
-
|
23
|
-
@queueTimeout
|
24
|
-
|
25
|
-
def initialize()
|
26
|
-
puts "Cannot instantiate config directly."
|
27
|
-
puts "For production, use ConfigFromEnv."
|
28
|
-
puts "For debugging or testing, you could try ConfigFromSetter"
|
29
|
-
abort()
|
30
|
-
end
|
31
|
-
|
32
|
-
def log( string )
|
33
|
-
puts string
|
34
|
-
end
|
35
|
-
|
36
|
-
def getValue( name, default=nil )
|
37
|
-
value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
|
38
|
-
log "Env value: #{name}: #{value}"
|
39
|
-
return value
|
40
|
-
end
|
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
|
-
#Marshals paths for message handlers
|
69
|
-
#
|
70
|
-
#Note. trailing slashs will be stripped
|
71
|
-
#
|
72
|
-
#Expected format;
|
73
|
-
# <path 1>;<path 2>
|
74
|
-
def loadHandlerPathList()
|
75
|
-
path = self.getValue( "MSGHANDLERPATH", "./MessageHandler" )
|
76
|
-
@handlerPathList = Array.new
|
77
|
-
path.split( ";" ).each do |path|
|
78
|
-
path = path.strip.chomp( "/" )
|
79
|
-
@handlerPathList << path
|
80
|
-
end
|
81
|
-
|
82
|
-
return self
|
83
|
-
end
|
84
|
-
|
85
|
-
def loadHostSection()
|
86
|
-
@appName = self.getValue( "APPNAME", "RServiceBus" )
|
87
|
-
@localQueueName = self.getValue( "LOCAL_QUEUE_NAME", @appName )
|
88
|
-
@errorQueueName = self.getValue( "ERROR_QUEUE_NAME", "error" )
|
89
|
-
@forwardSentMessagesTo = self.getValue( "AUDIT_QUEUE_NAME" )
|
90
|
-
@maxRetries = self.getValue( "MAX_RETRIES", "5" ).to_i
|
91
|
-
@forwardReceivedMessagesTo = self.getValue( "FORWARD_RECEIVED_MESSAGES_TO" )
|
92
|
-
@queueTimeout = self.getValue( "QUEUE_TIMEOUT", "5" ).to_i
|
93
|
-
@statOutputCountdown = self.getValue( "STAT_OUTPUT_COUNTDOWN", "100" ).to_i
|
94
|
-
@subscriptionUri = self.getValue( "SUBSCRIPTION_URI", "redis://127.0.0.1:6379/" )
|
95
|
-
|
96
|
-
return self
|
97
|
-
end
|
98
|
-
|
99
|
-
def ensureContractFileExists( path )
|
100
|
-
if !( File.exists?( path ) ||
|
101
|
-
File.exists?( "#{path}.rb" ) ) then
|
102
|
-
puts "Error while processing contracts"
|
103
|
-
puts "*** path, #{path}, provided does not exist as a file"
|
104
|
-
abort()
|
105
|
-
end
|
106
|
-
if !( File.extname( path ) == "" ||
|
107
|
-
File.extname( path ) == ".rb" ) then
|
108
|
-
puts "Error while processing contracts"
|
109
|
-
puts "*** path, #{path}, should point to a ruby file, with extention .rb"
|
110
|
-
abort()
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
#Marshals paths for contracts
|
115
|
-
#
|
116
|
-
#Note. .rb extension is optional
|
117
|
-
#
|
118
|
-
#Expected format;
|
119
|
-
# /one/two/Contracts
|
120
|
-
def loadContracts()
|
121
|
-
@contractList = Array.new
|
122
|
-
|
123
|
-
#This is a guard clause in case no Contracts have been specified
|
124
|
-
#If any guard clauses have been specified, then execution should drop to the second block
|
125
|
-
if self.getValue( "CONTRACTS" ).nil? then
|
126
|
-
return self
|
127
|
-
end
|
128
|
-
|
129
|
-
self.getValue( "CONTRACTS", "./Contract" ).split( ";" ).each do |path|
|
130
|
-
self.ensureContractFileExists( path )
|
131
|
-
@contractList << path
|
132
|
-
end
|
133
|
-
return self
|
134
|
-
end
|
135
|
-
|
136
|
-
#Marshals paths for lib
|
137
|
-
#
|
138
|
-
#Note. .rb extension is optional
|
139
|
-
#
|
140
|
-
#Expected format;
|
141
|
-
# /one/two/Contracts
|
142
|
-
def loadLibs()
|
143
|
-
@libList = Array.new
|
144
|
-
|
145
|
-
path = self.getValue( "LIB" )
|
146
|
-
path = "./lib" if path.nil? and File.exists?( "./lib" )
|
147
|
-
if path.nil? then
|
148
|
-
return self
|
149
|
-
end
|
150
|
-
|
151
|
-
path.split( ";" ).each do |path|
|
152
|
-
log "Loading libs from, #{path}"
|
153
|
-
if !File.exists?( path ) then
|
154
|
-
puts "Error while processing libs"
|
155
|
-
puts "*** path, #{path}, should point to a ruby file, with extention .rb, or"
|
156
|
-
puts "*** path, #{path}, should point to a directory than conatins ruby files, that have extention .rb"
|
157
|
-
abort()
|
158
|
-
end
|
159
|
-
@libList << path
|
160
|
-
end
|
161
|
-
return self
|
162
|
-
end
|
163
2
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
3
|
+
#Marshals configuration information for an rservicebus host
|
4
|
+
class Config
|
5
|
+
attr_reader :appName, :messageEndpointMappings, :handlerPathList, :localQueueName, :errorQueueName, :maxRetries, :forwardReceivedMessagesTo, :subscriptionUri, :verbose, :queueTimeout, :statOutputCountdown, :contractList, :libList, :forwardSentMessagesTo, :mqHost
|
6
|
+
|
7
|
+
@appName
|
8
|
+
@messageEndpointMappings
|
9
|
+
@handlerPathList
|
10
|
+
@contractList
|
11
|
+
|
12
|
+
@localQueueName
|
13
|
+
@errorQueueName
|
14
|
+
@forwardSentMessagesTo
|
15
|
+
@maxRetries
|
16
|
+
@forwardReceivedMessagesTo
|
17
|
+
@subscriptionUri
|
18
|
+
|
19
|
+
@verbose
|
20
|
+
|
21
|
+
@mq
|
22
|
+
|
23
|
+
@queueTimeout
|
24
|
+
|
25
|
+
def initialize()
|
26
|
+
puts "Cannot instantiate config directly."
|
27
|
+
puts "For production, use ConfigFromEnv."
|
28
|
+
puts "For debugging or testing, you could try ConfigFromSetter"
|
29
|
+
abort()
|
30
|
+
end
|
31
|
+
|
32
|
+
def log( string )
|
33
|
+
puts string
|
34
|
+
end
|
35
|
+
|
36
|
+
def getValue( name, default=nil )
|
37
|
+
value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
|
38
|
+
log "Env value: #{name}: #{value}"
|
39
|
+
return value
|
40
|
+
end
|
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" )
|
186
48
|
|
187
|
-
|
188
|
-
if
|
189
|
-
|
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
|
190
61
|
end
|
191
|
-
|
192
|
-
|
193
|
-
|
62
|
+
|
63
|
+
@messageEndpointMappings=messageEndpointMappings
|
64
|
+
|
65
|
+
return self
|
66
|
+
end
|
67
|
+
|
68
|
+
#Marshals paths for message handlers
|
69
|
+
#
|
70
|
+
#Note. trailing slashs will be stripped
|
71
|
+
#
|
72
|
+
#Expected format;
|
73
|
+
# <path 1>;<path 2>
|
74
|
+
def loadHandlerPathList()
|
75
|
+
path = self.getValue( "MSGHANDLERPATH", "./MessageHandler" )
|
76
|
+
@handlerPathList = Array.new
|
77
|
+
path.split( ";" ).each do |path|
|
78
|
+
path = path.strip.chomp( "/" )
|
79
|
+
@handlerPathList << path
|
194
80
|
end
|
195
|
-
|
196
|
-
|
197
|
-
|
81
|
+
|
82
|
+
return self
|
83
|
+
end
|
84
|
+
|
85
|
+
def loadHostSection()
|
86
|
+
@appName = self.getValue( "APPNAME", "RServiceBus" )
|
87
|
+
@localQueueName = self.getValue( "LOCAL_QUEUE_NAME", @appName )
|
88
|
+
@errorQueueName = self.getValue( "ERROR_QUEUE_NAME", "error" )
|
89
|
+
@maxRetries = self.getValue( "MAX_RETRIES", "5" ).to_i
|
90
|
+
@queueTimeout = self.getValue( "QUEUE_TIMEOUT", "5" ).to_i
|
91
|
+
@statOutputCountdown = self.getValue( "STAT_OUTPUT_COUNTDOWN", "100" ).to_i
|
92
|
+
@subscriptionUri = self.getValue( "SUBSCRIPTION_URI", "redis://127.0.0.1:6379/" )
|
93
|
+
|
94
|
+
auditQueueName = self.getValue( "AUDIT_QUEUE_NAME" )
|
95
|
+
if auditQueueName.nil? then
|
96
|
+
@forwardSentMessagesTo = self.getValue( "FORWARD_SENT_MESSAGES_TO" )
|
97
|
+
@forwardReceivedMessagesTo = self.getValue( "FORWARD_RECEIVED_MESSAGES_TO" )
|
98
|
+
else
|
99
|
+
@forwardSentMessagesTo = auditQueueName
|
100
|
+
@forwardReceivedMessagesTo = auditQueueName
|
198
101
|
end
|
199
|
-
end
|
200
|
-
|
201
|
-
return self
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
|
207
|
-
class ConfigFromEnv<Config
|
208
|
-
|
209
|
-
def initialize()
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
class ConfigFromSetter<Config
|
215
|
-
attr_writer :appName, :messageEndpointMappings, :handlerPathList, :localQueueName, :errorQueueName, :maxRetries, :forwardReceivedMessagesTo, :verbose, :beanstalkHost
|
216
|
-
|
217
|
-
def initialize()
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
221
|
-
|
222
102
|
|
103
|
+
return self
|
104
|
+
end
|
105
|
+
|
106
|
+
def ensureContractFileExists( path )
|
107
|
+
if !( File.exists?( path ) ||
|
108
|
+
File.exists?( "#{path}.rb" ) ) then
|
109
|
+
puts "Error while processing contracts"
|
110
|
+
puts "*** path, #{path}, provided does not exist as a file"
|
111
|
+
abort()
|
112
|
+
end
|
113
|
+
if !( File.extname( path ) == "" ||
|
114
|
+
File.extname( path ) == ".rb" ) then
|
115
|
+
puts "Error while processing contracts"
|
116
|
+
puts "*** path, #{path}, should point to a ruby file, with extention .rb"
|
117
|
+
abort()
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
#Marshals paths for contracts
|
122
|
+
#
|
123
|
+
#Note. .rb extension is optional
|
124
|
+
#
|
125
|
+
#Expected format;
|
126
|
+
# /one/two/Contracts
|
127
|
+
def loadContracts()
|
128
|
+
@contractList = Array.new
|
129
|
+
|
130
|
+
#This is a guard clause in case no Contracts have been specified
|
131
|
+
#If any guard clauses have been specified, then execution should drop to the second block
|
132
|
+
if self.getValue( "CONTRACTS" ).nil? then
|
133
|
+
return self
|
134
|
+
end
|
135
|
+
|
136
|
+
self.getValue( "CONTRACTS", "./Contract" ).split( ";" ).each do |path|
|
137
|
+
self.ensureContractFileExists( path )
|
138
|
+
@contractList << path
|
139
|
+
end
|
140
|
+
return self
|
141
|
+
end
|
142
|
+
|
143
|
+
#Marshals paths for lib
|
144
|
+
#
|
145
|
+
#Note. .rb extension is optional
|
146
|
+
#
|
147
|
+
#Expected format;
|
148
|
+
# /one/two/Contracts
|
149
|
+
def loadLibs()
|
150
|
+
@libList = Array.new
|
151
|
+
|
152
|
+
path = self.getValue( "LIB" )
|
153
|
+
path = "./lib" if path.nil? and File.exists?( "./lib" )
|
154
|
+
if path.nil? then
|
155
|
+
return self
|
156
|
+
end
|
157
|
+
|
158
|
+
path.split( ";" ).each do |path|
|
159
|
+
log "Loading libs from, #{path}"
|
160
|
+
if !File.exists?( path ) then
|
161
|
+
puts "Error while processing libs"
|
162
|
+
puts "*** path, #{path}, should point to a ruby file, with extention .rb, or"
|
163
|
+
puts "*** path, #{path}, should point to a directory than conatins ruby files, that have extention .rb"
|
164
|
+
abort()
|
165
|
+
end
|
166
|
+
@libList << path
|
167
|
+
end
|
168
|
+
return self
|
169
|
+
end
|
170
|
+
|
171
|
+
def configureLogging()
|
172
|
+
@verbose = !self.getValue( "VERBOSE", nil ).nil?
|
173
|
+
|
174
|
+
return self
|
175
|
+
end
|
176
|
+
|
177
|
+
def configureMq
|
178
|
+
@mqHost = self.getValue( "MQ", "beanstalk://localhost" )
|
179
|
+
return self
|
180
|
+
end
|
181
|
+
|
182
|
+
#Marshals paths for working_dirs
|
183
|
+
#
|
184
|
+
#Note. trailing slashs will be stripped
|
185
|
+
#
|
186
|
+
#Expected format;
|
187
|
+
# <path 1>;<path 2>
|
188
|
+
def loadWorkingDirList()
|
189
|
+
pathList = self.getValue( "WORKING_DIR" )
|
190
|
+
return self if pathList.nil?
|
191
|
+
|
192
|
+
pathList.split( ";" ).each do |path|
|
193
|
+
|
194
|
+
path = path.strip.chomp( "/" )
|
195
|
+
if Dir.exists?( "#{path}/MessageHandler" ) then
|
196
|
+
@handlerPathList << "#{path}/MessageHandler"
|
197
|
+
end
|
198
|
+
|
199
|
+
if File.exists?( "#{path}/Contract.rb" ) then
|
200
|
+
@contractList << "#{path}/Contract.rb"
|
201
|
+
end
|
202
|
+
|
203
|
+
if File.exists?( "#{path}/lib" ) then
|
204
|
+
@libList << "#{path}/lib"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
return self
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
class ConfigFromEnv<Config
|
215
|
+
|
216
|
+
def initialize()
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
class ConfigFromSetter<Config
|
222
|
+
attr_writer :appName, :messageEndpointMappings, :handlerPathList, :localQueueName, :errorQueueName, :maxRetries, :forwardReceivedMessagesTo, :verbose, :beanstalkHost
|
223
|
+
|
224
|
+
def initialize()
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
|
223
230
|
end
|
data/lib/rservicebus/Host.rb
CHANGED
@@ -169,6 +169,9 @@ module RServiceBus
|
|
169
169
|
if !@config.forwardReceivedMessagesTo.nil? then
|
170
170
|
log "Forwarding all received messages to: " + @config.forwardReceivedMessagesTo.to_s
|
171
171
|
end
|
172
|
+
if !@config.forwardSentMessagesTo.nil? then
|
173
|
+
log "Forwarding all sent messages to: " + @config.forwardSentMessagesTo.to_s
|
174
|
+
end
|
172
175
|
|
173
176
|
self.StartListeningToEndpoints
|
174
177
|
end
|
@@ -312,7 +315,7 @@ module RServiceBus
|
|
312
315
|
if !@config.forwardSentMessagesTo.nil? then
|
313
316
|
@mq.send( @config.forwardSentMessagesTo, serialized_object )
|
314
317
|
end
|
315
|
-
|
318
|
+
|
316
319
|
@mq.send( queueName, serialized_object )
|
317
320
|
end
|
318
321
|
|
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.
|
4
|
+
version: 0.0.53
|
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-
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|