Class: Rddd::Services::RemoteService
- Defined in:
- lib/rddd/services/remote_service.rb
Overview
Remote service is the way to execute logic on different application. Currently JSON encoded, HTTP based transport is supported. In future there is a plan for more generic RPC support.
Usage:
# Configure the remote endpoint.
Rddd.configure do |config|
config.remote_services = [
{:namespace => 'projects', :endpoint => 'http://products.dev/'}
]
end
# Execute service
class Test < Sinatra:Base
get '/:account_id/projects' do
execute_service(:projects__list, params[:account_id])
end
end
# Finally here is the remote app
class Projects < Sinatra:Base
post ':service_name' do
execute_service(params[:service_name], request.body)
end
end
As you can see remote app uses the service bus as well. This architecture would allow you pull part of your application to separate box without need for any change in your client or services code base.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(transport, service_name, attributes) ⇒ RemoteService
constructor
A new instance of RemoteService.
Methods inherited from Service
Constructor Details
#initialize(transport, service_name, attributes) ⇒ RemoteService
Returns a new instance of RemoteService.
41 42 43 44 45 46 |
# File 'lib/rddd/services/remote_service.rb', line 41 def initialize(transport, service_name, attributes) super(attributes) @transport = transport @service_name = service_name end |
Class Method Details
.build(namespace, service_name, attributes = {}) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/rddd/services/remote_service.rb', line 52 def self.build(namespace, service_name, attributes = {}) RemoteService.new( Transports::Factory.build(namespace), service_name, attributes ) end |
Instance Method Details
#execute ⇒ Object
48 49 50 |
# File 'lib/rddd/services/remote_service.rb', line 48 def execute @transport.call(@service_name, @attributes) end |