there are two routing configurations in zuul:
1. Map
by accessing IP and port Numbers
2. Map
by service name
p>
based on the code in the previous section:
first I cluster both service providers and service consumers:
p>
first configure the first:
change gateway application.yml
server:
port: 8090
eureka:
client:
service-url:
default-zone: http://localhost:8761/eureka
spring:
application:
name: zuul-service
zuul:
routes:
feign:
path: /feign/**
url: http://localhost:8085/
accesses the path path through path and url mapping and accesses the url directly to the address corresponding to the url, which is obviously not good, because the address of the service must be known, and the number of clusters may be dynamically extended, which only realizes proxy forwarding and cannot realize load balancing. Where /feign/* represents only one path, /feign/* represents the following multiple paths
accessed through the gateway:
p>
let’s look at the second one:
The
profile is as follows:
server:
port: 8090
eureka:
client:
service-url:
default-zone: http://localhost:8761/eureka
spring:
application:
name: zuul-service
zuul:
routes:
api-a:
path: /feign/**
service-id: eureka-feign
#zuul:
# routes:
# feign:
# path: /feign/**
# url: http://localhost:8085/
now that you are registered on eureka, you should get the registered service information, access the micro service through the service id, write the service name here with the service-id, and also implement the routing and melting functions.
p>
is then accessed through the gateway:
p>
and the third: zuul.routes. Service name: access path
zuul:
routes:
eureka-feign: /feign/**
p>
if you ignore a micro service and do not use the gateway, set this:
p>
zuul:
#忽略某个微服务
ignored-services: eureka-feign
forward jumps to local url:
zuul.routes.api-a.path=/user/**
zuul.routes.api-a.url=forward:/user
routing prefix:
zuul.prefix
does not take effect by default. To take effect, zuul.stripprefix =false
sets the omitted prefix to false
zuul.routes.api-a.path=/user/**
zuul.routes.api-a.stripPrefix=false
if you want to configure routing rules in order, you must use the yml file, not the properties file
zuul:
routes:
users:
path: /user/**
others:
path: /**
p>
my github address
p>