Introduction to zuul, routing mapping rules

table of Contents

About Zuul

Routing access mapping rules

Basic rules

Set agent name

Ignore the real service name

Set a unified common prefix

Last yml


About Zuul

Zuul includes the two most important functions of request routing and filtering:

The routing function is responsible for forwarding external requests to specific microservice instances, which is the basis for achieving a unified access to external access, and the filter function is responsible for intervening in the processing of requests, and is the basis for implementing request verification, service aggregation and other functions .
 
Zuul and Eureka are integrated to register Zuul itself as an application under Eureka service governance, and at the same time obtain information about other microservices from Eureka, that is, after accessing microservices, they are obtained after Zuul jumps.

Note: The Zuul service will eventually be registered in Eureka

Zuul provides three functions: proxy + routing + filtering

Routing access mapping rules

Basic rules

No routing

http://localhost:8001/dept/get/2

Enable routing

http://myzuul.com:9527/microservicecloud-dept/dept/get/2

Equivalent to    routing ip: routing port / specific microservice name / request path of the microservice

It turned out to be a   specific microservice ip: specific microservice port / request path of the microservice

Set agent name

Replace the specific name of the microservice in the address to prevent others from discovering the name

before
http://myzuul.com:9527/microservicecloud-dept/dept/get/2
 
zuul: 
  routes: 
    mydept.serviceId: microservicecloud-dept
    mydept.path: /mydept/**
 
after
http://myzuul.com:9527/mydept/dept/get/1
 

Ignore the real service name

prior to

Both http://myzuul.com:9527/microservicecloud-dept/dept/get/2 and http://myzuul.com:9527/mydept/dept/get/1
can be accessed, now let ’s make the real service name 'S address is not accessible

zuul: 
  ignored-services: microservicecloud-dept 
  routes: 
    mydept.serviceId: microservicecloud-dept
    mydept.path: /mydept/**
 

Set a unified common prefix

访问地址:http://myzuul.com:9527/atguigu/mydept/dept/get/1
zuul: 
  prefix: /atguigu
  ignored-services: "*"
  routes: 
    mydept.serviceId: microservicecloud-dept
    mydept.path: /mydept/**

 

Last yml

server: 
  port: 9527
 
spring: 
  application:
    name: microservicecloud-zuul-gateway
 
zuul: 
  prefix: /atguigu
  ignored-services: "*"
  routes: 
    mydept.serviceId: microservicecloud-dept
    mydept.path: /mydept/**
 
eureka: 
  client: 
    service-url: 
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka  
  instance:
    instance-id: gateway-9527.com
    prefer-ip-address: true 
 
info:
  app.name: atguigu-microcloud
  company.name: www.atguigu.com
  build.artifactId: $project.artifactId$
  build.version: $project.version$
 


 

Published 524 original articles · Like 80 · Visits 150,000+

Guess you like

Origin blog.csdn.net/xushiyu1996818/article/details/104558042