标签: hystrix

我们可以使用Spring-cloud-netflix和Hystrix来重试失败的exectuion

我正在使用Spring-Cloud-netflix库.

我想知道是否有办法获取此代码并添加配置它而不是立即执行回退方法重试执行N次,并且在N次执行回退方法的情况下:

 @HystrixCommand(fallbackMethod = "defaultInvokcation")
    public String getRemoteBro(String name) {
        return(executeRemoteService(name));
    }

     private String defaultInvokcation(String name) {
   return "something";
}
Run Code Online (Sandbox Code Playgroud)

谢谢,雷.

java spring spring-boot hystrix spring-cloud

5
推荐指数
1
解决办法
3929
查看次数

Spring Cloud Feign客户端调用是否在hystrix命令中执行?

我正在使用以下示例配置示例应用程序:http : //projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance。在本部分http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-ribbon中说:

Feign已经使用Ribbon,因此,如果您使用@FeignClient,则本节也适用

这是否意味着@FeignClient也使用Hystrix?对假冒客户的调用是否在hystrix命令中执行?如果是这样,通过hystrix配置的正确方法是什么?

有一些示例使用@HystrixCommand包装对伪装客户端的调用。这是正确的方法吗?

hystrix spring-cloud netflix-feign

5
推荐指数
1
解决办法
4155
查看次数

Netflix功能区和Hystrix超时

我们在项目中使用Spring云.我们有几个微服务,每个服务都有自己的.yml文件.

以下属性仅在zuul服务器中

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000

    ribbon: 
     ConnectTimeout: 3000
     ReadTimeout: 60000
Run Code Online (Sandbox Code Playgroud)

测试1:

账户服务:

我正在调用此服务来测试超时,我通过zuul调用请求,即使用端口8006.

@RequestMapping(value = "/accountholders/{cardHolderId}/accounts", produces = "application/json; charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public AllAccountsVO getAccounts(@PathVariable("cardHolderId") final String cardHolderId,
            @RequestHeader("userContextId") final String userContextId,
            @RequestParam final MultiValueMap<String, String> allRequestParams, final HttpServletRequest request) {

        return iAccountService.getCardHolderAccountsInfo(cardHolderId, userContextId, request, allRequestParams,
                ApplicationConstants.ACCOUNTHOLDER);
    }
Run Code Online (Sandbox Code Playgroud)

上面的服务使用Spring RestTemplate在内部调用下面的服务.我开始测试时通过在关联服务中添加如下所示的5000毫秒的休眠时间并向Accounts Service(getAccounts调用)发出请求.

协会服务:

