@henson/distributed
Henson library for distributed service
Last updated a year ago by henson .
UNLICENSED · Repository · Original npm · Tarball · package.json
$ cnpm install @henson/distributed 
SYNC missed versions from official npm registry.

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

Current Tags

  • 4.1.4                                ...           latest (a year ago)

1 Versions

  • 4.1.4                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |