rservicebus 0.0.75 → 0.0.76

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.
@@ -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
+
@@ -6,6 +6,14 @@ module RServiceBus
6
6
  # <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
7
7
  class EndpointMapping
8
8
 
9
+ def getValue( name )
10
+ return RServiceBus.getValue( name )
11
+ end
12
+
13
+ def log( string, ver=false )
14
+ RServiceBus.log( string )
15
+ end
16
+
9
17
  def configureMapping( mapping )
10
18
  match = mapping.match( /(.+):(.+)/ )
11
19
  if match.nil? then
@@ -15,23 +23,23 @@ module RServiceBus
15
23
  exit()
16
24
  end
17
25
 
18
- RServiceBus.log( "EndpointMapping.configureMapping: #{match[1]}, #{match[2]}", true )
26
+ self.log( "EndpointMapping.configureMapping: #{match[1]}, #{match[2]}", true )
19
27
  @endpoints[match[1]] = match[2]
20
-
28
+
21
29
  end
22
30
 
23
31
  def Configure
24
- RServiceBus.log( "EndpointMapping.Configure" )
25
- mappings = RServiceBus.getValue( "MESSAGE_ENDPOINT_MAPPINGS" )
32
+ self.log( "EndpointMapping.Configure" )
33
+ mappings = self.getValue( "MESSAGE_ENDPOINT_MAPPINGS" )
26
34
  return self if mappings.nil?
27
-
35
+
28
36
  mappings.split( ";" ).each do |mapping|
29
37
  self.configureMapping( mapping )
30
38
  end
31
39
 
32
40
  return self
33
41
  end
34
-
42
+
35
43
  def initialize
36
44
  @endpoints=Hash.new
37
45
  end
@@ -41,7 +41,7 @@ module RServiceBus
41
41
  puts "[#{type}] #{timestamp} :: #{string}"
42
42
  end
43
43
  end
44
-
44
+
45
45
  #Thin veneer for Configuring external resources
46
46
  #
47
47
  def configureAppResource
@@ -344,6 +344,15 @@ module RServiceBus
344
344
  # @param [String] queueName endpoint to which the msg will be sent
345
345
  def _SendNeedsWrapping( msg, queueName )
346
346
  log "Bus._SendNeedsWrapping", true
347
+
348
+ if queueName.index( "@" ).nil? then
349
+ @mq.send( queueName, serialized_object )
350
+ else
351
+ parts = queueName.split( "@" )
352
+ msg.setRemoteQueueName( parts[0] )
353
+ msg.setRemoteHostName( parts[1] )
354
+ @mq.send( 'transport-out', serialized_object )
355
+ end
347
356
 
348
357
  rMsg = RServiceBus::Message.new( msg, @config.localQueueName )
349
358
  serialized_object = YAML::dump(rMsg)
@@ -3,7 +3,7 @@ module RServiceBus
3
3
  #This is the top level message that is passed around the bus
4
4
  class Message
5
5
 
6
- attr_reader :returnAddress, :msgId
6
+ attr_reader :returnAddress, :msgId, :remoteQueueName, :remoteHostName
7
7
 
8
8
  # Constructor
9
9
  #
@@ -38,6 +38,16 @@ class Message
38
38
  return @errorList.last
39
39
  end
40
40
 
41
+
42
+ def setRemoteHostName( hostName )
43
+ @remoteHostName = hostName
44
+ end
45
+
46
+ def setRemoteQueueName( queueName )
47
+ @remoteQueueName = queueName
48
+ end
49
+
50
+
41
51
  # @return [Object] The msg to be sent
42
52
  def msg
43
53
  return YAML::load( @_msg )
