标签: spring-cloud-netflix

Spring Cloud Gateway与Zuul有何不同?

我一直在使用Zuul作为边缘服务和API网关.最近我注意到Spring Cloud Platform发布了Spring Cloud Gateway.这两个网关有什么区别?为什么Zuul没有扩展到支持SC-Gateway的功能?一个新图书馆的驱动因素是什么?什么时候应该使用?

spring-mvc spring-cloud netflix-zuul spring-cloud-netflix

52
推荐指数
1
解决办法
2万
查看次数

在Feign客户端+ Spring Cloud中使用带有动态值的@Headers(Brixton RC2)

是否可以将动态值设置为标题?

@FeignClient(name="Simple-Gateway")
interface GatewayClient {
    @Headers("X-Auth-Token: {token}")
    @RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
        String getSessionId(@Param("token") String token);
    }
Run Code Online (Sandbox Code Playgroud)

注册RequestInterceptor的实现会添加标头,但无法动态设置标头值

@Bean
    public RequestInterceptor requestInterceptor() {

        return new RequestInterceptor() {

            @Override
            public void apply(RequestTemplate template) {

                template.header("X-Auth-Token", "some_token");
            }
        };
    } 
Run Code Online (Sandbox Code Playgroud)

我在github上发现了以下问题,其中一个评论者(lpborges)试图在@RequestMapping注释中使用标题做类似的事情.

https://github.com/spring-cloud/spring-cloud-netflix/issues/288

亲切的问候

spring spring-cloud spring-cloud-netflix

28
推荐指数
3
解决办法
5万
查看次数

尤里卡和Kubernetes

我正在整理一个概念证明,以帮助使用Spring Boot/Netflix OSS和Kubernetes一起识别陷阱.这也是为了证明Prometheus和Graphana等相关技术.

我有一个Eureka服务设置,在我的Kubernetes clouster中没有任何问题.这被命名为discovery,并在使用K8添加到K8时被命名为"discovery-1551420162-iyz2c"

kubectl run discovery --image=xyz/discovery-microservice --replicas=1 --port=8761

对于我的配置服务器,我正在尝试使用基于逻辑URL的Eureka,所以在我的bootstrap.yml中

server:
  port: 8889

eureka:
  instance:
    hostname: configserver
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xyz/microservice-config
Run Code Online (Sandbox Code Playgroud)

我正在开始使用它

kubectl run configserver --image=xyz/config-microservice --replicas=1 --port=8889
Run Code Online (Sandbox Code Playgroud)

该服务最终运行命名为configserver-3481062421-tmv4d.然后我在配置服务器日志中看到异常,因为它试图找到eureka实例而不能.

我有相同的设置使用docker-compose本地链接,它启动各种容器没有任何问题.

discovery:
  image: xyz/discovery-microservice
  ports:
   - "8761:8761"
configserver:
  image: xyz/config-microservice
  ports:
   - "8888:8888"
  links:
   - discovery
Run Code Online (Sandbox Code Playgroud)

我怎么能设置像eureka.client.serviceUri这样的东西,这样我的微服务可以在不知道K8集群内的固定IP地址的情况下定位他们的同行?

spring-boot kubernetes microservices netflix-eureka spring-cloud-netflix

28
推荐指数
2
解决办法
2万
查看次数

@RibbonClient和@LoadBalanced之间的区别

据我所知@LoadBalanced,Rest模板应基于使用Ribbon的客户端负载平衡,并检查Eureka服务器是否将服务名称解析为主机/端口.

有什么用@RibbonClient?是否支持没有Eureka的原生Ribbon Client LB,并在配置时支持Eureka Discover DiscoveryEnabledNIWSServerList

spring-boot netflix-ribbon spring-cloud-netflix

22
推荐指数
2
解决办法
2万
查看次数

如何使用spring-cloud-netflix和feign编写集成测试

我使用Spring-Cloud-Netflix进行微服务之间的通信.假设我有两个服务,Foo和Bar,而Foo使用Bar的REST端点之一.我使用一个带注释的接口@FeignClient:

@FeignClient
public interface BarClient {
  @RequestMapping(value = "/some/url", method = "POST")
  void bazzle(@RequestBody BazzleRequest);
}
Run Code Online (Sandbox Code Playgroud)

然后我SomeService在Foo中有一个服务类,它调用了BarClient.

@Component
public class SomeService {
    @Autowired
    BarClient barClient;

    public String doSomething() {
      try {
        barClient.bazzle(new BazzleRequest(...));
        return "so bazzle my eyes dazzle";
      } catch(FeignException e) {
        return "Not bazzle today!";
      }

    }
}
Run Code Online (Sandbox Code Playgroud)

