rservicebus 0.0.01 → 0.0.2

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.
Files changed (75) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +48 -0
  3. data/bin/{rservicebus2 → rservicebus} +2 -1
  4. data/lib/rservicebus.rb +15 -54
  5. data/lib/rservicebus/Agent.rb +21 -0
  6. data/lib/rservicebus/Config.rb +125 -0
  7. data/lib/rservicebus/ErrorMessage.rb +14 -0
  8. data/lib/rservicebus/HandlerLoader.rb +100 -0
  9. data/lib/rservicebus/Host.rb +340 -0
  10. data/lib/rservicebus/Message.rb +29 -0
  11. data/lib/rservicebus/Subscription.rb +13 -0
  12. data/lib/rservicebus/helper_functions.rb +8 -81
  13. metadata +23 -150
  14. checksums.yaml +0 -7
  15. data/bin/return_messages_to_source_queue +0 -114
  16. data/bin/rsb_ctl +0 -38
  17. data/bin/rservicebus2-create +0 -107
  18. data/bin/rservicebus2-init +0 -104
  19. data/bin/rservicebus2-transport +0 -16
  20. data/bin/send_empty_message +0 -15
  21. data/lib/rservicebus/agent.rb +0 -54
  22. data/lib/rservicebus/appresource.rb +0 -65
  23. data/lib/rservicebus/appresource/dir.rb +0 -29
  24. data/lib/rservicebus/appresource/file.rb +0 -8
  25. data/lib/rservicebus/appresource/fluiddb.rb +0 -24
  26. data/lib/rservicebus/appresource_configure.rb +0 -33
  27. data/lib/rservicebus/audit.rb +0 -28
  28. data/lib/rservicebus/circuitbreaker.rb +0 -79
  29. data/lib/rservicebus/config.rb +0 -168
  30. data/lib/rservicebus/cron_manager.rb +0 -76
  31. data/lib/rservicebus/endpointmapping.rb +0 -72
  32. data/lib/rservicebus/errormessage.rb +0 -14
  33. data/lib/rservicebus/handler_loader.rb +0 -162
  34. data/lib/rservicebus/handler_manager.rb +0 -131
  35. data/lib/rservicebus/host.rb +0 -487
  36. data/lib/rservicebus/message.rb +0 -78
  37. data/lib/rservicebus/message/statisticoutput.rb +0 -7
  38. data/lib/rservicebus/message/subscription.rb +0 -10
  39. data/lib/rservicebus/message/verboseoutput.rb +0 -7
  40. data/lib/rservicebus/monitor.rb +0 -61
  41. data/lib/rservicebus/monitor/csvdir.rb +0 -52
  42. data/lib/rservicebus/monitor/dir.rb +0 -139
  43. data/lib/rservicebus/monitor/dirnotifier.rb +0 -101
  44. data/lib/rservicebus/monitor/message.rb +0 -11
  45. data/lib/rservicebus/monitor/xmldir.rb +0 -11
  46. data/lib/rservicebus/monitor_configure.rb +0 -71
  47. data/lib/rservicebus/mq.rb +0 -98
  48. data/lib/rservicebus/mq/beanstalk.rb +0 -72
  49. data/lib/rservicebus/resource_manager.rb +0 -69
  50. data/lib/rservicebus/saga/base.rb +0 -17
  51. data/lib/rservicebus/saga/data.rb +0 -20
  52. data/lib/rservicebus/saga/manager.rb +0 -128
  53. data/lib/rservicebus/saga_loader.rb +0 -118
  54. data/lib/rservicebus/saga_storage.rb +0 -18
  55. data/lib/rservicebus/saga_storage/dir.rb +0 -87
  56. data/lib/rservicebus/saga_storage/inmemory.rb +0 -37
  57. data/lib/rservicebus/sendat_manager.rb +0 -33
  58. data/lib/rservicebus/sendat_storage.rb +0 -20
  59. data/lib/rservicebus/sendat_storage/file.rb +0 -37
  60. data/lib/rservicebus/sendat_storage/inmemory.rb +0 -20
  61. data/lib/rservicebus/state_manager.rb +0 -30
  62. data/lib/rservicebus/state_storage.rb +0 -18
  63. data/lib/rservicebus/state_storage/dir.rb +0 -66
  64. data/lib/rservicebus/state_storage/inmemory.rb +0 -25
  65. data/lib/rservicebus/statistic_manager.rb +0 -86
  66. data/lib/rservicebus/stats.rb +0 -68
  67. data/lib/rservicebus/subscription_manager.rb +0 -31
  68. data/lib/rservicebus/subscription_storage.rb +0 -39
  69. data/lib/rservicebus/subscription_storage/file.rb +0 -42
  70. data/lib/rservicebus/subscription_storage/redis.rb +0 -69
  71. data/lib/rservicebus/subscription_storage_configure.rb +0 -19
  72. data/lib/rservicebus/test.rb +0 -2
  73. data/lib/rservicebus/test/bus.rb +0 -32
  74. data/lib/rservicebus/transporter.rb +0 -142
  75. data/lib/rservicebus/usermessage/withpayload.rb +0 -10
