Table of Contents
$ npm install @henson/distributed
import {discovery} from '@henson/distributed';
http://henson-book.sh.cn.ao.henson.se/design/service-coordination/
import {TaskCoordinator} from '@henson/distributed';
http://henson-book.sh.cn.ao.henson.se/design/service-discovery/
import {kv} from '@henson/distributed';
Option: MasterElectionOption
-
interval: number
- Election interval, in seconds
Example:
import {MasterElection} from '@henson/distributed';
// @param service: string - unique identity of the service
// @param option: { interval: number }
let test = new MasterElection('datacleanup', { interval: 10 });
test.start();
// check if it is the master
if (test.isMaster()) {
//do something
}
// stop when quit
test.stop();
import {ServiceInfo, getServiceInfo} from '@henson/distributed';
let serviceInfo: ServiceInfo = await getServiceInfo('servicename', 1);
method:
getBucketOwners(servicename:string):ServiceInfo[]
It return array of ServiceInfo which have structure like this:
ServiceInfo { Tags: string[]; Address: string; Port: number; }
import {getBucketOwners} from '@henson/distributed';
const nodes = await getBucketOwners('connectivitymanager');
if(serviceInfos.length > 0){
const ip = nodes[0].Address;
const port = nodes[0].Port;
...
}