Remote Procedure Calls are deepstreamHub’s request-response mechanism. Clients and backend processes can register as “providers” for a given RPC, identified by a unique name. Other endpoints can request said RPC.
deepstreamHub will route requests to the right provider, load-balance between multiple providers for the same RPC, and handle data-serialisation and transport.
argument | type | optional | description |
---|---|---|---|
name | String | false | The name of the RPC. Each client can only register as a provider for an RPC name once. |
callback | Function | false | A function that handles incoming RPCs. Will be called with data and an RPC response object. |
Registers the client as a provider for incoming RPCs of a specific name. The callback will be invoked when another client calls client.rpc.make()
.
client.rpc.provide( 'add-two-numbers', function( data, response ){
response.send( data.numA + data.numB );
});
Info
-
Only one callback per client can be registered for the same RPC
Data can be any serializable object
Documentation for theresponse
object can be found here
client.rpc.unprovide( name )
argument | type | optional | description |
---|---|---|---|
name | String | false | The name of the RPC. |
Removes the client as a provider previously registered using provide()
.
client.rpc.unprovide( 'add-two-numbers' );
client.rpc.make( name, data, callback )
argument | type | optional | description |
---|---|---|---|
name | String | false | rpcname |
data | Mixed | true | Any serialisable data ( Objects, Strings, Numbers... ) that will be send with the rpc |
Executes a remote procedure call. callback
will be invoked with the returned result or with an error if the RPC failed.
client.rpc.make( 'add-two-numbers', { numA:4, numB: 7 }, ( error, result ) => {
// error = null, result = 11
});