node-pigeon-client
This module is designed to resemble the Pigeon Java client API but with tweaks to follow the convention of Node.js modules. Develops that are familiar with the Pigeon Java client would be able to pick it up quickly.
This module has been tested to work with Pigeon version 2.3.10.
Getting Started
- Install node.
- Install node-pigeon-client using npm:
$ npm install node-pigeon-client --save
- An environment configuration file
/data/webapps/appenv
should be provided in the given format
deployenv = qa # Environment.
zkserver = 127.0.0.1:2181 # Zookeeper host and port.
Example
Remote service "EchoService":
Call the remote service "EchoService":
var pigeon = ;var java = java; var url = 'EchoService'; // Remote service url.pigeon;
Documentation
getService(url, [options], callback)
Retrieve the service of the given url.
Arguments
-
url
String
- The service url. -
options
Object
- An object to set the service retrive options. Currently available options are:zkserver
: Comma seperatedhost:port
pairs, each represents a Zookeeper server. e.g.
'127.0.0.1:2181, 127.0.0.1:2182, 127.0.0.1:2183'timeout
Remote service method call timeout in milliseconds.protocol
Protocol of remote service method call.serialize
Serailization of network transmission.timeoutRetry
Whether to retry when timeout.retries
The number of retry attempts for timeout.loadBalance
Type of remote service server load balance.
Default options:
zkserver : '127.0.0.1:2181' // Can also set in '/data/webapps/appenv'.timeout : 1000protocol : 'http' // http.serialize : 'hessian' // hessian.timeoutRetry: true // true/falseretries : 1loadBalance : 'autoaware' // autoaware/roundRobin/random -
callback(err, service)
Function
- The callback function. Theservice
can be regarded as an object containing all the service methods that can be called.
Java Types Supported
- null
- int
- long
- double
- boolean
- java.lang.Integer
- java.lang.Long
- java.lang.Double
- java.lang.Boolean
- java.lang.String
- java.lang.Object
- java.util.List
- java.util.Set
- java.util.Date
- array
- user-defined
java.null()
Example
Object a = null;
var a = java
java.int(jsNumber)
Example
int a = 123;
var a = java;
java.long(jsNumber)
Example
long a = 123;
var a = java;
java.double(jsNumber)
Example
double a = 1.23;
var a = java;
java.boolean(jsBoolean)
Example
boolean a = true;
var a = java;
java.Integer(jsNumber)
Example
java.lang.Integer a = new java.lang.Integer(123);
var a = java;
java.Long(jsNumber)
Example
java.lang.Long a = new java.lang.Long(123);
var a = java;
java.Double(jsNumber)
Example
java.lang.Double a = new java.lang.Double(1.23);
var a = java;
java.Boolean(jsBoolean)
Example
java.lang.Boolean a = new java.lang.Boolean(true);
var a = java;
java.String(jsString)
Example
java.lang.String a = new java.lang.String('123');
var a = java;
java.Object(jsObject)
Example
public Class Car { private String name; private int money; private ArrayList<Integer> wheelSize = new ArrayList<Integer>(); public { this.name = name; this.money = money; this.wheelSize = wheelSize; }} java.lang.Object a = new Car("Benz", 123, new ArrayList([1, 2, 3, 4]));
var a = java;
java.List.Generics(jsArray)
Generics
represents the following types:
- int
- long
- double
- boolean
- java.lang.Integer
- java.lang.Long
- java.lang.Double
- java.lang.Boolean
- java.lang.String
- java.lang.Object
- java.util.Date
- user-defined
Example
List<String> a = new ArrayList(["a", "b", "c"]);
var a = javaList;
java.Set.Generics(jsArray)
See java.List.Generics(jsArray).
java.array.Generics(jsArray)
See java.List.Generics(jsArray).
java.Date(jsDate)
Example
java.util.Date a = new java.util.Date();
var a = java;
java.Class(classname, jsObject)
Example
public Class Car { private String name; private int money; private ArrayList<Integer> wheelSize = new ArrayList<Integer>(); public { this.name = name; this.money = money; this.wheelSize = wheelSize; }} packagename.Car a = new packagename.Car("Benz", 123, new ArrayList([1, 2, 3, 4]));
var a = java