@@ -0,0 +1,115 @@
1
+ require 'beanstalk-client'
2
+ require 'rservicebus'
3
+ require 'net/ssh/gateway'
4
+
5
+ module RServiceBus
6
+
7
+ class CouldNotConnectToDestination<StandardError
8
+ end
9
+
10
+
11
+ #ToDo: Poison Message? Can I bury with timeout in beanstalk ?
12
+ #Needs to end up on an error queue, destination queue may be down.
13
+
14
+
15
+ class Transporter
16
+
17
+ def log( string, verbose=false )
18
+ if verbose == false ||
19
+ ( !ENV["VERBOSE"].nil? && ENV["VERBOSE"].upcase == "TRUE") then
20
+ puts string
21
+ end
22
+ end
23
+
24
+ def getValue( name, default=nil )
25
+ value = ( ENV[name].nil? || ENV[name] == "" ) ? default : ENV[name];
26
+ log "Env value: #{name}: #{value}"
27
+ return value
28
+ end
29
+
30
+ def connectToSourceBeanstalk
31
+ sourceQueueName = getValue( 'SOURCE_QUEUE_NAME', "transport-out" )
32
+ sourceUrl = getValue( 'SOURCE_URL', "127.0.0.1:11300" )
33
+ @source = Beanstalk::Pool.new([sourceUrl])
34
+ @source.watch sourceQueueName
35
+
36
+ log "Connected to, #{sourceQueueName}@#{sourceUrl}"
37
+
38
+ rescue Exception => e
39
+ puts "Error connecting to Beanstalk"
40
+ puts "Host string, #{sourceUrl}"
41
+ if e.message == "Beanstalk::NotConnected" then
42
+ puts "***Most likely, beanstalk is not running. Start beanstalk, and try running this again."
43
+ puts "***If you still get this error, check beanstalk is running at, #{sourceUrl}"
44
+ else
45
+ puts e.message
46
+ puts e.backtrace
47
+ end
48
+ abort();
49
+ end
50
+
51
+ def process
52
+ #Get the next job from the source queue
53
+ job = @source.reserve @timeout
54
+ msg = YAML::load(job.body)
55
+
56
+ log "job: #{job.body}", true
57
+
58
+
59
+ #Get destination url from job
60
+ remote_host = 'mega'
61
+ remote_user = getValue( "REMOTE_USER_#{remote_host.upcase}", "beanstalk" )
62
+ gateway = Net::SSH::Gateway.new(remote_host, remote_user)
63
+
64
+ # Open port 27018 to forward to 127.0.0.11300 on the remote host
65
+ gateway.open('127.0.0.1', 11300, 27018)
66
+
67
+ log "Connect to destination beanstalk"
68
+ begin
69
+ destincationUrl = '127.0.0.1:27018'
70
+ destination = Beanstalk::Pool.new([destincationUrl])
71
+ rescue Exception => e
72
+ if e.message == "Beanstalk::NotConnected" then
73
+ puts "***Could not connect to destination, check beanstalk is running at, #{destincationUrl}"
74
+ raise CouldNotConnectToDestination.new
75
+ end
76
+ raise
77
+ end
78
+
79
+
80
+ #getDestinationQueueName
81
+ destinationQueueName = "transportIn"
82
+ queueName = msg.destinationQueueName
83
+
84
+ #putMsg
85
+ log "Put msg, #{job.body}", true
86
+ destination.use( destinationQueueName )
87
+ destination.put( job.body )
88
+
89
+
90
+ #removeJob
91
+ job.delete
92
+
93
+
94
+ gateway.shutdown!
95
+
96
+ rescue Exception => e
97
+ if e.message == "TIMED_OUT" then
98
+ log "No Msg", true
99
+ return
100
+ end
101
+ raise e
102
+ end
103
+
104
+ def Run
105
+ @timeout = getValue( 'TIMEOUT', 5 )
106
+ connectToSourceBeanstalk
107
+ while true
108
+ process
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+ end
115
+
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.75
4
+ version: 0.0.76
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-07-21 00:00:00.000000000 Z
12
+ date: 2013-08-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby interpretation of NServiceBus
15
15
  email: guy@guyirvine.com
@@ -20,6 +20,7 @@ executables:
20
20
  - ReturnErroredMessagesToSourceQueueBeanstalk
21
21
  - ReturnErroredMessagesToSourceQueueBunny
22
22
  - SendEmptyMessage
23
+ - rservicebus-transport
23
24
  extensions: []
24
25
  extra_rdoc_files: []
25
26
  files:
@@ -68,12 +69,14 @@ files:
68
69
  - lib/rservicebus/Test/Bus.rb
69
70
  - lib/rservicebus/Test/Redis.rb
70
71
  - lib/rservicebus/Test.rb
72
+ - lib/rservicebus/Transporter.rb
71
73
  - lib/rservicebus.rb
72
74
  - bin/ReturnErroredMessagesToSourceQueue
73
75
  - bin/ReturnErroredMessagesToSourceQueueBeanstalk
74
76
  - bin/ReturnErroredMessagesToSourceQueueBunny
75
77
  - bin/rservicebus
76
78
  - bin/rservicebus-init
79
+ - bin/rservicebus-transport
77
80
  - bin/SendEmptyMessage
78
81
  - LICENSE
79
82
  - README.md