moleculerjs / moleculer-agent

:vertical_traffic_light: [PoC] Agent to control your Moleculer nodes remotely
MIT License
4 stars 3 forks source link
agent microservices moleculer

Moleculer logo

[PoC] Moleculer Agent NPM version

Proof-of-Concept project. Don't use it in production!

Concept

  1. Your Moleculer microservices project is a monorepo. Every services are in one repository.
  2. You are running multiple instances on multiple servers.
  3. Any services can run on any servers.
  4. Create a Docker image from project source which starts Moleculer broker without services, except Agent service.
  5. Agent Service Manager (ASM) watches the connected bare nodes and distributes the services by a configuration.
  6. You can dynamically scaling up or down services with Manager or turn on the Autopilot mode.
  7. Agent can update the project repository (pull, checkout by branch, tag, commit hash). Reload all services or reload the process.

Example video how you can start/stop services on remote nodes with agent from Moleculer CLI: Video

Usage

Bare node starter script

"use strict";

const { ServiceBroker } = require("moleculer");
const { Agent }         = require("../");

// Create broker
const broker = new ServiceBroker({
    nodeID: "node-" + require("os").hostname().toLowerCase() + process.pid,
    transporter: "NATS",
    logger: console
});

broker.createService(Agent);

broker.start();

Actions

Start a service

broker.call("$agent.start", { service: "math", nodeID: "node-10" });

Stop a service

broker.call("$agent.stop", { service: "math", nodeID: "node-10" });

Get list of available services

broker.call("$agent.services", { nodeID: "node-10" })
    .then(services => console.log(services));

Start all services

broker.call("$agent.startAll", { nodeID: "node-10" });

Stop all services

broker.call("$agent.stopAll", { nodeID: "node-10" });

Fork a node

The node forks itself to a new process with the same arguments & env.

broker.call("$agent.fork");

Exit Moleculer process

broker.call("$agent.quit");

License

Moleculer is available under the MIT license.

3rd party licenses

Contact

Copyright (c) 2016-2017 Ice Services

@ice-services @MoleculerJS