Explain in detail the API gateway of spring cloud to build micro service architecture

preface

In our previous blog, when service a needs to call service B, we only need to obtain the registered instance of service B from Eureka, then use feign to call service B, and use ribbon to achieve load balancing. However, when we expose multiple services to the client at the same time, how can the client call our exposed services, If we want to add features such as security authentication, permission control, filters and dynamic routing, we need to use zuul to implement API gateway. Next, let's see how zuul is used.

1、 Join zuul's dependency

Because we need to register zuul service on Eureka server and find the registered service from Eureka server, we add Eureka dependency here.

2、 Enable zuul support on the application main class

3、 In application Add zuul's basic configuration information to YML

4、 In application Add service routing configuration in YML

Premise: two services have been registered in Eureka server: springboot-h2-service and springboot-rest-template-feign. The springboot-rest-template-feign service will call the springboot-h2-service. The springboot-rest-template-feign service is our external service, that is, The springboot rest template feign service is leaked to the client.

5、 Verify

Now we can verify it and enter in the browser: http://localhost:8768/templateservice/template/1 You can see the test results.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>