Skip to content
fantasyni edited this page May 9, 2014 · 1 revision

Overview

Bearcat provides remote support for handling rpc remote service, it is support by Bearcat-remote

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.

Install

npm install bearcat-remote --save

Add context.json configuration metadata

{
	"name": "bearcat-remote",
	"dependencies": {
	    "bearcat-remote": "*"
	}
}

rpc remote

Exposing services using dnode

  • 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"]
	}]
}

Startup Bearcat and run it

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
	});
});