rservicebus2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +64 -0
  3. data/bin/return_messages_to_source_queue +114 -0
  4. data/bin/rsb_ctl +38 -0
  5. data/bin/rservicebus2 +14 -0
  6. data/bin/rservicebus2-create +107 -0
  7. data/bin/rservicebus2-init +104 -0
  8. data/bin/rservicebus2-transport +16 -0
  9. data/bin/send_empty_message +15 -0
  10. data/lib/rservicebus.rb +59 -0
  11. data/lib/rservicebus/agent.rb +54 -0
  12. data/lib/rservicebus/appresource.rb +65 -0
  13. data/lib/rservicebus/appresource/dir.rb +29 -0
  14. data/lib/rservicebus/appresource/file.rb +8 -0
  15. data/lib/rservicebus/appresource/fluiddb.rb +24 -0
  16. data/lib/rservicebus/appresource_configure.rb +33 -0
  17. data/lib/rservicebus/audit.rb +28 -0
  18. data/lib/rservicebus/circuitbreaker.rb +79 -0
  19. data/lib/rservicebus/config.rb +168 -0
  20. data/lib/rservicebus/cron_manager.rb +76 -0
  21. data/lib/rservicebus/endpointmapping.rb +72 -0
  22. data/lib/rservicebus/errormessage.rb +14 -0
  23. data/lib/rservicebus/handler_loader.rb +162 -0
  24. data/lib/rservicebus/handler_manager.rb +131 -0
  25. data/lib/rservicebus/helper_functions.rb +85 -0
  26. data/lib/rservicebus/host.rb +487 -0
  27. data/lib/rservicebus/message.rb +78 -0
  28. data/lib/rservicebus/message/statisticoutput.rb +7 -0
  29. data/lib/rservicebus/message/subscription.rb +10 -0
  30. data/lib/rservicebus/message/verboseoutput.rb +7 -0
  31. data/lib/rservicebus/monitor.rb +61 -0
  32. data/lib/rservicebus/monitor/csvdir.rb +52 -0
  33. data/lib/rservicebus/monitor/dir.rb +139 -0
  34. data/lib/rservicebus/monitor/dirnotifier.rb +101 -0
  35. data/lib/rservicebus/monitor/message.rb +11 -0
  36. data/lib/rservicebus/monitor/xmldir.rb +11 -0
  37. data/lib/rservicebus/monitor_configure.rb +71 -0
  38. data/lib/rservicebus/mq.rb +98 -0
  39. data/lib/rservicebus/mq/beanstalk.rb +72 -0
  40. data/lib/rservicebus/resource_manager.rb +69 -0
  41. data/lib/rservicebus/saga/base.rb +17 -0
  42. data/lib/rservicebus/saga/data.rb +20 -0
  43. data/lib/rservicebus/saga/manager.rb +128 -0
  44. data/lib/rservicebus/saga_loader.rb +118 -0
  45. data/lib/rservicebus/saga_storage.rb +18 -0
  46. data/lib/rservicebus/saga_storage/dir.rb +87 -0
  47. data/lib/rservicebus/saga_storage/inmemory.rb +37 -0
  48. data/lib/rservicebus/sendat_manager.rb +33 -0
  49. data/lib/rservicebus/sendat_storage.rb +20 -0
  50. data/lib/rservicebus/sendat_storage/file.rb +37 -0
  51. data/lib/rservicebus/sendat_storage/inmemory.rb +20 -0
  52. data/lib/rservicebus/state_manager.rb +30 -0
  53. data/lib/rservicebus/state_storage.rb +18 -0
  54. data/lib/rservicebus/state_storage/dir.rb +66 -0
  55. data/lib/rservicebus/state_storage/inmemory.rb +25 -0
  56. data/lib/rservicebus/statistic_manager.rb +86 -0
  57. data/lib/rservicebus/stats.rb +68 -0
  58. data/lib/rservicebus/subscription_manager.rb +31 -0
  59. data/lib/rservicebus/subscription_storage.rb +39 -0
  60. data/lib/rservicebus/subscription_storage/file.rb +42 -0
  61. data/lib/rservicebus/subscription_storage/redis.rb +69 -0
  62. data/lib/rservicebus/subscription_storage_configure.rb +19 -0
  63. data/lib/rservicebus/test.rb +2 -0
  64. data/lib/rservicebus/test/bus.rb +32 -0
  65. data/lib/rservicebus/transporter.rb +142 -0
  66. data/lib/rservicebus/usermessage/withpayload.rb +10 -0
  67. metadata +184 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6390a6216fea31b5315a309af0f998af347c539a
