SpringBoot Gateway configuration with NodeJs Service
Gateways - BackBone of the microservice architecture !!!
The server acts as an application entry point and routing to downstream services. It ensures scalable, secure communication between clients and services.
A few functionalities of gateways:
?? Routing - Incoming requests to respective backend microservices.
??Security - Handle token validations and end-to-end encryptions.
??Aggregation/Composition - Aggregate the data from various microservices and send it to the client in a single request and response.
??Load Balancing - Distribute the traffic across multiple instances to ensure High availability.
??Rate Limiting and Throttling - To prevent attacks, by controlling the number of requests.
??Protocol Transformations - Modify the protocols based on the client and requesting microservices.
??Monitoring and Logging - To track the metrics like number of requests, response times, error rates, and throughput.
??Service Discovery - Dynamically discover the services by using service registries.
??Caching - Cache the response of frequently requested APIs to reduce the load to backend services and reduce the latency.
Steps to finish this,
Gateway setup using spring boot
Create basic nodeJs service:
领英推荐
const express = require("express");
const app = express();
app.get('/call',(req,res)=>{res.send("Response from Microservice")})
app.listen(3000,()=>{
console.log("App connected at 3000")
})
Configuring proxy?
spring:
cloud:
gateway:
mvc:
routes:
- id: first
predicates:
- Path=/gw/call
filters:
- StripPrefix=1
uri: https://localhost:3000/call
spring: Root configuration for spring boot.
cloud: Indicate the configuration is part of the spring cloud?
gateway: To configure the cloud gateway to mention the routing components.
mvc: Routing approach in MVC pattern
routes: The block that can define the incoming requests.
id: unique identifier of the route, to manage or debug the route.
predicts: path matching variable, contains Path.
filters:: The StripPrefix=1: removes the first part of the path-? /gw
uri: Here configure the nodeJs microservice URL in the URI.
Initializing gateway and testing
Thank you