microservice-lite
Microservice-lite is a very small package for getting started with microservices on node.
It covers everything a simple microservice should have.
- Having it's own database (mysql, mongo, postgres, redis, and more)
- Small footprint
- Indepenent deployment
- Zero-configuration
- Zero-dependency
- Auto-discovery, fault toleranct and scalable
This works, thanks to the effort of @dashersw and his wonderful project cote.js
and @balderdashy for writing waterline
install
npm i -g microservice-lite
or
yarn global add microservice-lite
cli commands
create a project
mslite new sample
responder
mslite g responder foo [...othernames]
requester
mslite g requester foo [...othernames]
Requesters are global and can be accessed from any location. The above can be accessed as FooRequester
globally with the app
subscriber
mslite g subscriber foo [...othernames]
publisher
mslite g publisher foo [...othernames]
Publishers are global and can be accessed from any location. The above can be accessed as FooPublisher
globally with the app
model
mslite g model foo [...othernames]
Models are global and can be accessed from any location. The above can be accessed as Foo
globally with the app
database and adapters
Each microservice should have it's own database and mslite helps you with that. You could have a different database for each service. Eg mysql, mongodb, pouchdb etc.
By default, each project created with mslite comes with a disk based databased called sails-disk
. There are other adapters you can use to have a different database like
sails-mysql
sails-postgresql
sails-mongo
sails-redis
sails-orientdb
sails-filemaker
see here for more info about adapters.
To add a different adapter for your project, simply install the appropriate adapter and make sure you have the database on your current machine as the adapter would try to make connection.
configure adapters
- Install required adapter eg.
npm i --save sails-mongo
- open
config/adapters.js
and require intalled adapter, also passing it an object name of your pleasing eg
module.exports = {
'sailsDisk': require('sails-disk'),
'sailsMongo': require('sails-mongo')
}
You can have any amount of adapters saved here for later use
3. Open config/connections.js
create a connection object. Same as above, pass connection object to a name of your pleasing and specify the adapter from any defined in step 1
module.exports = {
'diskDb': {
'adapter': 'sailsDisk'
},
myMongodbServer: {
adapter: 'sailsMongo',
host: 'localhost',
port: 27017,
user: 'username',
password: 'password',
database: 'your_mongo_db_name_here'
}
}
- Open
cofig/models
Tell your models to use the connection you want.
module.exports = {
'connection': 'myMongodbServer',
'migrate': 'alter',
'schema': true
}
test
NYD
examples
NYD
goal
The goal of the project is to make getting started with a microservice easy and painless, giving you basic features. The following features are on the roadmap
- CLI for generating necessary files. eg
mslite g model name [names...]
- Easy connection to any database with the same api
- .... got a feature in mind ? create an issue here
development
This project uses the following to keep things a bit sane around the house
- standardjs
- validate-commit-msg see http://conventionalcommits.org/
- Github flow
and is completly test driven TDD