1

我正在学习 Spring Boot kubernetes 并尝试为我的服务设置 Spring Cloud Gateway。我相信有了 Spring Cloud Gateway,我们就不必再使用 Ribbon 进行负载平衡了。因此,如果我不使用功能区,那么路线的配置也会发生变化。我查看了网站的建议,以下是我发现的:-

routes:
- id: department_route
  uri: http://departmentservice:4200 # 
  predicates:
  - Path=/* 

在这种情况下,uri 具有服务可用的端口的硬编码值。这是推荐的方法吗?

然后还有另一种配置,看起来像这样,不确定 url-expression 试图做什么:-

spring:
  application.name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          url-expression: "'http://'+serviceId"
  server.port: 8080

是否不可能按名称进行服务发现并在其后附加谓词?

4

1 回答 1

1

我仍在努力修复 main 的 Spring Cloud Gateway 项目,但以下对我有用。我已经通过 Zuul 配置了路由,因此请确保与它相关的依赖项和配置匹配:-

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-kubernetes-all</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>

**Config :: application.yaml ::**

    zuul:
      routes:
        shopping-cart-service:
          path: "/shopping-cart-service/**"
        item-service:
          path: "/item-service/**" 
于 2021-03-20T23:37:19.610 回答