Using zuul for edge services

Concept Description

API Gateway:

The API Gateway is a server or a unique node that enters the system. The API Gateway encapsulates the architecture of the internal system and provides APIs to individual clients.


Zuul is Netflix's JVM-based router and server-side load balancer, which can be used by Zuul to:

  • Certification
  • Insight
  • pressure test
  • Canary Test
  • Dynamic routing
  • Service migration
  • Load shedding
  • Safety
  • Static phase response processing
  • Active / passive traffic management

This section focuses on using Zuul as an API Gateway in SpringBoot applications. For detailed functions of Zuul, please refer to the document [router and filter: Zuul] (

Scene Description

Zuul is the API Gateway, which is to establish a Zuul Proxy application. All the microservice access portals are defined in the Proxy application, and different microservices are distinguished by using different prefixes (stripped). This section demonstrates Zuul's API Gateway functionality by creating a ZuulProxy SpringBoot application.


The demos such as ZuulProxy and ZuulServer described in this section are based on SpringBoot and ServiceComb frameworks. For details, please refer to [using java chassis in Spring Boot] (../using-java-chassis-in-spring-boot/

Launching Zuul Proxy

This section describes how to launch a zuul proxy application as an API Gateway. Proceed as follows:

  • Step 1Add a dependency to the pom file:
  • Step 2Add annotations to the SpringBoot main class:
@EnableZuulProxy//Additional annotations
public class ZuulMain{
    public static void main(String[] args) throws Exception{, args);
  • Step 3 Define the routing policy in the application.yml file:
  port: 8754 #api gateway service port
  routes: #route strategy
    discoveryServer: /myServer/** #route rule

The red configuration item indicates that it can be configured according to the actual development environment. For detailed definition rules of the routing policy of zuul.routers, please refer to the official literature: [router and filter: Zuul] (, which can be more finely Control the route.

  • Step 4 Define microservice properties in microservice.yaml:
APPLICATION_ID: discoverytest #service ID
  name: discoveryGateway #service name
  version: 0.0.2 #service version number
      Address: #Service registry address
   address: # Service port, can not write
  • Step 5 Run ZuulMain Application

Using Zuul Proxy

Before using the API Gateway made by Zuul, you must first start the microservice provider defined in zuul.routers.

To develop a service provider, please refer to 3 Development Service Provider for the opening process. Pay attention to the following two points in the microservice.yaml file:

  • APPLICATION_ID needs to be consistent in the definition defined in the zuul proxy.

  • needs to correspond to zuul.routers.

An example is as follows:

APPLICATION_ID: discoverytest # is consistent with zuul proxy
  name: discoveryServer #service name, corresponding to zuul.routers
  version: 0.0.2
      address: #Service registry address

The API Gateway access is: [] (, all services defined in zuul.routers can be accessed through this access portal, access The rules are as follows:***

This means that Http calls [***] (***) and will go to the discoveryServer service (for example: "/myServer/101" jumps to "/101" under the discoveryServer service)

If there are multiple discoveryServer services in the service center (version is different), zuul uses the Ribbon policy to forward requests.