- Order Service
- Customer Service
- Kitchen Service
In this tutorial main motive is to demonstrate how to implement gateway for our services. Gateway is interface that will route our request to required services. If you want to know more about Gateway then feel free to visit MicroServices – GateWay Pattern.
Gateway Pattern |
As we know that each spring boot application is a microservice there fore for creating our services we will be using Spring Boot.
Note: You can get entire code at this link
Steps to be followed
- Create Spring Boot Application for OrderService.
- Create Spring Boot Application for CustomerService.
- Create Spring Boot Application for Gateway.
Step 1: Create a Spring Boot Application for OrderService
Generate a spring boot application named orderservice packaged as war with following maven dependencies.
Create a application.properties
Step 2: Create Spring Boot Application for CustomerService
Create a application.properties
Create a Customer.java
Now run the application as spring boot application. you will get the following result at 8082 port.
Step 3: Create Spring Boot Application for Gateway
Create a application.yml
Here we have in this application.yml “routes” is the array of the urls you want to give for routing and “Path” will match the incoming request and proxy it to given url in “uri“. Like in our case any uri with “/order/**” i.e path starting with “/order” will be redirected to “http://localhost:8081/”.
Now run the omgateway application as springboot application on port :8000
and try to visit “localhost:/8000/order/listorder” you should be getting the result of “localhost:8081/order/listorder” And visit “localhost:/8000/customer/getcustomer” you would get result which you get by visiting “localhost:/8082/customer/getcustomer”
This is because your gateway is routing the request to 8082 and 8081 respectively.
Note: You can get entire code at this link