@henson/distributed
TypeScript icon, indicating that this package has built-in type declarations

4.1.4 • Public • Published

Henson Library for Distributed Service

Table of Contents

Install

$ npm install @henson/distributed

Design and Usage

Service Discovery

import {discovery} from '@henson/distributed';

http://henson-book.sh.cn.ao.henson.se/design/service-coordination/

Task Coordinator

import {TaskCoordinator} from '@henson/distributed';

http://henson-book.sh.cn.ao.henson.se/design/service-discovery/

Consul KV API

import {kv} from '@henson/distributed';

Master Election API

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

Get bucket's ip

import {ServiceInfo, getServiceInfo} from '@henson/distributed';

let serviceInfo: ServiceInfo = await getServiceInfo('servicename', 1);

Get nodes(running task coordinator for specified service) that owns at least 1 bucket

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

Readme

Keywords

none

Package Sidebar

Install

npm i @henson/distributed

Weekly Downloads

0

Version

4.1.4

License

UNLICENSED

Unpacked Size

162 kB

Total Files

46

Last publish

Collaborators

  • henson