【问题标题】:Use Micrometer with OpenFeign in spring-boot application在 spring-boot 应用程序中使用 Micrometer 和 OpenFeign
【发布时间】:2021-01-14 13:33:16
【问题描述】:

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 请求的一般信息。缺少什么部分?

【问题讨论】:

    标签: spring-boot feign micrometer spring-micrometer


    【解决方案1】:

    更新

    我为此添加了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 并将MeterRegistry 传递给MicrometerCapability 至关重要

    在这些之后,并打电话给客户,我有了新的指标:

    • feign.Client
    • feign.Feign
    • feign.codec.Decoder
    • feign.codec.Decoder.response_size

    【讨论】:

    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多