xcomet-client
v0.1.4
Published
## Usage
Downloads
1
Readme
xcomet-client
Usage
$ npm install --save xcomet-client
var xcomet_client = require('xcomet-client');
var node1 = new xcomet_client.NodeInfo('192.168.2.3', '127.0.0.1', 9000, 9001);
var node2 = new xcomet_client.NodeInfo('192.168.2.3', '127.0.0.1', 9002, 9003);
var node3 = new xcomet_client.NodeInfo('192.168.2.3', '127.0.0.1', 9004, 9005);
var client = new xcomet_client.XCometClient([node1, node2, node3]);
var toUser = process.argv[2];
var fromUser = process.argv[3];
var message = process.argv[4];
// get user shard info
var node_info = client.shard(toUser);
console.log('shard for the user is: ' + require('util').inspect(node_info));
// pub to user
client.pub({to: toUser, from: fromUser, msg: message}, function(err, resp) {
if (err) {
console.log('pub err: ' + err);
} else {
console.log('pub result: ' + resp);
}
});
// pub a message with ttl
client.pub({to: toUser, from: fromUser, msg: message, ttl: 10}, function(err, resp) {
if (err) {
console.log('pub err: ' + err);
} else {
console.log('pub result: ' + resp);
}
});
Parameters
NodeInfo
- public host name, ** required **
- local host name, ** required **
- client port, ** required **
- admin port, ** require **
- if the node in local network, ** optional **, defalut is true
XCometClient
- Array of NodeInfo, ** required **
- sharding option, ** optional **, see
sharding
module for detail
XCometClient.shard
- user_id, ** required **
return: NodeInfo instance
XCometClient.pub
- option, ** required **, {to: '', from: '', msg: '', ttl: ''}
ttl
field is optional - callback, ** required **