标签: spring-cloud

如何在 Maven 构建中禁用 Spring Cloud Kubernetes

运行 Spring Boot 2.6.6 和 Spring Cloud 2021.0.1

我正在尝试将现有服务迁移到 Kubernetes,因此我添加了对spring-cloud-starter-kubernetes-client-all. 默认情况下,我拥有spring.cloud.kubernetes.enable=false并使用kubernetes配置文件来启用它。这样做的目的是让该服务能够在 Kubernetes 和遗留环境中运行。

我的单元测试在本地构建时成功完成,但在 Bitbucket 管道中失败,并出现以下错误:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException: unresolved namespace
Run Code Online (Sandbox Code Playgroud)

我怀疑发生这种情况是因为 Bitbucket Pipelines 部署在 Kubernetes 中,而 Spring 以某种方式检测到了这一点。我已尝试以下方法但无济于事

  • --define SPRING_CLOUD_KUBERNETES_ENABLED=false通过命令行传递给 Maven
  • 将其设置为环境变量,例如,export SPRING_CLOUD_KUBERNETES_ENABLED=false
  • --define spring.cloud.kubernetes.enabled=false通过命令行传递给 Maven

我还检查了 StackOverflow 是否有类似问题并调查了代码也无济于事。实际引发问题的类是KubernetesClientConfigUtils,应该禁用它。

我将不胜感激您能提供的任何指导。

spring maven spring-boot kubernetes spring-cloud

3
推荐指数
1
解决办法
3163
查看次数

Netflix Eureka和2个本地环境应用实例

