hoth 0.3.1 → 0.3.2.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hoth/encoding/json.rb +3 -3
- data/lib/hoth/modules.rb +5 -1
- data/lib/hoth/providers/beanstalkd_provider.rb +48 -0
- data/lib/hoth/service_module.rb +6 -2
- data/lib/hoth/transport.rb +7 -1
- data/lib/hoth/transport/beanstalkd.rb +24 -0
- metadata +42 -9
data/lib/hoth/encoding/json.rb
CHANGED
data/lib/hoth/modules.rb
CHANGED
@@ -11,6 +11,10 @@ module Hoth
|
|
11
11
|
def self.module(module_name)
|
12
12
|
instance.service_modules[module_name]
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.service_modules
|
16
|
+
instance.service_modules
|
17
|
+
end
|
14
18
|
|
15
19
|
def service_module(module_name, &block)
|
16
20
|
service_module = ServiceModule.new(:name => module_name)
|
@@ -24,4 +28,4 @@ module Hoth
|
|
24
28
|
@service_modules = {}
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
begin
|
2
|
+
require 'em-jack'
|
3
|
+
rescue LoadError
|
4
|
+
STDERR.puts "You need the 'em-jack' gem if you want to use Beanstalkd provider."
|
5
|
+
end
|
6
|
+
|
7
|
+
module Hoth
|
8
|
+
module Providers
|
9
|
+
|
10
|
+
class BeanstalkdProvider
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@services_to_listen_for = Hoth::Modules.service_modules.values.inject([]) do |services, service_module|
|
14
|
+
services << service_module.registered_services.select do |service|
|
15
|
+
service.endpoint.transport == :beanstalkd
|
16
|
+
end
|
17
|
+
services.flatten
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def listen
|
22
|
+
EM.run {
|
23
|
+
@services_to_listen_for.each do |service|
|
24
|
+
conn_for_service = EMJack::Connection.new(:host => service.endpoint.host, :port => service.endpoint.port)
|
25
|
+
conn_for_service.watch("#{service.endpoint.module_name}/#{service.name}")
|
26
|
+
conn_for_service.each_job do |job|
|
27
|
+
responsible_service = ServiceRegistry.locate_service(service.name)
|
28
|
+
|
29
|
+
raise ServiceNotFoundException.new("The requested service '#{service.name}' was not found!") if responsible_service.nil?
|
30
|
+
|
31
|
+
begin
|
32
|
+
decoded_params = responsible_service.transport.encoder.decode(job.body)
|
33
|
+
Rails.logger.debug "decoded_params: #{decoded_params}"
|
34
|
+
Hoth::Services.send(service.name, *decoded_params)
|
35
|
+
rescue => e
|
36
|
+
Rails.logger.warn "An error occured while invoking the service: #{e.message}"
|
37
|
+
ensure
|
38
|
+
conn_for_service.delete(job)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/hoth/service_module.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Hoth
|
2
2
|
class ServiceModule
|
3
|
-
attr_accessor :name, :environments
|
4
3
|
|
5
4
|
class Environment
|
6
5
|
attr_accessor :endpoints
|
@@ -19,8 +18,11 @@ module Hoth
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
21
|
+
attr_accessor :name, :environments, :registered_services
|
22
|
+
|
22
23
|
def initialize(attributes = {})
|
23
24
|
@environments = {}
|
25
|
+
@registered_services = []
|
24
26
|
@name = attributes[:name]
|
25
27
|
end
|
26
28
|
|
@@ -39,6 +41,8 @@ module Hoth
|
|
39
41
|
|
40
42
|
service.module = self
|
41
43
|
service.via_endpoint(options[:via])
|
44
|
+
|
45
|
+
@registered_services << service
|
42
46
|
end
|
43
47
|
|
44
48
|
def [](env_name)
|
@@ -46,4 +50,4 @@ module Hoth
|
|
46
50
|
end
|
47
51
|
|
48
52
|
end
|
49
|
-
end
|
53
|
+
end
|
data/lib/hoth/transport.rb
CHANGED
@@ -3,6 +3,7 @@ require 'hoth/transport/http'
|
|
3
3
|
require 'hoth/transport/https'
|
4
4
|
require 'hoth/transport/bert'
|
5
5
|
require 'hoth/transport/workling'
|
6
|
+
require 'hoth/transport/beanstalkd'
|
6
7
|
|
7
8
|
require 'hoth/encoding/json'
|
8
9
|
require 'hoth/encoding/no_op'
|
@@ -25,6 +26,11 @@ module Hoth
|
|
25
26
|
|
26
27
|
:workling => {
|
27
28
|
:transport_class => Transport::Workling
|
29
|
+
},
|
30
|
+
|
31
|
+
:beanstalkd => {
|
32
|
+
:transport_class => Transport::Beanstalkd,
|
33
|
+
:encoder => Encoding::Json
|
28
34
|
}
|
29
35
|
}
|
30
36
|
|
@@ -47,4 +53,4 @@ module Hoth
|
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
50
|
-
end
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'beanstalk-client'
|
3
|
+
rescue LoadError
|
4
|
+
STDERR.puts "You need the 'beanstalk-client' gem if you want to use Beanstalkd transport."
|
5
|
+
end
|
6
|
+
|
7
|
+
module Hoth
|
8
|
+
module Transport
|
9
|
+
|
10
|
+
class Beanstalkd < Base
|
11
|
+
|
12
|
+
def call_remote_with(*args)
|
13
|
+
connection = Beanstalk::Pool.new(["#{endpoint.host}:#{endpoint.port}"])
|
14
|
+
connection.use("#{endpoint.module_name}/#{name}")
|
15
|
+
|
16
|
+
encoded_args = encoder.encode(args)
|
17
|
+
Rails.logger.debug "encoded_args: #{encoded_args}"
|
18
|
+
connection.put encoded_args
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -1848230051
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
|
9
|
+
- 2
|
10
|
+
- beta1
|
11
|
+
version: 0.3.2.beta1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Dirk Breuer
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-01-
|
19
|
+
date: 2011-01-06 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -88,6 +89,34 @@ dependencies:
|
|
88
89
|
version: "0"
|
89
90
|
type: :development
|
90
91
|
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: beanstalk-client
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
type: :development
|
105
|
+
version_requirements: *id006
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: em-jack
|
108
|
+
prerelease: false
|
109
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
type: :development
|
119
|
+
version_requirements: *id007
|
91
120
|
description: |
|
92
121
|
Creating a SOA requires a centralized location to define all services within the
|
93
122
|
SOA. Furthermore you want to know where to deploy those services.
|
@@ -112,6 +141,7 @@ files:
|
|
112
141
|
- lib/hoth/exceptions.rb
|
113
142
|
- lib/hoth/extension/core/exception.rb
|
114
143
|
- lib/hoth/modules.rb
|
144
|
+
- lib/hoth/providers/beanstalkd_provider.rb
|
115
145
|
- lib/hoth/providers/bertrpc_provider.rb
|
116
146
|
- lib/hoth/providers/rack_provider.rb
|
117
147
|
- lib/hoth/service.rb
|
@@ -121,6 +151,7 @@ files:
|
|
121
151
|
- lib/hoth/services.rb
|
122
152
|
- lib/hoth/transport.rb
|
123
153
|
- lib/hoth/transport/base.rb
|
154
|
+
- lib/hoth/transport/beanstalkd.rb
|
124
155
|
- lib/hoth/transport/bert.rb
|
125
156
|
- lib/hoth/transport/http.rb
|
126
157
|
- lib/hoth/transport/https.rb
|
@@ -162,12 +193,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
194
|
none: false
|
164
195
|
requirements:
|
165
|
-
- - "
|
196
|
+
- - ">"
|
166
197
|
- !ruby/object:Gem::Version
|
167
|
-
hash:
|
198
|
+
hash: 25
|
168
199
|
segments:
|
169
|
-
-
|
170
|
-
|
200
|
+
- 1
|
201
|
+
- 3
|
202
|
+
- 1
|
203
|
+
version: 1.3.1
|
171
204
|
requirements: []
|
172
205
|
|
173
206
|
rubyforge_project:
|