This is a Moleculer-based microservices project.
Start the project with npm run dc:up
command and display logs with npm run dc:logs
command.
After starting, open the http://localhost:3000/api/worker/process?requestId=SOME URL in your browser, where SOME
is a non-empty string. The server will return the id of the instance that processed the request.
Shard strategy assumes that requests with the same requestId will be processed by one worker instance.
- Start transport with
npm run dc:nats
command. - Create
.env
file in root directory and fill it with data, for example:
NAMESPACE=deeplay
TRANSPORTER=nats
- Start api service with
npm run start:api
command. - Start worker service with
npm run start:worker
command.
Repeat step 3 as many times as you want worker instances.
- Start flooder script with
npm run start:flood
command.
Number of values requestId can be changed by an
FLOODER_MAX
environment variable.
- Start shard strategy test with
npm run test:shard
command. - Check that requests with the same requestId are processed by one worker instance.
- Start retry policy test with
npm run test:retry
command. - Wait 20 seconds for the request flood to end
- After that, wait another 10 seconds for the results to be displayed
npm run dev
: Start development mode (load all services locally with hot-reload & REPL)npm run start
: Start production mode (setSERVICES
env variable to load certain services)npm run start:api
: Start api service locallynpm run start:worker
: Start worker service locallynpm run start:flood
: Start flood scriptnpm run cli
: Start a CLI and connect to production. Don't forget to set production namespace with--ns
argument in script{{#lint}}npm run ci
: Run continuous test mode with watchingnpm test
: Run tests & generate coverage reportnpm disc:shard
: Run a test script to verify that sharding strategy is workingnpm disc:retry
: Run a test script to verify that retry policy is workingnpm "lint
: Run ESLintnpm run dc:up
: Start the stack with Docker Compose (api service & 4 worker service)npm run dc:nats
: Start NATS containernpm run dc:logs
: Display logs in follow modenpm run dc:down
: Stop the stack with Docker Compose