我开始使用Netflix Eureka并使用其1.1.145(https://github.com/Netflix/eureka/tree/1.1.145)版本.

我想在不同的端口上本地启动同一应用程序的2个实例,并让它们都注册到Eureka.我正在使用示例服务(https://github.com/Netflix/eureka/blob/1.1.145/eureka-server/conf/sampleservice/sample-eureka-service.properties)

所以我使用上面的配置启动了Eureka本身和2个实例 - 一个应用程序在8001端口上,另一个在8002上.

出于某种原因,我在任何时候都只有一个在Eureka注册的实例.他们两个都没有例外地开始,可以和Eureka OK谈谈.当我启动第二个实例时,它似乎只是用自己的信息覆盖有关第一个实例的信息.

我想要的是在http:// localhost/eureka/v2/apps下的同一个逻辑eureka.name下有2个'instance'元素

我错过了什么?

netflix spring-cloud netflix-eureka

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

Spring Cloud Turbine - 无法处理多个客户端?

让Turbine在Spring Cloud中工作我遇到了一些麻烦.简而言之,我无法确定如何配置它以一次聚合来自多个应用程序的电路.

我有6个独立的服务,一个eureka服务器和一个以独立模式运行的涡轮服务器.我可以从我的Eureka服务器上看到所有服务都已注册,包括涡轮机.我的涡轮机服务器已启动并运行,我可以看到它的/ hystrix页面没有问题.但是当我尝试用它来检查turbine.stream时,我只看到了在turb.appConfig中列出的FIRST服务器,其余的都被忽略了.

这是我的Turbine服务器的application.yml,或者至少是相关部分:

---
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8010/eureka/
server:
  port: 8030
info:
  component: Turbine
turbine:
  clusterNameExpression: new String(“default”)
  appConfig: sentence,subject,verb,article,adjective,noun
management:
  port: 8990  
Run Code Online (Sandbox Code Playgroud)

当我运行这个并访问我的涡轮机实例上的hystrix仪表板,询问turb.stream时,输出中列出的ONLY断路器是appConfig中列出的第一个服务,在这种情况下是"句子"服务.奇怪的是,如果我重新安排这些服务的顺序并先放入另一个服务(比如"名词"),我只会看到那些服务的电路.仅显示列表中的第一个服务.

我承认在一些术语上有点困惑,比如流,集群等,所以我可能会遗漏一些基本概念,但我的理解是Turbine可以从多个服务中消化流并聚合它们在一个显示器中.建议将不胜感激.

turbine spring-boot hystrix spring-cloud

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

在同一台服务器上运行Spring Clound Config和Eureka

我们正在尝试为我们的应用程序创建一个仪表板,作为单点输入/配置。为此,我们将构建和UI,并希望在同一实例上运行Spring Cloud Config和Eureka。有什么理由我们不应该这样做,如果不能,那么有可能吗?

spring spring-boot spring-cloud

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

Spring Eureka服务器在客户端URL中找不到上下文路径

当客户端应用程序注册到Spring Eureka服务器时,客户端ID出现在仪表板上,但链接URL仅包含没有客户端上下文路径的主机名和端口.

如果我在没有设置上下文路径的情况下创建Spring Boot客户端应用程序,我的意思是默认的根上下文,Eureka服务器可以访问那里可用的所有执行器.

有没有办法通知Eureka服务器?我试图设置健康和信息属性,但它不起作用.

java spring spring-boot spring-cloud netflix-eureka

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

使用Spring-Cloud-Config而不是Archaius的Hystrix运行时配置?

我正在研究Spring-Cloud-Netflix,我了解到Archaius用于Hystrix运行时配置.(https://ahus1.github.io/hystrix-examples/manual.html#archaius)

我还发现自从V1.5.0(https://github.com/Netflix/Hystrix/pull/1083)以来,Archaius是一个软依赖:"Archaius现在是Hystrix的软依赖,所以你可以提供自己的配置机制."

我的问题是,在运行时使用Spring-Cloud-Config配置Hystrix是否容易?我做了一些研究,但没有找到任何例子.

欣赏任何想法.

java netflix hystrix spring-cloud

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

具有Spring Cloud和Eureka的功能区java.lang.IllegalStateException:本地主机没有可用实例

我在用

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-netflix</artifactId>
  <version>1.2.3.RELEASE</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我的主班:

@SpringBootApplication
//@Configuration
@ComponentScan(basePackages = "com.mypackage")
@EnableAutoConfiguration
@EnableEurekaClient
@EnableSwagger2
public class App 
{
  public static void main( String[] args )
  {

    SpringApplication.run(App.class, args);
  }

  @LoadBalanced
  @Bean(name="template")
  RestTemplate restTemplate() {
    return new RestTemplate();
  }
}
Run Code Online (Sandbox Code Playgroud)

我的服务电话:

@Autowired
private RestTemplate template;

ResponseEntity<String> avs = template.exchange("http://localhost:7075/xyz/json/authenticate",HttpMethod.POST ,request,String.class); 
Run Code Online (Sandbox Code Playgroud)

它抛出以下异常

java.lang.IllegalStateException: No instances available for localhost
    at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:90)
    at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor$1.doWithRetry(RetryLoadBalancerInterceptor.java:60)
    at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor$1.doWithRetry(RetryLoadBalancerInterceptor.java:48)
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:276)
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:157)
Run Code Online (Sandbox Code Playgroud)

spring-cloud netflix-ribbon spring-cloud-netflix

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

如何覆盖Spring Cloud Eureka默认发现客户端默认ssl上下文?

我正在尝试为spring cloud eureka服务器启用https.Yaml配置:

server:
  port: 8100
ssl:
  clientAuth: want
  protocol: TLS
  key-store: classpath:keystore/keystore.jks
  key-store-password: some
  key-password: some
eureka:
  instance:
    prefer-ip-address: true
    non-secure-port-enabled: false
    secure-port-enabled: true
    secure-port: ${server.port}
    healthCheckUrl: https://${eureka.hostname}:${secure-port}/health
    statusPageUrl: https://${eureka.hostname}:${secure-port}/info
    homePageUrl: https://${eureka.hostname}:${secure-port}/
security:
  basic:
    enabled: true
Run Code Online (Sandbox Code Playgroud)

然后我启动一个客户端注册到服务器.我没有导入cource的自签名证书我得到了exc.security.provider.certpath.SunCertPathBuilderException :无法找到所请求目标的有效证书路径.我不想导入证书,因为有很多实例和证书管理成本很高.因此,我将cert放在classpath中并在启动时加载它.我通过添加代码覆盖客户端默认的ssl上下文和ssl套接字facotory

SSLContext.setDefault(sslContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
Run Code Online (Sandbox Code Playgroud)

它使用假装调用其他eureka客户端时工作正常.但是,在注册到eureka服务器时它没有任何努力.我检查了源代码,发现eureka发现客户端使用jersey,jersey调用http apache客户端.麻烦的是,它使用SchemeRegistryFactory.createDefault(),它将最终调用不考虑系统属性的SSLContexts.createDefault().换句话说,这个http客户端不会标记我的自定义SSLContexts.所以我的问题是,有一种方法可以在eureka发现客户端中添加/重新定位/替换默认的http客户端吗?

java ssl spring spring-cloud netflix-eureka

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

春天如何在@feignclient配置中设置自定义最大连接池大小

@feignclient春季如何在配置中设置自定义最大连接池大小,

@FeignClient(name = "content-cms", configuration = ContentCmsServiceFeignConfig.class)
public interface FeignService {

@RequestMapping(value = "/test/", method = RequestMethod.GET)
String getSample(@RequestParam("token") String token, @RequestParam("cid") String cid,
        @RequestParam("ratio") String ratio, @RequestParam("s") String source);

}
Run Code Online (Sandbox Code Playgroud)

java spring-cloud netflix-feign feign spring-cloud-netflix

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

使用自定义端口和地址配置Eureka Server和客户端

我有一个Eureka Server在默认的localhost主机和端口8761上运行,因此我尝试通过以下方式更改此默认配置:

server:
  port: 6000
  servlet:
    context-path: /myeureka
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
Run Code Online (Sandbox Code Playgroud)

但是以这种方式,仅使用默认配置就无法访问eureka仪表板:

server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
Run Code Online (Sandbox Code Playgroud)

在我的客户端中,同样的事情发生了,我无法指向不同于默认值的另一个eureka服务器(localhost:8761),请参阅我的配置:

server:
  port: 7000
  servlet:
    context-path: /client-eureka
spring:
  application:
    name: client-eureka
eureka:
  instance:
    prefer-ip-address: true
  client:
    eureka-server-port: 6000
    eureka-server-u-r-l-context: /myeureka
Run Code Online (Sandbox Code Playgroud)

在客户端日志中查找,我得到以下信息:

2018-09-01 09:19:37.175  INFO 4931 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : Replica node URL:  http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)

无论我在客户端中配置什么端口或主机,都应始终尝试达到默认值。

重要提示:我正在此版本中使用eureka:https : //mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server/2.0.1.RELEASE

spring-cloud netflix-eureka

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