rservicebus 0.0.79 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ReturnErroredMessagesToSourceQueue +47 -2
- data/lib/rservicebus/Agent.rb +1 -4
- data/lib/rservicebus/Agent/Beanstalk.rb +6 -7
- data/lib/rservicebus/ConfigureMQ.rb +0 -4
- data/lib/rservicebus/Host.rb +2 -2
- data/lib/rservicebus/MQ.rb +1 -1
- data/lib/rservicebus/Transporter.rb +2 -2
- metadata +2 -8
- data/bin/ReturnErroredMessagesToSourceQueueBeanstalk +0 -49
- data/bin/ReturnErroredMessagesToSourceQueueBunny +0 -51
- data/lib/rservicebus/Agent/Bunny.rb +0 -48
- data/lib/rservicebus/MQ/Bunny.rb +0 -54
@@ -1,4 +1,49 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
require "beanstalk-client"
|
6
|
+
|
7
|
+
require "rservicebus"
|
8
|
+
|
9
|
+
begin
|
10
|
+
host = 'localhost:11300'
|
11
|
+
errorQueueName = "error"
|
12
|
+
beanstalk = Beanstalk::Pool.new([host])
|
13
|
+
|
14
|
+
tubes = beanstalk.list_tubes[host]
|
15
|
+
if !tubes.include?(errorQueueName) then
|
16
|
+
abort( "Nothing waiting on the Beanstalk error queue" )
|
17
|
+
end
|
18
|
+
|
19
|
+
tubeStats = beanstalk.stats_tube(errorQueueName)
|
20
|
+
number_of_messages = tubeStats["current-jobs-ready"]
|
21
|
+
puts
|
22
|
+
puts "Attempting to return #{number_of_messages} to their source queue"
|
23
|
+
puts
|
24
|
+
|
25
|
+
begin
|
26
|
+
beanstalk.watch(errorQueueName)
|
27
|
+
1.upto(number_of_messages) do |request_nbr|
|
28
|
+
job = beanstalk.reserve 1
|
29
|
+
payload = job.body
|
30
|
+
|
31
|
+
puts "#" + request_nbr.to_s + ": " + payload
|
32
|
+
msg = YAML::load(payload)
|
33
|
+
queueName = msg.getLastErrorMsg.sourceQueue
|
34
|
+
|
35
|
+
beanstalk.use( queueName )
|
36
|
+
beanstalk.put( payload )
|
37
|
+
|
38
|
+
job.delete
|
39
|
+
end
|
40
|
+
rescue Exception => e
|
41
|
+
if e.message == "TIMED_OUT" then
|
42
|
+
else
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
rescue Beanstalk::NotConnected=>e
|
48
|
+
puts "Beanstalk not running"
|
49
|
+
end
|
data/lib/rservicebus/Agent.rb
CHANGED
@@ -8,13 +8,10 @@ module RServiceBus
|
|
8
8
|
if uri.scheme == "beanstalk" then
|
9
9
|
require "rservicebus/Agent/Beanstalk"
|
10
10
|
return Agent_Beanstalk.new()
|
11
|
-
elsif uri.scheme == "bunny" then
|
12
|
-
require "rservicebus/Agent/Bunny"
|
13
|
-
return Agent_Bunny.new()
|
14
11
|
else
|
15
12
|
raise StandardError.new( "Scheme not recognised" )
|
16
13
|
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
20
|
-
end
|
17
|
+
end
|
@@ -17,19 +17,18 @@ class Agent_Beanstalk
|
|
17
17
|
# @param [String] returnAddress the name of a queue to send replies to
|
18
18
|
def sendMsg(messageObj, queueName, returnAddress=nil)
|
19
19
|
msg = RServiceBus::Message.new( messageObj, returnAddress )
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
|
22
22
|
if queueName.index( "@" ).nil? then
|
23
23
|
q = queueName
|
24
|
-
|
24
|
+
else
|
25
25
|
parts = queueName.split( "@" )
|
26
26
|
msg.setRemoteQueueName( parts[0] )
|
27
27
|
msg.setRemoteHostName( parts[1] )
|
28
|
-
|
28
|
+
q = 'transport-out'
|
29
29
|
end
|
30
|
-
|
31
|
-
|
32
|
-
serialized_object = YAML::dump(msg)
|
30
|
+
|
31
|
+
serialized_object = YAML::dump(msg)
|
33
32
|
|
34
33
|
@beanstalk.use( q )
|
35
34
|
@beanstalk.put( serialized_object )
|
@@ -13,10 +13,6 @@ module RServiceBus
|
|
13
13
|
require "rservicebus/MQ/Beanstalk"
|
14
14
|
mq = MQ_Beanstalk.new( uri, timeout )
|
15
15
|
|
16
|
-
when "bunny"
|
17
|
-
require "rservicebus/MQ/Bunny"
|
18
|
-
mq = MQ_Bunny.new( uri, timeout )
|
19
|
-
|
20
16
|
else
|
21
17
|
abort("Scheme, #{uri.scheme}, not recognised when configuring mq, #{string}");
|
22
18
|
end
|
data/lib/rservicebus/Host.rb
CHANGED
@@ -330,11 +330,11 @@ module RServiceBus
|
|
330
330
|
# @param [String] queueName endpoint to which the msg will be sent
|
331
331
|
def _SendAlreadyWrappedAndSerialised( serialized_object, queueName )
|
332
332
|
log "Bus._SendAlreadyWrappedAndSerialised", true
|
333
|
-
|
333
|
+
|
334
334
|
if !@config.forwardSentMessagesTo.nil? then
|
335
335
|
@mq.send( @config.forwardSentMessagesTo, serialized_object )
|
336
336
|
end
|
337
|
-
|
337
|
+
|
338
338
|
@mq.send( queueName, serialized_object )
|
339
339
|
end
|
340
340
|
|
data/lib/rservicebus/MQ.rb
CHANGED
@@ -11,7 +11,7 @@ module RServiceBus
|
|
11
11
|
|
12
12
|
# Resources are attached resources, and can be specified using the URI syntax.
|
13
13
|
#
|
14
|
-
# @param [URI] uri the type and location of queue, eg
|
14
|
+
# @param [URI] uri the type and location of queue, eg beanstalk://127.0.0.1/foo
|
15
15
|
# @param [Integer] timeout the amount of time to wait for a msg to arrive
|
16
16
|
def initialize( uri, timeout )
|
17
17
|
@timeout = timeout
|
@@ -52,7 +52,7 @@ class Transporter
|
|
52
52
|
#Get the next job from the source queue
|
53
53
|
job = @source.reserve @timeout
|
54
54
|
msg = YAML::load(job.body)
|
55
|
-
|
55
|
+
|
56
56
|
log "job: #{job.body}", true
|
57
57
|
|
58
58
|
|
@@ -63,7 +63,7 @@ class Transporter
|
|
63
63
|
|
64
64
|
# Open port 27018 to forward to 127.0.0.11300 on the remote host
|
65
65
|
gateway.open('127.0.0.1', 11300, 27018)
|
66
|
-
|
66
|
+
|
67
67
|
log "Connect to destination beanstalk"
|
68
68
|
begin
|
69
69
|
destinationUrl = '127.0.0.1:27018'
|
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.1.0
|
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-08-
|
12
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby interpretation of NServiceBus
|
15
15
|
email: guy@guyirvine.com
|
@@ -17,15 +17,12 @@ executables:
|
|
17
17
|
- rservicebus
|
18
18
|
- rservicebus-init
|
19
19
|
- ReturnErroredMessagesToSourceQueue
|
20
|
-
- ReturnErroredMessagesToSourceQueueBeanstalk
|
21
|
-
- ReturnErroredMessagesToSourceQueueBunny
|
22
20
|
- SendEmptyMessage
|
23
21
|
- rservicebus-transport
|
24
22
|
extensions: []
|
25
23
|
extra_rdoc_files: []
|
26
24
|
files:
|
27
25
|
- lib/rservicebus/Agent/Beanstalk.rb
|
28
|
-
- lib/rservicebus/Agent/Bunny.rb
|
29
26
|
- lib/rservicebus/Agent.rb
|
30
27
|
- lib/rservicebus/AppResource/Dir.rb
|
31
28
|
- lib/rservicebus/AppResource/File.rb
|
@@ -58,7 +55,6 @@ files:
|
|
58
55
|
- lib/rservicebus/Monitor/XmlDir.rb
|
59
56
|
- lib/rservicebus/Monitor.rb
|
60
57
|
- lib/rservicebus/MQ/Beanstalk.rb
|
61
|
-
- lib/rservicebus/MQ/Bunny.rb
|
62
58
|
- lib/rservicebus/MQ.rb
|
63
59
|
- lib/rservicebus/Saga.rb
|
64
60
|
- lib/rservicebus/Stats.rb
|
@@ -72,8 +68,6 @@ files:
|
|
72
68
|
- lib/rservicebus/Transporter.rb
|
73
69
|
- lib/rservicebus.rb
|
74
70
|
- bin/ReturnErroredMessagesToSourceQueue
|
75
|
-
- bin/ReturnErroredMessagesToSourceQueueBeanstalk
|
76
|
-
- bin/ReturnErroredMessagesToSourceQueueBunny
|
77
71
|
- bin/rservicebus
|
78
72
|
- bin/rservicebus-init
|
79
73
|
- bin/rservicebus-transport
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
require "beanstalk-client"
|
6
|
-
|
7
|
-
require "rservicebus"
|
8
|
-
|
9
|
-
begin
|
10
|
-
host = 'localhost:11300'
|
11
|
-
errorQueueName = "error"
|
12
|
-
beanstalk = Beanstalk::Pool.new([host])
|
13
|
-
|
14
|
-
tubes = beanstalk.list_tubes[host]
|
15
|
-
if !tubes.include?(errorQueueName) then
|
16
|
-
abort( "Nothing waiting on the Beanstalk error queue" )
|
17
|
-
end
|
18
|
-
|
19
|
-
tubeStats = beanstalk.stats_tube(errorQueueName)
|
20
|
-
number_of_messages = tubeStats["current-jobs-ready"]
|
21
|
-
puts
|
22
|
-
puts "Attempting to return #{number_of_messages} to their source queue"
|
23
|
-
puts
|
24
|
-
|
25
|
-
begin
|
26
|
-
beanstalk.watch(errorQueueName)
|
27
|
-
1.upto(number_of_messages) do |request_nbr|
|
28
|
-
job = beanstalk.reserve 1
|
29
|
-
payload = job.body
|
30
|
-
|
31
|
-
puts "#" + request_nbr.to_s + ": " + payload
|
32
|
-
msg = YAML::load(payload)
|
33
|
-
queueName = msg.getLastErrorMsg.sourceQueue
|
34
|
-
|
35
|
-
beanstalk.use( queueName )
|
36
|
-
beanstalk.put( payload )
|
37
|
-
|
38
|
-
job.delete
|
39
|
-
end
|
40
|
-
rescue Exception => e
|
41
|
-
if e.message == "TIMED_OUT" then
|
42
|
-
else
|
43
|
-
raise
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
rescue Beanstalk::NotConnected=>e
|
48
|
-
puts "Beanstalk not running"
|
49
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
require "bunny"
|
6
|
-
|
7
|
-
require "rservicebus"
|
8
|
-
|
9
|
-
host = 'localhost'
|
10
|
-
port = '5672'
|
11
|
-
errorQueueName = "error"
|
12
|
-
|
13
|
-
begin
|
14
|
-
bunny = Bunny.new(:host=>host, :port=>port)
|
15
|
-
bunny.start
|
16
|
-
direct_exchange = bunny.exchange('rservicebus.agent')
|
17
|
-
|
18
|
-
q = bunny.queue(errorQueueName)
|
19
|
-
|
20
|
-
number_of_messages = 0
|
21
|
-
loop = true
|
22
|
-
while loop do
|
23
|
-
msg = q.pop[:payload]
|
24
|
-
if msg == :queue_empty then
|
25
|
-
loop = false
|
26
|
-
else
|
27
|
-
number_of_messages++
|
28
|
-
|
29
|
-
msg = YAML::load(msg)
|
30
|
-
|
31
|
-
queueName = msg.getLastErrorMsg.sourceQueue
|
32
|
-
sq = bunny.queue(queueName)
|
33
|
-
sq.bind(@direct_exchange)
|
34
|
-
#q.publish( serialized_object )
|
35
|
-
|
36
|
-
@direct_exchange.publish(msg)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
if number_of_messages == 0 then
|
42
|
-
puts "Nothing waiting on RabbitMq error queue"
|
43
|
-
else
|
44
|
-
|
45
|
-
puts "Returned #{number_of_messages} to their source queue"
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
rescue Bunny::ConnectionError, Bunny::ServerDownError => e
|
50
|
-
abort( "RabbitMq not running" )
|
51
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module RServiceBus
|
2
|
-
require 'bunny'
|
3
|
-
|
4
|
-
#A means for a stand-alone process to interact with the bus, without being a full
|
5
|
-
#rservicebus application
|
6
|
-
class Agent_Bunny
|
7
|
-
@bunny
|
8
|
-
|
9
|
-
def initialize(host='localhost')
|
10
|
-
@bunny = Bunny.new(:host=>host)
|
11
|
-
@bunny.start
|
12
|
-
@direct_exchange = @bunny.exchange('rservicebus.agent')
|
13
|
-
end
|
14
|
-
|
15
|
-
# Put a msg on the bus
|
16
|
-
#
|
17
|
-
# @param [Object] messageObj The msg to be sent
|
18
|
-
# @param [String] queueName the name of the queue to be send the msg to
|
19
|
-
# @param [String] returnAddress the name of a queue to send replies to
|
20
|
-
def sendMsg(messageObj, queueName, returnAddress=nil)
|
21
|
-
msg = RServiceBus::Message.new( messageObj, returnAddress )
|
22
|
-
serialized_object = YAML::dump(msg)
|
23
|
-
|
24
|
-
q = @bunny.queue(queueName)
|
25
|
-
q.bind(@direct_exchange)
|
26
|
-
#q.publish( serialized_object )
|
27
|
-
|
28
|
-
@direct_exchange.publish(serialized_object)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Gives an agent a mean to receive replies
|
32
|
-
#
|
33
|
-
# @param [String] queueName the name of the queue to monitor for messages
|
34
|
-
def checkForReply( queueName )
|
35
|
-
q = @bunny.queue(queueName)
|
36
|
-
|
37
|
-
loop = true
|
38
|
-
while loop do
|
39
|
-
msg = q.pop[:payload]
|
40
|
-
loop = ( msg == :queue_empty )
|
41
|
-
end
|
42
|
-
|
43
|
-
@msg = YAML::load(msg)
|
44
|
-
return @msg.msg
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/lib/rservicebus/MQ/Bunny.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module RServiceBus
|
2
|
-
|
3
|
-
require "bunny"
|
4
|
-
require "rservicebus/MQ"
|
5
|
-
|
6
|
-
# RabbitMQ client implementation.
|
7
|
-
#
|
8
|
-
class MQ_Bunny<MQ
|
9
|
-
@uri
|
10
|
-
|
11
|
-
# Connect to the broker
|
12
|
-
#
|
13
|
-
def connect( host, port )
|
14
|
-
port ||= 5672
|
15
|
-
|
16
|
-
@bunny = Bunny.new(:host=>host, :port=>port)
|
17
|
-
@bunny.start
|
18
|
-
@pop_exch = @bunny.exchange('rservicebus.pop')
|
19
|
-
@send_exch = @bunny.exchange('rservicebus.send')
|
20
|
-
end
|
21
|
-
|
22
|
-
# Connect to the queue
|
23
|
-
#
|
24
|
-
def subscribe( queueName )
|
25
|
-
@queue = @bunny.queue( queueName )
|
26
|
-
@queue.bind( @pop_exch );
|
27
|
-
end
|
28
|
-
|
29
|
-
# Get next msg from queue
|
30
|
-
def pop
|
31
|
-
msg = @queue.pop(:ack => true)[:payload]
|
32
|
-
|
33
|
-
if msg == :queue_empty then
|
34
|
-
raise NoMsgToProcess.new
|
35
|
-
end
|
36
|
-
|
37
|
-
return msg
|
38
|
-
end
|
39
|
-
|
40
|
-
# "Commit" the pop to the queue
|
41
|
-
def ack
|
42
|
-
@queue.ack
|
43
|
-
end
|
44
|
-
|
45
|
-
# Send a msg to a queue
|
46
|
-
def send( queueName, msg )
|
47
|
-
queue = @bunny.queue(queueName)
|
48
|
-
queue.bind(@send_exch)
|
49
|
-
@send_exch.publish(msg)
|
50
|
-
queue.unbind(@send_exch)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|