4
+ data.tar.gz: 50415a26cf33df5771b1072d7d263a7ce44e4b36
5
+ SHA512:
6
+ metadata.gz: db4ba7b7a200ace966ea8edf6a6f2a00496e34096964acf35c09c0156fd4e0f7f1839669b0be42acc720ba0a763ebc99bcf511a8b61acdf12ab1145b7dace7ee
7
+ data.tar.gz: 0529c38bae3eaa9f024ac54d2c1c4c09a7a665d571f3dd4fef19f61175fac9acbf69e06e2b4cd5cabb32af485f3fcbc154a8bda6926a9909a41fb2afd4f52299
data/LICENSE ADDED
@@ -0,0 +1,64 @@
1
+ rservicebus2 is copyrighted free software by all contributors, see logs in
2
+ revision control for names and email addresses of all of them.
3
+
4
+ You can redistribute it and/or modify it under either the terms of the
5
+ GNU General Public License (GPL) as published by the Free Software
6
+ Foundation (FSF), version {3.0}[http://www.gnu.org/licenses/gpl-3.0.txt]
7
+ or version {2.0}[http://www.gnu.org/licenses/gpl-2.0.txt]
8
+ or the Ruby-specific license terms (see below).
9
+
10
+ The rservicebus project leader (Guy Irvine) reserves the right to add future
11
+ versions of the GPL (and no other licenses) as published by the FSF to
12
+ the licensing terms.
13
+
14
+ === Ruby-specific terms (if you're not using the GPLv2 or GPLv3)
15
+
16
+ 1. You may make and give away verbatim copies of the source form of the
17
+ software without restriction, provided that you duplicate all of the
18
+ original copyright notices and associated disclaimers.
19
+
20
+ 2. You may modify your copy of the software in any way, provided that
21
+ you do at least ONE of the following:
22
+
23
+ a) place your modifications in the Public Domain or otherwise make them
24
+ Freely Available, such as by posting said modifications to Usenet or an
25
+ equivalent medium, or by allowing the author to include your
26
+ modifications in the software.
27
+
28
+ b) use the modified software only within your corporation or
29
+ organization.
30
+
31
+ c) rename any non-standard executables so the names do not conflict with
32
+ standard executables, which must also be provided.
33
+
34
+ d) make other distribution arrangements with the author.
35
+
36
+ 3. You may distribute the software in object code or executable
37
+ form, provided that you do at least ONE of the following:
38
+
39
+ a) distribute the executables and library files of the software,
40
+ together with instructions (in the manual page or equivalent) on where
41
+ to get the original distribution.
42
+
43
+ b) accompany the distribution with the machine-readable source of the
44
+ software.
45
+
46
+ c) give non-standard executables non-standard names, with
47
+ instructions on where to get the original software distribution.
48
+
49
+ d) make other distribution arrangements with the author.
50
+
51
+ 4. You may modify and include the part of the software into any other
52
+ software (possibly commercial). But some files in the distribution
53
+ are not written by the author, so that they are not under this terms.
54
+
55
+ 5. The scripts and library files supplied as input to or produced as
56
+ output from the software do not automatically fall under the
57
+ copyright of the software, but belong to whomever generated them,
58
+ and may be sold commercially, and may be aggregated with this
59
+ software.
60
+
61
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
62
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
63
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
64
+ PURPOSE.
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'beanstalk-client'
5
+ require 'rservicebus'
6
+
7
+ def returnMsg( beanstalk, job, request_nbr )
8
+ firstMatch = 'ruby/object:'
9
+
10
+ payload = job.body
11
+
12
+ firstIndex = payload.index( firstMatch )
13
+ startIndex = payload.index( firstMatch, firstIndex + 1 ) + firstMatch.length
14
+
15
+ msgName = payload.match( '(\w*)', startIndex )[1]
16
+
17
+ msg = YAML::load(payload)
18
+ if msg.lastErrorString.nil? then
19
+ puts "*** Requested msg, #{request_nbr}, does not have a sourceQueue to which it can be returned"
20
+ puts '*** Only errored msgs can be Returned'
21
+ puts '*** Generally, msgs would not be manually moved between queues'
22
+ puts '*** If you do need to, try'
23
+ puts '*** beanstalk-admin-dump <source queue name> | beanstalk-admin-load <destination queue name>'
24
+
25
+ job.release
26
+ return
27
+ end
28
+ queueName = msg.lastErrorSourceQueue
29
+ puts '#' + "#{request_nbr.to_s}: #{msgName} to #{queueName}"
30
+
31
+ beanstalk.use( queueName )
32
+ beanstalk.put( payload )
33
+
34
+ job.delete
35
+ end
36
+
37
+
38
+ index=nil
39
+ if ARGV.length == 0 then
40
+ queueName = 'error'
41
+ elsif ARGV.length == 1 then
42
+ queueName = ARGV[0]
43
+ elsif ARGV.length == 2 then
44
+ queueName = ARGV[0]
45
+ index = ARGV[1].to_i
46
+ else
47
+ abort('Usage: ReturnMessagesToSourceQueue [queue name] [index]')
48
+ end
49
+
50
+ begin
51
+ host = 'localhost:11300'
52
+ beanstalk = Beanstalk::Pool.new([host])
53
+
54
+ tubes = beanstalk.list_tubes[host]
55
+ unless tubes.include?(queueName) then
56
+ abort("Nothing waiting on the Beanstalk queue, #{queueName}")
57
+ end
58
+
59
+ tubeStats = beanstalk.stats_tube(queueName)
60
+ number_of_messages = tubeStats['current-jobs-ready']
61
+ if index.nil? then
62
+ puts
63
+ puts "Attempting to return #{number_of_messages} to their source queue"
64
+ puts
65
+
66
+ begin
67
+ beanstalk.watch(queueName)
68
+ 1.upto(number_of_messages) do |request_nbr|
69
+ job = beanstalk.reserve 1
70
+
71
+ returnMsg( beanstalk, job, request_nbr )
72
+ end
73
+ rescue Exception => e
74
+ if e.message == 'TIMED_OUT' then
75
+ else
76
+ raise
77
+ end
78
+ end
79
+ else
80
+ if index > number_of_messages then
81
+ puts "*** Requested msg, #{index}, is greater than the number of msgs in the queue, #{number_of_messages}"
82
+ puts '*** Try a smaller index, or remove the index number to return all msgs'
83
+ abort();
84
+ end
85
+
86
+ puts
87
+ puts "Attempting to msg number, #{index} to it's source queue"
88
+ puts
89
+
90
+ begin
91
+ beanstalk.watch(queueName)
92
+ jobList = Array.new
93
+ 1.upto(index-1) do |request_nbr|
94
+ job = beanstalk.reserve 1
95
+ jobList << job
96
+ end
97
+ job = beanstalk.reserve 1
98
+ returnMsg( beanstalk, job, index )
99
+
100
+ jobList.each do |job|
101
+ job.release
102
+ end
103
+
104
+ rescue Exception => e
105
+ if e.message == 'TIMED_OUT' then
106
+ else
107
+ raise
108
+ end
109
+ end
110
+ end
111
+
112
+ rescue Beanstalk::NotConnected=>e
113
+ puts 'Beanstalk not running'
114
+ end
data/bin/rsb_ctl ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The application 'rservicebus' 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/Agent'
10
+
11
+
12
+
13
+ if ARGV.length == 3 then
14
+ queue_name = ARGV[0]
15
+ switch_name = ARGV[1].upcase
16
+ switch_state = ARGV[2].upcase == 'TRUE' || ARGV[2].upcase == 'ON'
17
+ else
18
+ puts 'Usage: rsb_ctl <queue name> <switch> <switch state>'
19
+ puts 'Valid switchs: Stats, Verbose'
20
+ puts 'Valid switch states: On, Off'
21
+ abort()
22
+ end
23
+
24
+
25
+ agent = RServiceBus::Agent.new.getAgent( URI.parse('beanstalk://localhost') )
26
+ obj = nil
27
+ case switch_name
28
+ when switch_name = 'STATS'
29
+ obj = switch_state == true ? RServiceBus::Message_StatisticOutputOn.new : RServiceBus::Message_StatisticOutputOff.new
30
+ when switch_name = 'VERBOSE'
31
+ obj = switch_state == true ? RServiceBus::Message_VerboseOutputOn.new : RServiceBus::Message_VerboseOutputOff.new
32
+ else
33
+ puts "Switch name, #{ARGV[0]}, not recognized"
34
+ puts 'Valid switchs: Stats, Verbose'
35
+ abort()
36
+ end
37
+
38
+ agent.sendMsg(obj, queue_name, "#{queue_name}Response")
data/bin/rservicebus2 ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The application 'rservicebus' 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
+
10
+ def run_rservicebus()
11
+ RServiceBus::Host.new().run()
12
+ end
13
+
14
+ run_rservicebus
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #################################
4
+ # Contract
5
+ def contract(name)
6
+ content = '
7
+ class First
8
+ end
9
+ '
10
+
11
+ File.write("#{name}/Contract.rb", content)
12
+ end
13
+
14
+ #################################
15
+ # Rakefile
16
+ def rakefile(name)
17
+ content = %{
18
+ require 'rake/testtask'
19
+
20
+ Rake::TestTask.new do |t|
21
+ t.libs << 'test'
22
+ end
23
+
24
+ desc "Run tests"
25
+ task :default => :test
26
+
27
+ }
28
+
29
+ File.write("#{name}/Rakefile", content)
30
+ end
31
+
32
+ #################################
33
+ # Procfile
34
+ def procfile(name)
35
+ content = %{
36
+ #{name}: env APPNAME=#{name.capitalize} VERBOSE=true MAX_RETRIES=0 WORKING_DIR=#{Dir.pwd}/#{name} rservicebus
37
+
38
+ }
39
+
40
+ File.write("#{name}/Procfile", content)
41
+ end
42
+
43
+ #################################
44
+ # MessageHandler
45
+ def messagehandler(name)
46
+ content = '
47
+ class MessageHandler_First
48
+
49
+ def handle( msg )
50
+
51
+ end
52
+
53
+ end
54
+ '
55
+
56
+ Dir.mkdir("#{name}/MessageHandler")
57
+ File.write("#{name}/MessageHandler/First.rb", content)
58
+ end
59
+
60
+ #################################
61
+ # Test
62
+ def test(name)
63
+ content = %{
64
+ require 'test/unit'
65
+ require './Contract'
66
+ require './MessageHandler/First'
67
+
68
+
69
+ class Test_MessageHandler_First<MessageHandler_First
70
+
71
+
72
+
73
+ end
74
+
75
+ class FirstTest < Test::Unit::TestCase
76
+
77
+ def setup
78
+ @handler = Test_MessageHandler_First.new
79
+ end
80
+
81
+ def test_Basic
82
+ @handler.Handle( First.new )
83
+
84
+ assert_equal false, @handler.nil?
85
+ end
86
+ end
87
+
88
+ }
89
+
90
+ Dir.mkdir("#{name}/test")
91
+ File.write("#{name}/test/test_First.rb", content)
92
+ end
93
+
94
+ ################################################################
95
+
96
+ abort "usage: #{File.basename($0)} <name>" if ARGV.length != 1
97
+
98
+ #################################
99
+ name = ARGV[0].downcase
100
+
101
+ #################################
102
+ Dir.mkdir(name)
103
+ contract(name)
104
+ rakefile(name)
105
+ procfile(name)
106
+ messagehandler(name)
107
+ test(name)
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stringio'
4
+
5
+ ############################################
6
+ ContentReadMe = StringIO.new( <<"END_DATA" )
7
+ #Req
8
+
9
+ ##What
10
+ This is the starting point for RServiceBus
11
+
12
+ A single client, using the agent to send a message
13
+
14
+ A single message handler, running inside rservicebus which receives
15
+ the message and sends a reply
16
+
17
+ The client then picks up the reply
18
+
19
+ ##How
20
+ make sure beanstalk is running, then
21
+
22
+ run the
23
+ ./run
24
+
25
+ command in one terminal
26
+
27
+ in a second terminal, run
28
+ ruby Client.rb
29
+ END_DATA
30
+
31
+
32
+ ############################################
33
+ ContentClient = StringIO.new( <<"END_DATA" )
34
+ require "rservicebus"
35
+ require "rservicebus/Agent"
36
+ require "./Contract"
37
+
38
+ agent = RServiceBus::Agent.new.getAgent( URI.parse( "beanstalk://localhost" ) )
39
+
40
+ 1.upto(2) do |request_nbr|
41
+ agent.sendMsg(HelloWorld.new( "Hello World! " + request_nbr.to_s ), "HelloWorld", "helloResponse")
42
+ end
43
+
44
+ msg = agent.checkForReply( "helloResponse" )
45
+ puts msg
46
+ msg = agent.checkForReply( "helloResponse" )
47
+ puts msg
48
+ END_DATA
49
+
50
+
51
+ ############################################
52
+ ContentRun = StringIO.new( <<"END_DATA" )
53
+ APPNAME=HelloWorld \
54
+ ERROR_QUEUE_NAME=error \
55
+ MAX_RETRIES=2 \
56
+ VERBOSE=true \
57
+ WORKING_DIR=./ \
58
+ rservicebus
59
+ END_DATA
60
+
61
+
62
+
63
+ ############################################
64
+ ContentContract = StringIO.new( <<"END_DATA" )
65
+ class HelloWorld
66
+ attr_reader :name
67
+ def initialize( name )
68
+ @name = name
69
+ end
70
+ end
71
+ END_DATA
72
+
73
+
74
+ ############################################
75
+ ContentMessageHandler = StringIO.new( <<"END_DATA" )
76
+ class MessageHandler_HelloWorld
77
+
78
+ attr_accessor :Bus
79
+
80
+ def Handle( msg )
81
+ #raise "Manually generated error for testng"
82
+ puts "Handling Hello World: " + msg.name
83
+ @Bus.Reply( "Hey. " + msg.name )
84
+ end
85
+ end
86
+ END_DATA
87
+
88
+ ################################################################################################
89
+ class Init
90
+
91
+ def Run
92
+ IO.write( 'README.md', ContentReadMe.string );
93
+ IO.write( 'Client.rb', ContentClient.string );
94
+ IO.write( 'Contract.rb', ContentContract.string );
95
+ IO.write( 'run', ContentRun.string );
96
+
97
+ Dir.mkdir('./MessageHandler') unless Dir.exists? './MessageHandler'
98
+ ;
99
+ IO.write( 'MessageHandler/HelloWorld.rb', ContentMessageHandler.string );
100
+ end
101
+
102
+ end
103
+
104
+ Init.new.Run