Проблема конфигурации облачного шлюза Spring в обнаружении сервиса Kubernetes - PullRequest
0 голосов
/ 13 октября 2019

Я пытаюсь использовать весенний облачный шлюз с обнаружением сервиса kubernetes. Ниже приведены настройки, которые я использую

build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.0.BUILD-SNAPSHOT'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

ext {
    set('springCloudVersion', "Hoxton.BUILD-SNAPSHOT")
    set('springCloudKubernetesVersion', "1.0.3.RELEASE")
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes'
    implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-ribbon'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom "org.springframework.cloud:spring-cloud-kubernetes-dependencies:${springCloudKubernetesVersion}"
    }
}

test {
    useJUnitPlatform()
}

application.yml

spring:
  application.name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
    kubernetes:
      reload:
        enabled: true
server:
  port: 8080
logging:
  level:
    org.springframework.cloud.gateway: TRACE
    org.springframework.cloud.loadbalancer: TRACE
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      enabled: true
    info:
      enabled: true

DemoApplication.java

package com.example.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {

    @Autowired
    private DiscoveryClient discoveryClient;
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/services")
    public List<String> services() {
      return this.discoveryClient.getServices();
    }
}

Spring Cloud Gateway не может перенаправить запрос другим службам. Печатается журнал:

2019-10-13 18: 29: 38.303 TRACE 1 --- [or-http-epoll-2] oscgfWeightCalculatorWebFilter: Весовые коэффициенты attr: {} 2019-10-1318: 29: 38.305 TRACE 1 --- [or-http-epoll-2] oscghRoutePredicateHandlerMapping: не найдено определение маршрута для [Exchange: GET http://gateway -url / имя-службы / привет]

Хотя, когда я звоню http://<gateway-url>/services, тогда я вижу список всех услуг. Таким образом, все разрешения предоставляются на уровне модуля и обнаружение службы работает нормально. Я почти уверен, что есть какая-то конфигурация, которую мне не хватает, но я не могу понять это даже после просмотра документации несколько раз.

1 Ответ

0 голосов
/ 20 октября 2019

Итак, похоже, что есть проблема в Spring Cloud Hoxton.M3, версия , так как она нормально работает с Hoxton.M2 ​​.

Я открыл выпуск для того же.

...