Menu Close
In fact, it has the 39mm Oystersteel monobloc middle-case of the OP essentially, which appears a little more curvaceous than the flat, trapezoid profile of the 40mm Oystersteel Submariner. The bezel of the replica rolex watches Explorer I is different on each: The OP has a domed, high-polish bezel, while the Explorer I has what Rolex calls a "Smooth" bezel. It has a flat surface instead of the convex bezel of the OP, with nicely polished.

Implementing Microservice Architecture In Node JS

Implementing Microservice Architecture In Node JS



๐Ÿ“ Introduction

๐Ÿ™‚ As we have discussed in our previous blog “Monolithic vs Microservices: A Practical Approach“. But today we’re going to implement Microservices Architecture in NodeJS.

๐Ÿ‘‰ You can use any technology like Spring, Python, etc. But we are going to demonstrate using NodeJS.

NodeJS Meme



๐Ÿ“ Directory Structure

๐Ÿ™‚ You can find the GitHub Repo (Kindly run npm install in Order, Payment, and API-Gateway directories before running) Here. We have two services Order and Payment with API Gateway.

NodeJS_Microservices
|
—> Order
|
——> server.js (Running on PORT 8081)
|
—> Payment
|
——> server.js (Running on PORT 8082)
|
—> API-Gateway
|
——> server.js (Running on Port 9091)

๐Ÿ”ฅ The structure of our services looks like this:-



๐Ÿ“ Implementation

Microservices Architecture

๐Ÿ™‚ Whenever a client makes a request to the API-Gateway, We have defined some routes (Using prefixes) that redirect the request to the appropriate service (Depends which route is called). Payment and Order services are independent means If one fails other will not be affected.

๐Ÿ”ฅ Also we can add Auth or Middlewares so that no one can call the services directly or without Authentication. We have implemented a very basic architecture.

  • Order Server.js
const express = require("express");
const app = express();

const port = 8081;
app.get("/order-list", (req,res)=>{
    let response = {
        data: {
            item: [
                {
                    id: 1,
                    name: 'order-1'
                },
                {
                    id: 2,
                    name: 'order-2'
                }
            ]
        }
    };
    res.status(200).json(response);
});
app.get("/", (req,res)=>{
    res.send("Order called");
});

app.listen(port, ()=>{
    console.log("Listening at localhost "+ port);    
})
Enter fullscreen mode

Exit fullscreen mode

  • Payment server.js
const express = require("express");
const app = express();

const port = 8082;
app.get("/payment-list", (req,res)=>{
    let response = {
        data: {
            item: [
                {
                    id: 1,
                    name: 'Payment-1'
                },
                {
                    id: 2,
                    name: 'Payment-2'
                }
            ]
        }
    };
    res.status(200).json(response);
});

app.get("/", (req,res)=>{
    res.send("Payment called");
});

app.listen(port, ()=>{
    console.log("Listening at localhost "+ port);    
})
Enter fullscreen mode

Exit fullscreen mode

  • API-Gateway
const gateway = require("fast-gateway");

const port = 9001;
const server = gateway({
    routes: [
        {
            prefix: "/order",
            target: "http://localhost:8081/",
            hooks: {}
        },
        {
            prefix: "/payment",
            target: "http://localhost:8082/",
            hooks: {}
        }
    ]
});

server.get('/mytesting', (req,res)=> {
    res.send("Gateway Called");
})

server.start(port).then(server=>{
    console.log("Gateway is running "+port);
})

Enter fullscreen mode

Exit fullscreen mode

๐Ÿ˜Œ Now, we can start the services including the gateway

Terminal running microservices

๐Ÿ“ And we can request http://localhost:9001/order Or http://localhost:9001/payment


๐Ÿ™‹ Follow for more in-depth tutorials. Right now, I am targeting beginners but soon more advanced things we’ll discuss.

Drop your views in the Comment Box. Hope It helps.

View Source