Skip to content

Latest commit

 

History

History

02-microservices

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Description

Multiple services recipe for Mau.

This recipe is using a monorepo setup with multiple applications. Each application is a separate NestJS application. This isn't required, we just used it here for demonstration purposes.

This monorepo contains the following applications:

  1. HTTP gateway application (listening on port 3000)
  2. Private (non-accessible from the outside) HTTP service (port 3002)
  3. TCP-based microservice (port 3001)
  4. Redis-based microservice
  5. RabbitMQ-based microservice
  6. NATS-based microservice

Project setup

  1. Install necessary dependencies
$ npm install
$ npm install -g @nestjs/mau
  1. Create a new Mau project.
  2. Within that project, create as many applications as you need (one for each of the applications listed above).
  3. Create: Redis database, RabbitMQ broker, and NATS broker.
  4. Now one by one, generate API keys for each application and run the following commands to deploy this recipe to the cloud:
$ npm run build APP_NAME
$ mau deploy APP_NAME

Environment variables

  1. HTTP gateway application
TCP_SERVICE_HOST= # TCP-based microservice host from Mau dashboard (without "http://")
PRIVATE_HTTP_SERVICE_URL= # Private HTTP service URL
REDIS_DB_HOST= # Redis database host (without protocol)
REDIS_DB_TOKEN= # Redis database authentication token
RABBITMQ_BROKER_URL= # RabbitMQ broker URL, example: "amqps://username:password@your-hostname:5671"
NATS_BROKER_URL= # NATS broker URL, example: "nats://broker-nats-node-alb-111.elb.us-east-2.amazonaws.com:4222"
  1. Redis service
REDIS_DB_HOST= # Redis database host (without protocol)
REDIS_DB_TOKEN= # Redis database authentication token
  1. RabbitMQ service
RABBITMQ_BROKER_URL= # RabbitMQ broker URL, example: "amqps://username:password@your-hostname:5671"
  1. NATS service
NATS_BROKER_URL= # NATS broker URL, example: "nats://broker-nats-node-alb-111.elb.us-east-2.amazonaws.com:4222"

Other services don't require any additional environment variables.

Compile and run the project

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Run tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Resources

Check out a few resources that may come in handy when working with NestJS:

  • Visit the NestJS Documentation to learn more about the framework.
  • For questions and support, please visit our Discord channel.
  • To dive deeper and get more hands-on experience, check out our official video courses.
  • Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
  • Need help with your project (part-time to full-time)? Check out our official enterprise support.
  • To stay in the loop and get updates, follow us on X and LinkedIn.
  • Looking for a job, or have a job to offer? Check out our official Jobs board.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.