Building Microservices with Spring Boot — Part 02
Zuul API Gateway
In my first medium post on Building Microservice with Spring Boot — Part 01, I’ve completed building the basic structure of microservices based projects using Spring cloud, Netflix Eureka Registry, SpringBoot etc. Here I’ll explain how to integrate API Gateway to the microservices based project that I’ve developed for the previous post, and how to secure the API using JWT (JSON Web Token) with creating API documentation using Swagger2.
Integrate API Gateway into the application.
API Gateway is designed and developed to make a single entry point into the microservices based application. Basically, it acts as an Edge service. After configuring the API Gateway into the application it can be mainly used to route API consumer requests. additionally, We can secure whole services platform from a single point by integrating a secure layer to API gateway.
So Here I’m gonna use Zuul from Netflix OSS to configure API gateway into our system. Basically, Zuul provides dynamic routing, monitoring, resiliency, security, and more.
Configure Zuul API Gateway as a Spring Boot App
Zuul API Gateway is simply another Spring Boot application with Eureka client (Please refer Part 1 for creating a Eureka Client App)which is registered into the central service registry. additionally, it has some special features to be configured such a below.
Dependencies to use
@EnableZuulProxy To Main Application class.
Adding EnableZuulProxy in Main Class
Ok, as spring boot application has Zuul API gateway behavior, Now we can configure routing in order to route API consumer requests to registered services in the registry.
Configuring Zuul routes to the application.properties
Enabling Zuul Routes
What’s happening here ???
Let’s think our API gateway run on http://localhost:3003 and ‘medium-user-service’ is running on different port while registered into the service registry and have an API endpoint as ‘/api/v1/welcome’.
Then we can call medium-user-service’s API endpoint via API gateway using URL below.
Also, we can call the API directly using
Basically, Zuul finds the medium-user-service with route name which we configured in the application properties. In this case the router name is ‘user’. Then it routes the request into the ‘medium-user-service’ with setting API URL as ‘api/v1/welcome’. That’s how Zuul API gateway works !!!!!
Thanks for reading… Let’s meet with,
Building Microservices with Spring Boot — Part 03
Secure Zuul API Gateway | Authentication and Authorization | JWT