gpt4 book ai didi

spring-boot - 在 spring-boot 应用程序中使用 Micrometer 和 OpenFeign

转载 作者:行者123 更新时间:2023-12-04 08:15:39 29 4
gpt4 key购买 nike

OpenApi documentation说它支持千分尺。集成如何工作?除了这个小文档,我找不到任何东西。
我在 Spring Boot 应用程序中有一个 FeignClient

@FeignClient(name = "SomeService", url = "xxx", configuration = FeignConfiguration.class)
public interface SomeService {

@GET
@Path("/something")
Something getSomething();
}
与配置
public class FeignConfiguration {
@Bean
public Capability capability() {
return new MicrometerCapability();
}
}
以及作为依赖项的千分尺集成
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
<version>10.12</version>
</dependency>
该代码进行了调用,但我无法通过 actuator 找到任何新指标。概述,期待一些关于我的 HTTP 请求的一般信息。缺少什么部分?

最佳答案

更新
我添加了 support为此向 spring-cloud-openfeign .在下一个版本( 2020.0.2 )之后,如果设置了千分尺,您唯一需要做的就是放置 feign-micrometer到你的类路径上。
旧答案
我不确定你是否这样做,但我建议使用 spring-cloud-openfeign它为您自动配置 Feign 组件。不幸的是,它似乎没有自动配置 Capability (这是您的解决方案不起作用的原因之一)所以您需要手动完成,please see the docs how to do it .
我能够结合 OpenFeign 和 Spring Cloud OpenFeign 文档中的示例完成这项工作:

@Import(FeignClientsConfiguration.class)
class FooController {
private final FooClient fooClient;

public FooController(Decoder decoder, Encoder encoder, Contract contract, MeterRegistry meterRegistry) {
this.fooClient = Feign.builder()
.encoder(encoder)
.decoder(decoder)
.contract(contract)
.addCapability(new MicrometerCapability(meterRegistry))
.target(FooClient.class, "https://PROD-SVC");
}
}

我做了什么:
  • 二手 spring-cloud-openfeign
  • 已添加 feign-micrometer (见 feign-bom)
  • 以您在上面看到的方式创建客户端
    进口FeignClientsConfiguration和路过 MeterRegistryMicrometerCapability至关重要

  • 在这些之后,并调用客户,我有了新的指标:
  • feign.Client
  • feign.Feign
  • feign.codec.Decoder
  • feign.codec.Decoder.response_size
  • 关于spring-boot - 在 spring-boot 应用程序中使用 Micrometer 和 OpenFeign,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65719975/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com