rservicebus2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +64 -0
- data/bin/return_messages_to_source_queue +114 -0
- data/bin/rsb_ctl +38 -0
- data/bin/rservicebus2 +14 -0
- data/bin/rservicebus2-create +107 -0
- data/bin/rservicebus2-init +104 -0
- data/bin/rservicebus2-transport +16 -0
- data/bin/send_empty_message +15 -0
- data/lib/rservicebus.rb +59 -0
- data/lib/rservicebus/agent.rb +54 -0
- data/lib/rservicebus/appresource.rb +65 -0
- data/lib/rservicebus/appresource/dir.rb +29 -0
- data/lib/rservicebus/appresource/file.rb +8 -0
- data/lib/rservicebus/appresource/fluiddb.rb +24 -0
- data/lib/rservicebus/appresource_configure.rb +33 -0
- data/lib/rservicebus/audit.rb +28 -0
- data/lib/rservicebus/circuitbreaker.rb +79 -0
- data/lib/rservicebus/config.rb +168 -0
- data/lib/rservicebus/cron_manager.rb +76 -0
- data/lib/rservicebus/endpointmapping.rb +72 -0
- data/lib/rservicebus/errormessage.rb +14 -0
- data/lib/rservicebus/handler_loader.rb +162 -0
- data/lib/rservicebus/handler_manager.rb +131 -0
- data/lib/rservicebus/helper_functions.rb +85 -0
- data/lib/rservicebus/host.rb +487 -0
- data/lib/rservicebus/message.rb +78 -0
- data/lib/rservicebus/message/statisticoutput.rb +7 -0
- data/lib/rservicebus/message/subscription.rb +10 -0
- data/lib/rservicebus/message/verboseoutput.rb +7 -0
- data/lib/rservicebus/monitor.rb +61 -0
- data/lib/rservicebus/monitor/csvdir.rb +52 -0
- data/lib/rservicebus/monitor/dir.rb +139 -0
- data/lib/rservicebus/monitor/dirnotifier.rb +101 -0
- data/lib/rservicebus/monitor/message.rb +11 -0
- data/lib/rservicebus/monitor/xmldir.rb +11 -0
- data/lib/rservicebus/monitor_configure.rb +71 -0
- data/lib/rservicebus/mq.rb +98 -0
- data/lib/rservicebus/mq/beanstalk.rb +72 -0
- data/lib/rservicebus/resource_manager.rb +69 -0
- data/lib/rservicebus/saga/base.rb +17 -0
- data/lib/rservicebus/saga/data.rb +20 -0
- data/lib/rservicebus/saga/manager.rb +128 -0
- data/lib/rservicebus/saga_loader.rb +118 -0
- data/lib/rservicebus/saga_storage.rb +18 -0
- data/lib/rservicebus/saga_storage/dir.rb +87 -0
- data/lib/rservicebus/saga_storage/inmemory.rb +37 -0
- data/lib/rservicebus/sendat_manager.rb +33 -0
- data/lib/rservicebus/sendat_storage.rb +20 -0
- data/lib/rservicebus/sendat_storage/file.rb +37 -0
- data/lib/rservicebus/sendat_storage/inmemory.rb +20 -0
- data/lib/rservicebus/state_manager.rb +30 -0
- data/lib/rservicebus/state_storage.rb +18 -0
- data/lib/rservicebus/state_storage/dir.rb +66 -0
- data/lib/rservicebus/state_storage/inmemory.rb +25 -0
- data/lib/rservicebus/statistic_manager.rb +86 -0
- data/lib/rservicebus/stats.rb +68 -0
- data/lib/rservicebus/subscription_manager.rb +31 -0
- data/lib/rservicebus/subscription_storage.rb +39 -0
- data/lib/rservicebus/subscription_storage/file.rb +42 -0
- data/lib/rservicebus/subscription_storage/redis.rb +69 -0
- data/lib/rservicebus/subscription_storage_configure.rb +19 -0
- data/lib/rservicebus/test.rb +2 -0
- data/lib/rservicebus/test/bus.rb +32 -0
- data/lib/rservicebus/transporter.rb +142 -0
- data/lib/rservicebus/usermessage/withpayload.rb +10 -0
- metadata +184 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# The application 'rservicebus-transport' is installed as part of a gem, and
|
4
|
+
# this file is here to facilitate running it.
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rservicebus'
|
9
|
+
require 'rservicebus/Transporter'
|
10
|
+
|
11
|
+
def run_rservicebus_transport()
|
12
|
+
RServiceBus::Transporter.new().Run()
|
13
|
+
end
|
14
|
+
|
15
|
+
run_rservicebus_transport
|
16
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rservicebus'
|
4
|
+
require 'rservicebus/Agent'
|
5
|
+
|
6
|
+
|
7
|
+
abort( "Usage: #{File.basename($0)} <Msg Name> <Queue Name> [Response Queue Name] [Beanstalk Host]" ) unless ARGV.length >=2 && ARGV.length <=4
|
8
|
+
msg_name = ARGV[0]
|
9
|
+
queue_name = ARGV[1]
|
10
|
+
response_queue_name = "#{queue_name}Response" if ARGV.length >= 3
|
11
|
+
beanstalkHost = 'beanstalk://localhost' if ARGV.length <= 4
|
12
|
+
|
13
|
+
agent = RServiceBus::Agent.new.getAgent( URI.parse( beanstalkHost) )
|
14
|
+
msg = RServiceBus.createAnonymousClass( msg_name )
|
15
|
+
agent.sendMsg(msg, queue_name, response_queue_name)
|
data/lib/rservicebus.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Add the currently running directory to the start of the load path
|
2
|
+
# $:.unshift File.dirname(__FILE__) + '/../../lib'
|
3
|
+
|
4
|
+
# Don't buffer stdout
|
5
|
+
$stdout.sync = true
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'yaml'
|
9
|
+
require 'uuidtools'
|
10
|
+
require 'json'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
require 'rservicebus/helper_functions'
|
14
|
+
require 'rservicebus/errormessage'
|
15
|
+
require 'rservicebus/handler_loader'
|
16
|
+
require 'rservicebus/handler_manager'
|
17
|
+
require 'rservicebus/appresource_configure'
|
18
|
+
require 'rservicebus/mq'
|
19
|
+
require 'rservicebus/host'
|
20
|
+
require 'rservicebus/config'
|
21
|
+
require 'rservicebus/endpointmapping'
|
22
|
+
require 'rservicebus/stats'
|
23
|
+
require 'rservicebus/statistic_manager'
|
24
|
+
require 'rservicebus/audit'
|
25
|
+
|
26
|
+
require 'rservicebus/message'
|
27
|
+
require 'rservicebus/message/subscription'
|
28
|
+
require 'rservicebus/message/statisticoutput'
|
29
|
+
require 'rservicebus/message/verboseoutput'
|
30
|
+
|
31
|
+
require 'rservicebus/usermessage/withpayload'
|
32
|
+
|
33
|
+
require 'rservicebus/state_manager'
|
34
|
+
require 'rservicebus/cron_manager'
|
35
|
+
require 'rservicebus/circuitbreaker'
|
36
|
+
|
37
|
+
require 'rservicebus/appresource'
|
38
|
+
require 'rservicebus/resource_manager'
|
39
|
+
|
40
|
+
require 'rservicebus/subscription_manager'
|
41
|
+
require 'rservicebus/subscription_storage'
|
42
|
+
require 'rservicebus/subscription_storage_configure'
|
43
|
+
|
44
|
+
require 'rservicebus/monitor_configure'
|
45
|
+
|
46
|
+
require 'rservicebus/agent'
|
47
|
+
|
48
|
+
require 'rservicebus/saga_loader.rb'
|
49
|
+
require 'rservicebus/saga/manager.rb'
|
50
|
+
require 'rservicebus/saga/data.rb'
|
51
|
+
require 'rservicebus/saga/base.rb'
|
52
|
+
|
53
|
+
require 'rservicebus/saga_storage'
|
54
|
+
|
55
|
+
require 'rservicebus/sendat_manager'
|
56
|
+
|
57
|
+
# Initial definition of the namespace
|
58
|
+
module RServiceBus
|
59
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
class QueueNotFoundForMsg < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
# A means for a stand-alone process to interact with the bus, without being
|
6
|
+
# a full rservicebus application
|
7
|
+
class Agent
|
8
|
+
def get_agent(uri)
|
9
|
+
ENV['RSBMQ'] = uri.to_s
|
10
|
+
|
11
|
+
RServiceBus.rlog '*** Agent.getAgent has been deprecated. Set the
|
12
|
+
environment variable, RSBMQ, and simply create the class'
|
13
|
+
Agent.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@mq = MQ.get
|
18
|
+
end
|
19
|
+
|
20
|
+
# Put a msg on the bus
|
21
|
+
#
|
22
|
+
# @param [Object] messageObj The msg to be sent
|
23
|
+
# @param [String] queueName the name of the queue to be send the msg to
|
24
|
+
# @param [String] returnAddress the name of a queue to send replies to
|
25
|
+
def send_msg(message_obj, queue_name, return_address = nil)
|
26
|
+
fail QueueNotFoundForMsg, message_obj.class.name if queue_name.nil?
|
27
|
+
|
28
|
+
msg = RServiceBus::Message.new(message_obj, return_address)
|
29
|
+
if queue_name.index('@').nil?
|
30
|
+
q = queue_name
|
31
|
+
else
|
32
|
+
parts = queueName.split('@')
|
33
|
+
msg.set_remote_queue_name(parts[0])
|
34
|
+
msg.set_remote_host_name(parts[1])
|
35
|
+
q = 'transport-out'
|
36
|
+
end
|
37
|
+
|
38
|
+
serialized_object = YAML.dump(msg)
|
39
|
+
|
40
|
+
@mq.send(q, serialized_object)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Gives an agent the means to receive a reply
|
44
|
+
#
|
45
|
+
# @param [String] queueName the name of the queue to monitor for messages
|
46
|
+
def check_for_reply(queue_name)
|
47
|
+
@mq.subscribe(queue_name)
|
48
|
+
body = @mq.pop
|
49
|
+
@msg = YAML.load(body)
|
50
|
+
@mq.ack
|
51
|
+
@msg.msg
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module RServiceBus
|
4
|
+
# Wrapper base class for resources used by applications, allowing rservicebus
|
5
|
+
# to configure the resource - dependency injection.
|
6
|
+
class AppResource
|
7
|
+
attr_reader :connection
|
8
|
+
|
9
|
+
# The method which actually connects to the resource.
|
10
|
+
def connect(_uri)
|
11
|
+
fail 'Method, connect, needs to be implemented for resource'
|
12
|
+
end
|
13
|
+
|
14
|
+
def _connect
|
15
|
+
@connection = connect(@uri)
|
16
|
+
RServiceBus.rlog "#{self.class.name}. Connected to, #{@uri}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_resource
|
20
|
+
@connection
|
21
|
+
end
|
22
|
+
|
23
|
+
# Resources are attached, and can be specified using the URI syntax.
|
24
|
+
# @param [String] uri a location for the resource to which we will attach,
|
25
|
+
# eg redis://127.0.0.1/foo
|
26
|
+
def initialize(host, uri)
|
27
|
+
@host = host
|
28
|
+
@uri = uri
|
29
|
+
# Do a connect / disconnect loop on startup to validate the connection
|
30
|
+
_connect
|
31
|
+
finished
|
32
|
+
end
|
33
|
+
|
34
|
+
# A notification that ocurs after getResource, to allow cleanup
|
35
|
+
def finished
|
36
|
+
@connection.close
|
37
|
+
end
|
38
|
+
|
39
|
+
# At least called in the Host rescue block, to ensure all network links are
|
40
|
+
# healthy
|
41
|
+
def reconnect
|
42
|
+
begin
|
43
|
+
finished
|
44
|
+
rescue StandardError => e
|
45
|
+
puts '** AppResource. An error was raised while closing connection
|
46
|
+
to, ' + @uri
|
47
|
+
puts 'Message: ' + e.message
|
48
|
+
puts e.backtrace
|
49
|
+
end
|
50
|
+
_connect
|
51
|
+
end
|
52
|
+
|
53
|
+
# Transaction Semantics
|
54
|
+
def begin
|
55
|
+
end
|
56
|
+
|
57
|
+
# Transaction Semantics
|
58
|
+
def commit
|
59
|
+
end
|
60
|
+
|
61
|
+
# Transaction Semantics
|
62
|
+
def rollback
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
# AppResourceDir
|
3
|
+
class AppResourceDir < AppResource
|
4
|
+
def connect(uri)
|
5
|
+
begin
|
6
|
+
input_dir = Dir.new(uri.path)
|
7
|
+
unless File.writable?(uri.path)
|
8
|
+
puts "*** Warning. Directory is not writable, #{uri.path}."
|
9
|
+
puts "*** Warning. Make the directory, #{uri.path}, writable and try
|
10
|
+
again."
|
11
|
+
end
|
12
|
+
rescue Errno::ENOENT
|
13
|
+
puts "***** Directory does not exist, #{uri.path}."
|
14
|
+
puts "***** Create the directory, #{uri.path}, and try again."
|
15
|
+
puts "***** eg, mkdir #{uri.path}"
|
16
|
+
abort
|
17
|
+
rescue Errno::ENOTDIR
|
18
|
+
puts "***** The specified path does not point to a directory,
|
19
|
+
#{uri.path}."
|
20
|
+
puts "***** Either repoint path to a directory, or remove, #{uri.path},
|
21
|
+
and create it as a directory."
|
22
|
+
puts "***** eg, rm #{uri.path} && mkdir #{uri.path}"
|
23
|
+
abort
|
24
|
+
end
|
25
|
+
|
26
|
+
input_dir
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'FluidDb/Db'
|
2
|
+
module RServiceBus
|
3
|
+
# Implementation of an AppResource - FluidDb
|
4
|
+
class AppResourceFluidDb < AppResource
|
5
|
+
def connect(uri)
|
6
|
+
FluidDb::Db(uri)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Transaction Semantics
|
10
|
+
def begin
|
11
|
+
@connection.begin
|
12
|
+
end
|
13
|
+
|
14
|
+
# Transaction Semantics
|
15
|
+
def commit
|
16
|
+
@connection.commit
|
17
|
+
end
|
18
|
+
|
19
|
+
# Transaction Semantics
|
20
|
+
def rollback
|
21
|
+
@connection.rollback
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module RServiceBus
|
4
|
+
# Configure AppResources for an rservicebus host
|
5
|
+
class ConfigureAppResource
|
6
|
+
def get_resources(env, host, state_manager, saga_storage)
|
7
|
+
# rm = resource_manager
|
8
|
+
rm = ResourceManager.new(state_manager, saga_storage)
|
9
|
+
env.each do |k, v|
|
10
|
+
if v.is_a?(String) && k.start_with?('RSBFDB_')
|
11
|
+
uri = URI.parse(v)
|
12
|
+
require 'rservicebus/appresource/fluiddb'
|
13
|
+
rm.add k.sub('RSBFDB_', ''), AppResourceFluidDb.new(host, uri)
|
14
|
+
elsif v.is_a?(String) && k.start_with?('RSB_')
|
15
|
+
uri = URI.parse(v)
|
16
|
+
case uri.scheme
|
17
|
+
when 'dir'
|
18
|
+
require 'rservicebus/appresource/dir'
|
19
|
+
rm.add k.sub('RSB_', ''), AppResourceDir.new(host, uri)
|
20
|
+
when 'file'
|
21
|
+
require 'rservicebus/appresource/file'
|
22
|
+
rm.add k.sub('RSB_', ''), AppResourceFile.new(host, uri)
|
23
|
+
else
|
24
|
+
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
25
|
+
app resource, #{k}=#{v}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
rm
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
# Audit Class
|
3
|
+
class Audit
|
4
|
+
def initialize(mq)
|
5
|
+
@mq = mq
|
6
|
+
audit_queue_name = RServiceBus.get_value('AUDIT_QUEUE_NAME')
|
7
|
+
if audit_queue_name.nil?
|
8
|
+
@sent_messages_to = RServiceBus.get_value('sent_messages_to')
|
9
|
+
@received_messages_to = RServiceBus.get_value('received_messages_to')
|
10
|
+
else
|
11
|
+
@sent_messages_to = audit_queue_name
|
12
|
+
@received_messages_to = audit_queue_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def audit_to_queue(obj)
|
17
|
+
@mq.send_msg(obj, @sent_messages_to)
|
18
|
+
end
|
19
|
+
|
20
|
+
def audit_outgoing(obj)
|
21
|
+
audit_to_queue(obj) unless @sent_messages_to.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def audit_incoming(obj)
|
25
|
+
audit_to_queue(obj) unless @received_messages_to.nil?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
class MessageArrivedWhileCricuitBroken < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
# An implementation of Michael Nygard's Circuit Breaker pattern.
|
6
|
+
class CircuitBreaker
|
7
|
+
def reset
|
8
|
+
@broken = false
|
9
|
+
|
10
|
+
@number_of_failures = 0
|
11
|
+
@time_of_first_failure = nil
|
12
|
+
|
13
|
+
@time_to_break = nil
|
14
|
+
@time_to_reset = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(host)
|
18
|
+
@host = host
|
19
|
+
@maxnumber_of_failures = RServiceBus.get_value('RSBCB_MAX', 5)
|
20
|
+
@seconds_to_break = RServiceBus.get_value('RSBCB_SECONDS_TO_BREAK', 60).to_i
|
21
|
+
@seconds_to_reset = RServiceBus.get_value('RSBCB_SECONDS_TO_RESET', 60).to_i
|
22
|
+
@reset_on_success = RServiceBus.get_value('RSBCB_RESET_ON_SUCCESS', false)
|
23
|
+
|
24
|
+
reset
|
25
|
+
end
|
26
|
+
|
27
|
+
####### Public Interface
|
28
|
+
# Broken will be called before processing a message.
|
29
|
+
# => Broken will be called before Failure
|
30
|
+
def broken
|
31
|
+
reset if !@time_to_reset.nil? && Time.now > @time_to_reset
|
32
|
+
@broken
|
33
|
+
end
|
34
|
+
|
35
|
+
def live
|
36
|
+
!broken
|
37
|
+
end
|
38
|
+
|
39
|
+
## This should be called less than success.
|
40
|
+
## If there is a failure, then taking a bit longer gives time to settle.
|
41
|
+
def failure
|
42
|
+
message_arrived
|
43
|
+
|
44
|
+
## logFirstFailure
|
45
|
+
if @number_of_failures == 0
|
46
|
+
@number_of_failures = 1
|
47
|
+
@time_of_first_failure = Time.now
|
48
|
+
@time_to_break = @time_of_first_failure + @seconds_to_break
|
49
|
+
else
|
50
|
+
@number_of_failures += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
## checkToBreakCircuit
|
54
|
+
break_circuit if @number_of_failures >= @maxnumber_of_failures
|
55
|
+
end
|
56
|
+
|
57
|
+
def success
|
58
|
+
if @reset_on_success == true
|
59
|
+
reset
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
message_arrived
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def message_arrived
|
69
|
+
reset if !@time_to_break.nil? && Time.now > @time_to_break
|
70
|
+
|
71
|
+
fail MessageArrivedWhileCricuitBroken if @broken == true
|
72
|
+
end
|
73
|
+
|
74
|
+
def break_circuit
|
75
|
+
@broken = true
|
76
|
+
@time_to_reset = Time.now + @seconds_to_reset
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module RServiceBus
|
2
|
+
# Marshals configuration information for an rservicebus host
|
3
|
+
class Config
|
4
|
+
attr_reader :app_name, :message_endpoint_mappings, :handler_path_list,
|
5
|
+
:saga_path_list, :error_queue_name, :max_retries,
|
6
|
+
:forward_received_messages_to, :subscription_uri,
|
7
|
+
:stat_output_countdown, :contract_list, :lib_list,
|
8
|
+
:forward_sent_messages_to, :mq_host
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
puts 'Cannot instantiate config directly.'
|
12
|
+
puts 'For production, use ConfigFromEnv.'
|
13
|
+
puts 'For debugging or testing, you could try ConfigFromSetter'
|
14
|
+
abort
|
15
|
+
end
|
16
|
+
|
17
|
+
def log(string)
|
18
|
+
puts string
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_value(name, default = nil)
|
22
|
+
value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name]
|
23
|
+
log "Env value: #{name}: #{value}"
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
27
|
+
# Marshals paths for message handlers
|
28
|
+
# Note. trailing slashs will be stripped
|
29
|
+
# Expected format: <path 1>;<path 2>
|
30
|
+
def load_handler_path_list
|
31
|
+
paths = get_value('MSGHANDLERPATH', './MessageHandler')
|
32
|
+
@handler_path_list = []
|
33
|
+
paths.split(';').each do |path|
|
34
|
+
@handler_path_list << path.strip.chomp('/')
|
35
|
+
end
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_saga_path_list
|
41
|
+
paths = get_value('SAGAPATH', './Saga')
|
42
|
+
@saga_path_list = []
|
43
|
+
paths.split(';').each do |path|
|
44
|
+
@saga_path_list << path.strip.chomp('/')
|
45
|
+
end
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_host_section
|
51
|
+
@app_name = get_value('APPNAME', 'RServiceBus')
|
52
|
+
@error_queue_name = get_value('ERROR_QUEUE_NAME', 'error')
|
53
|
+
@max_retries = get_value('MAX_RETRIES', '5').to_i
|
54
|
+
@stat_output_countdown = get_value('STAT_OUTPUT_COUNTDOWN', '100').to_i
|
55
|
+
@subscription_uri = get_value('SUBSCRIPTION_URI',
|
56
|
+
"file:///tmp/#{app_name}_subscriptions.yaml")
|
57
|
+
|
58
|
+
audit_queue_name = get_value('AUDIT_QUEUE_NAME')
|
59
|
+
if audit_queue_name.nil?
|
60
|
+
@forward_sent_messages_to = get_value('FORWARD_SENT_MESSAGES_TO')
|
61
|
+
@forward_received_messages_to = get_value('FORWARD_RECEIVED_MESSAGES_TO')
|
62
|
+
else
|
63
|
+
@forward_sent_messages_to = audit_queue_name
|
64
|
+
@forward_received_messages_to = audit_queue_name
|
65
|
+
end
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def ensure_contract_file_exists(path)
|
71
|
+
unless File.exist?(path) || File.exist?("#{path}.rb")
|
72
|
+
puts 'Error while processing contracts'
|
73
|
+
puts "*** path, #{path}, provided does not exist as a file"
|
74
|
+
abort
|
75
|
+
end
|
76
|
+
unless File.extname(path) == '' || File.extname(path) == '.rb'
|
77
|
+
puts 'Error while processing contracts'
|
78
|
+
puts "*** path, #{path}, should point to a ruby file, with extention .rb"
|
79
|
+
abort
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Marshals paths for contracts
|
84
|
+
# Note. .rb extension is optional
|
85
|
+
# Expected format: /one/two/Contracts
|
86
|
+
def load_contracts
|
87
|
+
@contract_list = []
|
88
|
+
# This is a guard clause in case no Contracts have been specified
|
89
|
+
# If any guard clauses have been specified, then execution should drop
|
90
|
+
# to the second block
|
91
|
+
puts "Config.load_contracts, #{@contract_list}"
|
92
|
+
return self if get_value('CONTRACTS').nil?
|
93
|
+
|
94
|
+
get_value('CONTRACTS', './Contract').split(';').each do |path|
|
95
|
+
ensure_contract_file_exists(path)
|
96
|
+
@contract_list << path
|
97
|
+
end
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
# Marshals paths for lib
|
102
|
+
# Note. .rb extension is optional
|
103
|
+
# Expected format: /one/two/Contracts
|
104
|
+
def load_libs
|
105
|
+
@lib_list = []
|
106
|
+
|
107
|
+
paths = get_value('LIB')
|
108
|
+
paths = './lib' if paths.nil? && File.exist?('./lib')
|
109
|
+
return self if paths.nil?
|
110
|
+
|
111
|
+
paths.split(';').each do |path|
|
112
|
+
log "Loading libs from, #{path}"
|
113
|
+
unless File.exist?(path)
|
114
|
+
puts 'Error while processing libs'
|
115
|
+
puts "*** path, #{path}, should point to a ruby file, with extention
|
116
|
+
.rb, or"
|
117
|
+
puts "*** path, #{path}, should point to a directory than conatins
|
118
|
+
ruby files, that have extention .rb"
|
119
|
+
abort
|
120
|
+
end
|
121
|
+
@lib_list << path
|
122
|
+
end
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def configure_mq
|
127
|
+
@mq_host = get_value('MQ', 'beanstalk://localhost')
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
# Marshals paths for working_dirs
|
132
|
+
# Note. trailing slashs will be stripped
|
133
|
+
# Expected format: <path 1>;<path 2>
|
134
|
+
def load_working_dir_list
|
135
|
+
puts "Config.load_working_dir_list.1"
|
136
|
+
puts "Config.load_working_dir_list.2 #{@contract_list}"
|
137
|
+
path_list = get_value('WORKING_DIR')
|
138
|
+
return self if path_list.nil?
|
139
|
+
|
140
|
+
path_list.split(';').each do |path|
|
141
|
+
path = path.strip.chomp('/')
|
142
|
+
unless Dir.exist?("#{path}")
|
143
|
+
puts 'Error while processing working directory list'
|
144
|
+
puts "*** path, #{path}, does not exist"
|
145
|
+
abort
|
146
|
+
end
|
147
|
+
@handler_path_list << "#{path}/MessageHandler" if Dir.exist?("#{path}/MessageHandler")
|
148
|
+
@saga_path_list << "#{path}/Saga" if Dir.exist?("#{path}/Saga")
|
149
|
+
@contract_list << "#{path}/Contract.rb" if File.exist?( "#{path}/Contract.rb" )
|
150
|
+
@lib_list << "#{path}/lib" if File.exist?("#{path}/lib")
|
151
|
+
end
|
152
|
+
self
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Class
|
157
|
+
class ConfigFromEnv < Config
|
158
|
+
def initialize
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Class
|
163
|
+
class ConfigFromSetter < Config
|
164
|
+
attr_writer :appName, :messageEndpointMappings, :handler_path_list, :errorQueueName, :maxRetries, :forward_received_messages_to, :beanstalkHost
|
165
|
+
def initialize
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|