-
Notifications
You must be signed in to change notification settings - Fork 110
Remote service
fantasyni edited this page May 9, 2014
·
1 revision
Bearcat provides remote support for handling rpc remote service, it is support by Bearcat-remote
Bearcat-remote provides rpc remote support wrapped on Bearcat and rpc library like dnode. It makes it easy to use rpc remote in node.js.
npm install bearcat-remote --save
{
"name": "bearcat-remote",
"dependencies": {
"bearcat-remote": "*"
}
}
- Exporting the service using the dnodeServiceExporter Of cource, we first have to set up our service in Bearcat IoC container:
remoteService.js
var remoteService = function() {
}
remoteService.prototype.remotePing = function(ping, cb) {
console.log(ping);
cb('pong');
}
module.exports = remoteService;
{
"id": "remoteService",
"func": "remoteService"
}
Next we’ll have to expose our service using the dnodeServiceExporter:
{
"id": "dnodeServiceExporter",
"func": "node_modules.bearcat-remote.lib.remote.dnode.dnodeServiceExporter",
"props": [{
"name": "service",
"ref": "remoteService"
}, {
"name": "port",
"value": 8003
}, {
"name": "host",
"value": "localhost"
}]
}
- Linking in the service at the client Exposing our service using the dnodeDynamicProxy:
{
"id": "dnodeClient",
"func": "node_modules.bearcat-remote.lib.remote.dnode.dnodeDynamicProxy",
"init": "dyInit",
"async": true,
"destroy": "dyDestroy",
"props": [{
"name": "serviceHost",
"value": "localhost"
}, {
"name": "servicePort",
"value": 8003
}, {
"name": "serviceInterface",
"value": ["remotePing"]
}]
}
var Bearcat = require('bearcat');
var simplepath = require.resolve('./context.json');
var paths = [simplepath];
var bearcat = Bearcat.createApp(paths);
bearcat.start(function() {
var dnodeClient = bearcat.getBean('dnodeClient');
dnodeClient.remotePing('ping', function(msg) {
console.log(msg); // pong
});
});