13.0.4 • Published 1 day ago

happner-cluster v13.0.4

Weekly downloads
98
License
MIT
Repository
github
Last release
1 day ago

npmBuild StatusCoverage Status

happner-cluster

Extends happner with clustering capabilities.

Install

npm install happner-cluster happn-service-mongo-2 —save

Note data service installed separately.

Starting a cluster node

Happner-cluster and happner configs are almost identical excpet that cluster nodes should include a domain name and the happn subconfigs necessary for clustering - as minimum shown below.

For more on happn-cluster subconfig see happn-cluster docs

var HappnerCluster = require('happner-cluster');

var config = {
  
  // name: 'UNIQUE_NAME', // allow default uniqie name
  domain: 'DOMAIN_NAME', // same as other cluster nodes
  
  cluster: {
    //  requestTimeout: 20 * 1000, // exchange timeouts
    //  responseTimeout: 30 * 1000
  },
  
  happn: { // was "datalayer"
    services: {
      data: {
        // see data sub-config in happn-cluster docs
        config: {
          datastores: [
            // defaulted by happn-cluster
            //{
            //  name: 'mongo',
            //  provider: 'happn-service-mongo-2',
            //  isDefault: true,
            //  settings: {
            //    collection: 'happn-cluster',
            //    database: 'happn-cluster',
            //    url: 'mongodb://127.0.0.1:27017'
            //    url: 'mongodb://username:password@127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/happn?replicaSet=test-set&ssl=true&authSource=admin'
            //  }
            //},
            
            // defaulted by happner-cluster to prevent overwrites in shared db
            // where each cluster server requires unique data at certain paths
            //{
            //  name: 'nedb-own-schema',
            //  settings: {},
            //  patterns: [
            //    '/mesh/schema/*',
            //    '/_SYSTEM/_NETWORK/_SETTINGS/NAME',
            //    '/_SYSTEM/_SECURITY/_SETTINGS/KEYPAIR'
            //  ]
            //}
          ]
        }
      }
      membership: {
        // see membership sub-config in happn-cluster docs
      }
    }
  },
    
  modules: {
  },
    
  components: {
  }
}

HappnerCluster.create(config).then...

Using remote components in the cluster

A component that wishes to use non-local components whose instances reside elsewhere in the cluster should declare the dependencies in their package.json

Given a clusternode with component1...

config = {
  modules: {
    'component1': {
      // using most complex example of module which defines multiple component classes
      path: 'node-module-name',
      construct: {
        name: 'Component1'
      }
    }
  },
  components: {
    'component1': {...}
  }
}

…to enable component1 to use remote components from elsewhere in the cluster...

Component1.prototype.method = function ($happner, callback) {
  // $happner aka $happn
  // call remote component not defined locally
  $happner.exchange['remote-component'].method1(function (e, result) {
    callback(e, result);
  });
  
  // also
  // $happner.event['remote-component'].on() .off() .offPath()
}

…it should declare the dependency in its package.json file…

// package.json expressed as js
{
  name: 'node-module-name',
  version: '1.0.0',
  happner: {
    dependencies: {
      'component1': { // the component name which has the dependencies
                      // (allows 1 node_module to define more than 1 mesh component class)
        'remote-component': {
          version: '^1.0.0', // will only use matching versions from 
                             // elsewhefre in the cluster
          methods: { // list of methods desired on the remote compnoent
            method1: {},
            method2: {}
          }
        },
        'remote-component2': {
          version: '~1.0.0'
          // no methods, only interested in events
        }
      }
    }
  }
}

Note:

  • If a component is defined locally and remotely then local is preferred and remote never used.
  • If the component is defined on multiple remote nodes, a round-robin is performed on the method calls.
13.0.4

1 month ago

13.0.1-prerelease-1

10 months ago

13.0.2

10 months ago

13.0.3

9 months ago

13.0.0

12 months ago

13.0.1

10 months ago

12.4.3

1 year ago

12.5.0

1 year ago

12.4.1

1 year ago

12.4.2

1 year ago

12.4.0

1 year ago

12.3.6

1 year ago

12.3.4

1 year ago

12.3.5

1 year ago

12.3.0

2 years ago

12.3.1

2 years ago

12.3.2

2 years ago

12.3.3

1 year ago

12.2.1

2 years ago

12.2.2

2 years ago

12.2.3

2 years ago

12.2.0

2 years ago

12.1.6

2 years ago

12.1.7

2 years ago

12.1.8

2 years ago

12.1.9

2 years ago

12.1.5

2 years ago

12.1.2

2 years ago

12.1.3

2 years ago

12.1.4

2 years ago

12.0.3

2 years ago

12.0.4

2 years ago

12.0.5

2 years ago

12.0.6

2 years ago

12.1.0

2 years ago

12.1.1

2 years ago

12.0.0

2 years ago

12.0.1

2 years ago

12.0.2

2 years ago

11.2.4

2 years ago

11.2.5

2 years ago

11.2.2

2 years ago

11.2.3

2 years ago

11.2.6

2 years ago

11.2.7

2 years ago

11.2.0

2 years ago

11.2.1

2 years ago

11.4.0

2 years ago

11.3.1

2 years ago

11.3.0

2 years ago

11.1.1

2 years ago

11.1.0

2 years ago

11.0.2

3 years ago

11.0.3

3 years ago

11.0.1

3 years ago

11.0.0

3 years ago

10.5.0

3 years ago

10.4.2

3 years ago

10.4.1

3 years ago

10.4.0

3 years ago

10.3.1

3 years ago

10.3.0

3 years ago

10.2.0

3 years ago

10.1.0

3 years ago

10.0.0

4 years ago

9.0.10

4 years ago

9.0.9

4 years ago

9.0.8

4 years ago

9.0.7

4 years ago

9.0.6

4 years ago

9.0.5

4 years ago

9.0.5-test2

4 years ago

9.0.5-test

4 years ago

9.0.4

4 years ago

9.0.3

4 years ago

9.0.2

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.3.0

5 years ago

8.2.2

5 years ago

8.2.1

5 years ago

8.2.0

5 years ago

8.1.3

5 years ago

8.1.2

5 years ago

8.1.1

5 years ago

8.1.0

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

7.3.0

5 years ago

7.2.0

5 years ago

7.1.0

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.1.0

6 years ago

6.0.1-beta.1

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.0

6 years ago

5.0.0-beta.1

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.5.0

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago