Detailed configuration of routing endpoint of cloud and docker 8.3 zuul

Routing endpoint of cloud and docker zuul

Exposed route endpoint / routes

@EnableZuulProxy works with the actor, zuul exposes the routing endpoint / routes

Get access, get route list
post access, force refreshing route list

Starter zuul already contains an actor

http://localhost:8040/routes
{
    "/microservice-consumer-movie/**": "microservice-consumer-movie",
    "/microservice-provider-user/**": "microservice-provider-user"
}

Route configuration details

1 path of custom microservice:

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
zuul:
  routes:
    microservice-provider-user: /user/**
management:
  security:
    enabled: false

2 specify the microservices to ignore:

zuul:
ignored-services: microservice-provider-user,microservice-consumer-movie

3 specify routing service, ignore other

zuul:
Ignored services: 'use' to ignore all microservices
routes:
microservice-provider-user: /user/**

4. Specify the service id and corresponding path of the microservice:

zuul:
routes:
User route: in this configuration mode, user route only gives a name to the route, which can be named arbitrarily.
service-id: microservice-provider-user
Path: the path corresponding to / user / * * ා service ID

It is the same as the first configuration:
zuul:
routes:
microservice-provider-user: /user/**

5 specify both path and url

zuul:
routes:
User route: in this configuration mode, user route only gives a name to the route, which can be named arbitrarily.
url: http://localhost:8000 / ා specified url
Path: the path corresponding to / user / * * ා URL.

Access: / user / * *, which will map to http://localhost:8000 /;

In this way, there will be no hystrix and ribbon

6 specify the url and path without destroying the hystrix and ribbon

zuul:
  routes:
    user-route:
      path: /user/**
      service-id: microservice-provider-user

ribbon:
  eureka:
    enabled: false    # Disable ribbon Of eureka Use. See: http://cloud.spring.io/spring-cloud-static/Camden.SR3/#_example_disable_eureka_use_in_ribbon
microservice-provider-user:
  ribbon:
    listOfServers: localhost:8000,localhost:8001
management:
  security:
    enabled: false

Disable the eureka usage of ribbon and use the listOfServers load balancing of ribbon

Using regular expressions to specify zuul's routing rules

 @Bean
public PatternServiceRouteMapper serviceRouteMapper(){
//Regularity of microservices, regularity of routes
return new PatternServiceRouteMapper(
"(?<name>^.+)-(?<version>v.+$)",
"${version}/${name}");
}

microservice-provider-user-v1
Will map to / V1 / microservice provider user

8 prefix route:

zuul:
  prefix: /api
  strip-prefix: false
  routes:
    microservice-provider-user: /user/**
logging:
  level:
    com.netflix: DEBUG
management:
  security:
    enabled: false

Visit Zuul's / API / microservice provider user / 1 path, and the request will be forwarded to microservice provider user's / api/1. You can view the log printing, which is helpful for understanding.

Or:

zuul:
routes:
microservice-provider-user:
path: /user/**
strip-prefix: false

Access / user/1 will be forwarded to / user/1 of microservice provider user

Ignore some paths:

zuul:
  ignoredPatterns: /**/admin/**   # Ignore all paths including / admin /
  routes:
    microservice-provider-user: /user/**

You can map: microservice provider user to / user/**
And ignore it

logging:
level:
com.netflix: DEBUG

Local forwarding:

zuul:
  routes:
    route-name:
      path: /path-a/**
      url: forward:/path-b
Published an original article, won praise 27, visited 30000+
Private letter follow

Tags: Spring Docker

Posted on Tue, 04 Feb 2020 07:27:13 -0800 by toodi4