Skip to content

krzyurb/node-moleculer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node microservices project

Monorepo Node.js microservices architecture.

📦 Project Structure

.
├── api               # graphql gateway
├── infrastructure/   # docker and docker-compose config
├── packages/
│   ├── shared        # types shared between services
│   └── core          # core package
└── services/
    └── plants         # plants microservice

🧰 Stack

⚙️ Local development

Set up local environment

  yarn initialize  # init project
  yarn up          # start whole infrastructure
  yarn logs        # show logs
  yarn down        # shut down docker compose

Queries examples

Run in Insomnia}

If you have installed Insomnia rest client you can check example queries.

RabbitMQ UI

Management UI Access

Graphql

GQL Playground

Commands

Adding dependency to package:

  yarn workspace @project/PACKAGE_NAME add DEPENDENCY_NAME

💡 Concepts

Communication between ApiGateway and Services

ApiGateway sends a message to service. There are two types of messages (QUERY and COMMAND). Both of them have the same format, but both of them can be implemented differently by each service.

{
  "id": "ab8e9d80-8efa-11ea-9d92-575a9da7b82b",
  "type": "query",
  "timestamp": 1588702825455,
  "data": {
    "id": "5eadd062dd477d002a8d5302"
  }
}

When service receives the message it's validated and then processed by proper action handler. After that, service responds with a success message, e.g:

{
  "success": true,
  "timestamp": 1588703954976,
  "actionName": "items.get",
  "messageId": "ab8e9d80-8efa-11ea-9d92-575a9da7b82b",
  "data": {
    "id": "5eadd062dd477d002a8d5302",
    "name": "Boris",
  }
}

or with an error message:

{
  "success": false,
  "timestamp": 1588703998266,
  "actionName": "items.get",
  "messageId": "ab8e9d80-8efa-11ea-9d92-575a9da7b82b",
  "error": {
    "message": "Item Not found",
    "type": "other",
    "code": "item-not-found",
    "data": { "id": "5eadd062dd477d002a8d5301" }
  }
}