Mu is a message based router for building distributed systems. It allows messages to be routed and handled across various transports. Mu is aggressively light weight to ensure ease of use and speed of execution.
To install mu, simply use npm,
$ npm install mu
service-a.js
:
const mu = require('mu')({dev: process.NODE_ENV !== 'production'})
const tcp = require('mu-tcp')
// define routing:
mu.inbound({role: 'some'}, tcp.server({port: 3000, host: '127.0.0.1'}))
// define patterns:
mu.define({role: 'some', cmd: 'thing'}, function (args, cb) {
if (!args.pattern.user) {
return cb(mu.error('no user found!'))
}
cb(null, {some: 'data'})
})
service-b.js
:
const mu = require('mu')({dev: process.NODE_ENV !== 'production'})
const tcp = require('mu-tcp')
// define routing:
mu.outbound({role: 'some'}, tcp.client({port: 3000, host: '127.0.0.1'}))
// define patterns:
mu.dispatch({role: 'some', cmd: 'thing', user: 'me :)'}, function (err, result) {
if (err) {
return console.error(err)
}
console.log(result)
})
The mu
repo is managed as a monorepo, composed of multiple npm packages.
Package | Version | Dependencies |
---|---|---|
mu |
||
mu-error |
||
mu-local |
||
mu-tcp |
||
mu-http |
N/A | |
mu-redis |
||
mu-balance |
||
mu-tee |
||
mu-router |
||
mu-transport |
The mu
repository is Monorepo, managed with lerna
Each folder in packages is a distinct module, separately published to npm.
But general admin such as tests, linting, coverage, and build pipeline is managed at this repositories top level.
Clone:
$ git clone https://github.com/apparatus/mu
Setup:
$ npm run setup
This runs the lerna bootstrap command, which installs all sub-deps and links common packages together.
Our dev environment is now set up.
npm test
- to run tests. Tests may be written at the top level, and in individual packages, this command will ensure all tests are run. npm run lint
- lint the codenpm run coverage
- run and open a coverage report.npm run check
- test and lint (used as a precommit hook)npm run release
This runs the lerna publish command, which discovers packages that have changes, prompts for a version, then publishes each to npm, and creates a git release for the Github repository.
https://github.com/davidmarkclements
https://twitter.com/davidmarkclem
https://github.com/mcdonnelldean
https://twitter.com/mcdonnelldean
https://twitter.com/matteocollina
Copyright Peter Elger 2016 & Contributors, Licensed under MIT.