当前位置: 首页 > 知识库问答 >
问题:

HystrixCodaHaleMetricsPublisher不能与Spring-Cloud-feign hystrix一起工作

督辉
2023-03-14

当结合使用HystrixCodaHaleMetricsPublisher和Graphite时,我遇到了一个奇怪的问题。已创建度量节点,但未输入任何数据。

我的配置:

@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(ApiGatewayProperties.class)
@EnableFeignClients
public class AccountSettingsClientConfig {
    private final ApiGatewayProperties apiGatewayProperties;

    @Bean
    public RequestInterceptor oauth2FeignRequestInterceptor() {
        return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), resource());
    }

    @Bean
    public okhttp3.OkHttpClient okHttpClient() {
        return new OkHttpClient.Builder().hostnameVerifier((s, sslSession) -> true)
                .build();
    }

    @Bean
    public AccountSettingsClientFallbackFactory accountSettingsClientFallbackFactory() {
        return new AccountSettingsClientFallbackFactory();
    }

共有1个答案

林浩漫
2023-03-14

最后我找到了问题的解决方案。问题是,FeignHistrix的默认SetterFactory生成了带有无效字符(对于graphite)的commandKey,即<代码>开发。地方的帐户设置客户端。accountSettings客户端#accountSettings(字符串)。countbad请求。在这种情况下,无效字符是#和()。当GraphiteReport开始向Graphite发送数据时,一切都正常,数据也会被发送,但Graphite无法处理。因此没有数据被持久化。

作为解决方法,我注册了一个自定义SetterFactory:

 @Bean
public SetterFactory setterFactoryThatGeneratesGraphiteConformCommandKey() {
    return (target, method) -> {
        String groupKey = target.name();
        //allowed chars for graphite are a-z, A-Z, 0-9, "-", "_", "." and "/".
        //We don't use default SetterFactory.Default because it generates command key with parenthesis () and #
        String commandKey = target.type().getSimpleName() + "-" + method.getName();
        return HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
                .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
    };
}

现在一切都好了。

 类似资料:
  • 我正在尝试建立Spring云涡轮amqp和hystrix仪表板。但当我启动所有应用程序时,hystrix dashboard没有显示任何内容:hystrix-dashboard-screenshot-link 这是gradle.build: 看起来问题出在依赖项版本上。

  • pom.xml版本信息: SpringFox-Swagger2:2.5.0 昂首阔步-核心:1.5.10 springfox-swagger-ui:2.6.1 Springboot:1.5.3 我有一个项目与swagger2和Springboot。 没有@Aspect的项目代码工作得很好。 正确的结果: 但是当我添加以下代码时,swagger-ui没有显示test-api-impl。 swagge

  • 我在为Spring Cloud Config服务器定义多个基于svn的配置存储库时遇到了问题。我已经建立了三个配置库。一个用于开发,单位和生产。我已经将默认值设置为development(通过设置spring.cloud.config.server.svn.uri=development repo uri)。但是,每当我向配置服务器的RESTendpoint发出GET请求时,无论我请求哪个概要文件

  • 当在嵌入了tomcat的spring boot中运行代码时,Spring cloud consul可以像预期的那样工作。 当我们在独立的tomcat上部署代码时,它不起作用。似乎有一个Web服务器上启动领事服务注册。仅当我们在带有嵌入式 tomcat 的Spring启动内运行代码时,才会触发此事件。 https://github.com/spring-cloud/spring-cloud-cons

  • 我使用的是Spring批处理版本2.2.4.Release,我试图用有状态的ItemReader、ItemProcessor和ItemWriter bean编写一个简单的示例。 在我的集成测试中,我在一个内部静态java配置类中声明bean,如下所示: 这个测试通过了。 但是,一旦我将StatefulItemReader定义为step范围的bean(这对于有状态的读取器更好),“Before st

  • 更新:Oook,首先,非常感谢。我不知道用户是postgres中的保留关键字。我把名字改成了CustomUser,但现在问题是另外一个了,应用程序可以工作,但我注意到它创建了一个名为custom_user的相同的CustomUser表,因为它没有使用现有的表? 我刚开始使用Springboot,我不明白我错在哪里。这是我的模型: 希望在您的帮助下,非常感谢大家。