@RequestMapping(value = "/internal/userassociationstatus", produces = "application/json; charset=utf-8", consumes = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public UserAssociationStatusVO getUserAssociationStatus(@RequestParam final Map<String, String> allRequestParams) {
        try …
Run Code Online (Sandbox Code Playgroud)

spring-boot hystrix microservices spring-cloud netflix-ribbon

5
推荐指数
1
解决办法
5580
查看次数

无法在Spring Cloud中获取/hystrix.stream

我创建了一个具有以下Spring云版本依赖关系的微服务Camden.SR2.Spring Boot 1.4.1.http://localhost:8080/hystrix.stream没有回应.

如果我将Spring Cloud版本设为Brixton.*(RELEASE,SR1,...),我只能ping:在浏览器中作为回复.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

application.properties

spring.application.name=sample-service
server.port = 8080
Run Code Online (Sandbox Code Playgroud)

应用

@SpringBootApplication
@EnableCircuitBreaker
public class SampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

hystrix spring-cloud spring-cloud-netflix

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

Hystrix命令对象:新vs单例

HystrixCommand对象实现创建为Singleton 是否正确?如果是这样,它将保留线程直到执行完成并且不再创建了吗?

singleton multithreading command-pattern threadpool hystrix

5
推荐指数
1
解决办法
361
查看次数

NodeJS中用于微服务的Netflix工具

NodeJS是否有服务发现(eureka),断路器模式(Hystrix),客户端负载平衡(ribbon)和api网关(Zuul)实现?我在Java的Spring框架中看到了这些组件的良好集成,但是在NodeJS中是否有可用的组件?

Netflix通过Prana(https://github.com/Netflix/Prana)为非JVM语言提供了另一种方法,但未得到积极支持。NodeJS是否有其他可供选择的生产就绪组件套件?理想情况下,微服务的好处之一是每种服务可以用不同的语言开发。有什么好的选择可用,还是我应该自己实现?

netflix node.js hystrix microservices netflix-eureka

5
推荐指数
0
解决办法
1081
查看次数

与正常的异常处理相比,Hystrix的优势是什么?

我是Hystrix主题和弹性服务概念的新手,我正在经历一些课程,这个问题进入我的脑海.

在Hystrix中,我需要为优雅降级定义回退方法,然后在电路断开时调用此方法.但我可以想象只是用代码包装代码,try并且catch当出现特殊异常时(例如,对于超时),在catch子句中调用fallback方法.当被叫服务启动时,将调用普通代码.

当然,有了Hystrix,我可以另外监控这个,但它给了我什么呢?我很确定我不理解整个概念.

java spring hystrix microservices spring-cloud

5
推荐指数
1
解决办法
2695
查看次数

可观察的发射器为HystrixCommands产生太大的压力

我有一个Observable发出文件行(从GCS读取许多GB).

return StringObservable.byLine(
    Observable.using(
        () -> storage.get(blobId).reader(),
            reader -> Observable.create(
                    new OnSubscribeReadChannel(reader, 64 * 1024)
                ),
            ReadChannel::close
    )
)
Run Code Online (Sandbox Code Playgroud)

每行产生多个(在某些情况下很多)调用各种DB,所有这些都包含在Hystrix命令中.显然这些线最终压倒了Hystrix命令,电路开始打开,每个人都有糟糕的一天.

这大致就是我正在做的事情:

readLinesFromCloudStorageFile.readLines(blobInfo.getBlobId()))
            .map(this::deserializeLine)
            .flatMap(this::addDataToObjectFromSomeDb)
            .flatMap(this::writeObj)
            .map(Set::size)
            .reduce(0, (a, b) -> a + b)
            .toBlocking().single()
Run Code Online (Sandbox Code Playgroud)

有没有办法可以应用一些背压,或限制一次处理的线数?

observable java-8 rx-java hystrix

5
推荐指数
1
解决办法
80
查看次数

Hystrix线程池属性

在我们的应用程序中,我们使用Hystrix,因为我们调用了多个外部服务。我们想为我们调用的每个外部服务配置一个线程池(具有特定的大小)。

假设有三个外部服务,分别称为S1,S2,S3。此外,我们有10个扩展类HystrixCommand,称为C1至C10。

C1和C2调用S1,并且应使用具有15个线程的相同线程池。在C1的构造函数中,我们对进行以下调用super

super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("S1"))
    .andThreadPoolKey(ThreadPools.S1)
    .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(15))
    .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeout)));
Run Code Online (Sandbox Code Playgroud)

在一个命令(C1)的构造函数内部,我们将S1的线程池大小指定为15。这ThreadPools是一个自定义类,其中的final static属性S1

S1 = HystrixThreadPoolKey.Factory.asKey("S1");
Run Code Online (Sandbox Code Playgroud)

现在的实际问题是:(1)为什么在a HystrixCommand而不是中央线程池定义(似乎不是Hystrix的概念)中指定线程池核心大小(对于S1为15 )。

假设在C2(与上面的代码段相同的)构造函数中,我们用一个非15的参数调用withCoreSize。(2)将使用哪个参数?

(3)有没有一种方法可以在一个类中为服务S1,S2和S3定义三个线程池,并从命令类中引用它们?

Hystrix的使用方法指南似乎不包含与此相关的信息。如果有人有时间回答这个问题,那就太好了。

java concurrency multithreading hystrix

5
推荐指数
1
解决办法
5104
查看次数

无法使用Spring Cloud连接到Hystrix仪表板的Command Metric Stream

我有Spring Cloud的微服务项目,这是父母的摘录:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.SR3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

所有服务都在Eureka服务器下运行:

在此处输入图片说明

所有服务运行正常。我可以打给Postman适当的电话,一切正常。

我有单独的服务来处理Hystrix仪表板,摘录自pom

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

配置主类:

@SpringBootApplication
@EnableHystrixDashboard
public class DashboardApp {
    public static void main(String[] args) {
        SpringApplication.run(DashboardApp.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

和配置yaml文件:

spring:
  application:
    name: Dashboard

server:
  port: 8000

eureka:
  client:
    fetchRegistry: true
    registerWithEureka: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
Run Code Online (Sandbox Code Playgroud)

我有下一个仪表板:

在此处输入图片说明

来自控制台的完整堆栈跟踪在这里。以下是一些代码段: …

spring runtimeexception spring-boot hystrix spring-cloud

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