现在,为了确保服务之间的通信正常工作,我想构建一个测试,使用WireMock之类的东西,对一个假的Bar服务器发出真正的HTTP请求.测试应确保假设正确解码服务响应并报告SomeService.

public class SomeServiceIntegrationTest {

    @Autowired SomeService someService;

    @Test
    public void shouldSucceed() {
      stubFor(get(urlEqualTo("/some/url"))
        .willReturn(aResponse()
            .withStatus(204);

      String result = someService.doSomething();

      assertThat(result, is("so …
Run Code Online (Sandbox Code Playgroud)

java wiremock netflix-eureka feign spring-cloud-netflix

21
推荐指数
4
解决办法
2万
查看次数

容错和容错之间有什么区别?

我正在阅读 Spring Cloud 和 NetFlix API。很多地方,我读到了 Fault Tolerance 和 Fault Resilience 关键词。

请解释区别。

fault spring-cloud spring-cloud-netflix

20
推荐指数
2
解决办法
8536
查看次数

负载均衡器没有可用于客户端的服务器

我正在尝试使用Feign客户端.以下是我的客户:

import com.eprogrammerz.examples.domain.Movie;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Yogen on 12/26/2016.
 */
@FeignClient(name = "movie-api")
public interface MovieApi {
    @RequestMapping(method = RequestMethod.GET, value = "/movies/{id}")
    Movie getMovie(@PathVariable("id") Long id);
}
Run Code Online (Sandbox Code Playgroud)

我从简单的服务中调用它,如下所示:

@Service
public class MovieService {

    @Autowired
    MovieApi movieApi;

    public Movie findMovie(Long id){
        Movie movieOfTheDay = movieApi.getMovie(id);
        return movieOfTheDay;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的春季启动应用程序如下:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

@EnableFeignClients(basePackages = {"com.eprogrammerz.examples"})
@EnableCircuitBreaker
@SpringBootApplication
public class ClientAppApplication {

    public static void main(String[] …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot netflix-feign spring-cloud-netflix

18
推荐指数
4
解决办法
5万
查看次数

使用尤里卡和功能区的测试服务

我正在使用带有netflix堆栈和spring boot的微服务构建一个应用程序.让我感到困惑的一件事是我还没有集成测试,我可以在这里模拟周围的服务.

所以,我有一个服务A,它是一个带有功能区的eureka客户端,用于在通话期间将eureka名称解析为注册服务B的URL.

理想情况下,我想用springtest注释启动应用程序,使用wiremock来模拟服务B,然后调用服务A的方法,这应该使用服务的符号名称来调用我的模拟服务B.

有人已经解决了吗?我已经搜索了人们这样做的博客条目等,但找不到任何...

我知道SO文章Mock是Eureka Feign客户端进行单元测试,但据我所知,这只会阻止发现客户端抱怨.

java spring integration-testing spring-boot spring-cloud-netflix

16
推荐指数
2
解决办法
2351
查看次数

如何在使用@ConditionalOnProperty或@ConditionalOnExpression时检查两个条件

在创建bean时,我需要检查YAML属性文件是否满足两个条件.我该怎么做,因为@ConditionalOnProperty注释只支持一个属性?

spring-boot netflix-eureka spring-cloud-netflix

15
推荐指数
4
解决办法
2万
查看次数

EnableEurekaClient导入不存在

我在我的项目中添加了 spring-cloud-starter-netflix-eureka-client gradle 依赖项并取消了依赖项。但是,当在我的主类中使用 @EnableEurekaClient 时,它会向我显示建议创建 @EnableEurekaClient 注释。不显示eureka客户端的任何导入文件。

Unresolved reference: EnableEurekaClient
Run Code Online (Sandbox Code Playgroud)

产品服务应用程序.kt

  package com.main.productservice
    
    import org.springframework.boot.autoconfigure.SpringBootApplication
    import org.springframework.boot.runApplication
    
    @SpringBootApplication
    @EnableEurekaClient
    class ProductServiceApplication
    
    fun main(args: Array<String>) {
        runApplication<ProductServiceApplication>(*args)
    }
Run Code Online (Sandbox Code Playgroud)

gradle.kt

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.5.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.5.20"
    kotlin("plugin.spring") version "1.5.20"
}

group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.

    kotlin:kotlin-reflect")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
        implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
        testImplementation("org.springframework.boot:spring-boot-starter-test")
    }
    
    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "11" …
Run Code Online (Sandbox Code Playgroud)

kotlin spring-boot spring-cloud netflix-eureka spring-cloud-netflix

14
推荐指数
3
解决办法
2万
查看次数