@@ -1,24 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,28 +0,0 @@
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
@@ -1,79 +0,0 @@
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
@@ -1,168 +0,0 @@
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
@@ -1,76 +0,0 @@
1
- require 'parse-cron'
2
-
3
- module RServiceBus
4
- # Globber
5
- class Globber
6
- def self.parse_to_regex(str)
7
- escaped = Regexp.escape(str).gsub('\*', '.*?')
8
- Regexp.new "^#{escaped}$", Regexp::IGNORECASE
9
- end
10
-
11
- def initialize(str)
12
- @regex = self.class.parse_to_regex str
13
- end
14
-
15
- def =~(str)
16
- !!(str =~ @regex)
17
- end
18
- end
19
-
20
- class NoMatchingMsgForCron < StandardError
21
- end
22
-
23
- # Cron Manager
24
- class CronManager
25
- def get_matching_msg_names(name)
26
- list = []
27
- @msg_names.each do |n|
28
- list << n if Globber.new(name) =~ n
29
- end
30
- fail NoMatchingMsgForCron, name if list.length == 0
31
- list
32
- end
33
-
34
- def add_cron(name, cron_string)
35
- get_matching_msg_names(name).each do |n|
36
- hash = {}
37
- hash['name'] = n
38
- hash['last'] = Time.now
39
- hash['v'] = cron_string
40
- hash['cron'] = CronParser.new(cron_string)
41
- hash['next'] = hash['cron'].next(Time.now)
42
- @list << hash
43
- @bus.log("Cron set for, #{n}, #{cron_string}, next run, #{hash['next']}")
44
- end
45
- end
46
-
47
- def initialize(host, msg_names = [])
48
- @bus = host
49
- @msg_names = msg_names
50
-
51
- RServiceBus.rlog 'Load Cron'
52
- @list = []
53
- ENV.each do |k, vs|
54
- if k.start_with?('RSBCRON_')
55
- add_cron(k.sub('RSBCRON_', ''), vs)
56
- elsif k.start_with?('RSBCRON')
57
- vs.split(';').each do |v|
58
- parts = v.split(' ', 6)
59
- add_cron(parts.pop, parts.join(' '))
60
- end
61
- end
62
- end
63
- end
64
-
65
- def run
66
- now = Time.now
67
- @list.each_with_index do |v, idx|
68
- next if now <= v['next']
69
-
70
- RServiceBus.rlog "CronManager.Send, #{v['name']}"
71
- @bus.send(RServiceBus.create_anonymous_class(v['name']))
72
- @list[idx]['next'] = v['cron'].next(now)
73
- end
74
- end
75
- end
76
- end
@@ -1,72 +0,0 @@
1
- module RServiceBus
2
- # Marshals data for message end points
3
- # Expected format: <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
4
- class EndpointMapping
5
- def get_value(name)
6
- RServiceBus.get_value(name)
7
- end
8
-
9
- def log(string, _ver = false)
10
- RServiceBus.log(string)
11
- end
12
-
13
- def configure_mapping(mapping)
14
- match = mapping.match(/(.+):(.+)/)
15
- if match.nil?
16
- log 'Mapping string provided is invalid'
17
- log "The entire mapping string is: #{mapping}"
18
- log "*** Could not find ':' in mapping entry, #{line}"
19
- exit
20
- end
21
-
22
- RServiceBus.rlog "EndpointMapping.configureMapping: #{match[1]}, #{match[2]}"
23
- @endpoints[match[1]] = match[2]
24
-
25
- @queue_name_list.each do |q|
26
- if q != match[2] && q.downcase == match[2].downcase
27
- log('*** Two queues specified with only case sensitive difference.')
28
- log("*** #{q} != #{match[2]}")
29
- log('*** If you meant these queues to be the same, please match case
30
- and restart the bus.')
31
- end
32
- end
33
- @queue_name_list << match[2]
34
- end
35
-
36
- def configure(local_queue_name=nil)
37
- log('EndpointMapping.Configure')
38
-
39
- @queue_name_list = []
40
- @queue_name_list << local_queue_name unless local_queue_name.nil?
41
-
42
- unless get_value('MESSAGE_ENDPOINT_MAPPING').nil?
43
- log('*** MESSAGE_ENDPOINT_MAPPING environment variable was detected')
44
- log("*** You may have intended MESSAGE_ENDPOINT_MAPPINGS, note the 'S'
45
- on the end")
46
- end
47
-
48
- mappings = get_value('MESSAGE_ENDPOINT_MAPPINGS')
49
- return self if mappings.nil?
50
-
51
- mappings.split(';').each do |mapping|
52
- configure_mapping(mapping)
53
- end
54
-
55
- self
56
- end
57
-
58
- def initialize
59
- @endpoints = {}
60
- end
61
-
62
- def get(msg_name)
63
- return @endpoints[msg_name] if @endpoints.key?(msg_name)
64
-
65
- nil
66
- end
67
-
68
- def get_subscription_endpoints
69
- @endpoints.keys.select { |el| el.end_with?('Event') }
70
- end
71
- end
72
- end