JSPM

brick-cluster-client

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q36068F
  • License MIT

cluster-client package for brick-engine

Package Exports

  • brick-cluster-client

Readme

brick-cluster-client

基于brick-enginecluster-client工具包.用于给brick-engine多进程应用程序提供Leader/Follower功能支持.

+--------+   +--------+
| Client |   | Client |   ...
+--------+   +--------+
    |  \     /   |
    |    \ /     |
    |    / \     |
    |  /     \   |
+--------+   +--------+
| Server |   | Server |   ...
+--------+   +--------+

Install

npm install --save brick-cluster-client

Usage

const { defineProviderFactory } = require('brick-engine');
const {RegistryClient, clusterClientSetup, defineListener } = require('brick-cluster-client');

class Agent {
  /**
   * 代理进程模块构建函数
   * @param {RegistryClient} registry
   */
  constructor(registry) {
    this.registry = registry;
  }

  onAgentEvent(reg) {
    console.log(`Agent Event ${JSON.stringify(reg)}`);
    this.registry.publish({ eventName: 'worker', msg: 'publish with agent' });
  }

}

exports.Agent = Agent;

// 定义Agent对象构建工厂
defineProviderFactory(Agent, { deps: [{ id: RegistryClient }] });

// 定义绑定监听事件
defineListener(Agent, { reg: { eventName: 'agent' }, method: 'onAgentEvent' });

// 安装RegistryClient,以及监听器插件
clusterClientSetup(Agent, { registry: { isLeader: true, isBroadcast: true } });

Documentations

使用jsdoc生成注释文档

git clone https://github.com/kiba-zhao/brick-cluster-client.git
cd brick-cluster
npm install
npm run docs
open docs/index.html

License

MIT