Spring cloud uses zuul to implement API gateway service

Through the previous sharing, we learned about several core facilities of microservice architecture. Through these components, we can build a simple microservice architecture system. For example, build a highly available service registry through spring cloud Eureka and realize service registration and discovery;

Load balancing through spring cloud ribbon or feign; Service fault tolerance protection through spring cloud hystrix to avoid fault propagation. After the microservices are built, we will certainly provide some unified restful API service interfaces for external systems to call,

However, when an external system calls our restful API, how to determine which service provides the required functions? This involves the maintenance of routing rules and service instance list.

This introduces our protagonist today - spring cloud zuul, which is an API gateway component based on Netflix zuul implementation. It can solve two major problems:

OK, let's take a look at how to implement this gateway service.

@H_ 403_ 20 @ I. build gateway and configure routing

Here we still need to use the above Hello service and feign consumer services. We used to regard feign consumer as a service consumer, but don't forget that in the Eureka system, each service is both a service provider and a service consumer, so feign consumer is also a service provider, and http://localhost:9001/feign -Consumer and other interfaces are the services it provides.

Test, start Eureka, hello service, feign consumer and the newly added API gateway service, and then visit http://localhost:5555/api -a/feign-consumer

Testing, accessing http://localhost:5555/api -a/hello

)Visit http://localhost:5555/hello -Service / Hello, access failed

)Visit http://localhost:5555/hello -service/hello? Accesstoken = token, normal access

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
分享
二维码
< <上一篇
下一篇>>