Git Product home page Git Product logo

demo-microservice-nodejs's Introduction

Cinema Microservice (Nodejs, Mongodb)

Cài đặt

Dự án chạy trên môi trường docker nên máy cần phải được cài đặt docker

Chạy các câu lệnh để cài đặt node_modules cho từng service

 Cinema\Booking> npm install
 Cinema\Movies> npm install
 Cinema\Notifications> npm install
 Cinema\Catalogs> npm install

Tiếp tục mở terminal trong dự án và build thành các container trên docker

 Cinema> docker-compose up

Port của các service

  • Booking: 3001
  • Notifications: 3002
  • Catalogs: 3003
  • Movies: 3004
  • Gateway: 80

Giới thiệu cấu trúc dự án

Dự án microservice xây dựng quản lý rạp phim dựa. Trong dự án sử dụng:

  • Nodejs (ES6 syntax)
  • MongoDB
  • Docker environment

Trong dự án gồm 5 service chính:

  • Movies service (thêm phim, danh sách phim, danh sách công chiếu)
  • Catalogs service (danh sách rạp, lịch chiếu)
  • Bookings service (Đặt vé, tạo ticket, quản lý user)
  • Notifications (Gửi notification qua kênh gmail)
  • Gateway

Mô hình tổng thể của dự án

Cinema Diagram

Gateway service sẽ chịu trách nhiệm điều hướng (nhận request từ port 80) và chuyển đến từng service tương ứng thông qua url truyền vào Gateway sử dụng nginx của Docker.

Mô hình của 1 service (ví dụ ở booking service)

Cinema Diagram

Mỗi service (trừ gateway) được chia thành 4 tầng (4-layer)

  • Tầng router chịu trách nhiệm điều hướng, nhận url, parameter truyền vào
  • Tầng BUS sẽ xử lý nghiệp vụ và logicstic
  • Tầng Repos (repository) tương tác với database thông qua models (CRUD)
  • Tâng Models định danh và cấu trúc 1 collection.

Các service sẽ gọi qua lại thông qua API Ví dụ service sẽ gửi notification trên kênh gmail thông qua notification service

const supertest = require('supertest');
exports.SendNoti = (payload) => {
    return new Promise((resolve, reject) => {
        supertest(process.env.NOTI_HOST)
            .post('/notification/sendmail')
            .send(payload)
            .end((err, res) => {
                if (err) {
                    reject(new Error('An error occured with the payment service, err: ' + err))
                }
                resolve(res.body)
            })
    })
}

demo-microservice-nodejs's People

Contributors

vudc avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.