使用 Hystrix 和数十种服务的架构
Architecture with Hystrix and dozens of services
我正在维护一个可以与至少 80 个外部服务通信的架构,并且我们在这些服务上使用 Hystrix。
这些服务有一些共同点:其中一些有相同的后端 - 这意味着与它们通信的方式是相同的,所以我们有一个驱动程序 class 与它们通信,唯一改变的是 ip 地址。我们在该驱动程序中使用了一个 HystrixCommand。
我的问题从这里开始。如果具有相同后端的那些服务之一变得不稳定,Hystrix 将切断所有其他服务,而不是我们想要的服务。
据我了解,我实际上需要为它们中的每一个创建一个 HystrixCommand。
这就是我需要做的?我需要创建 80 个 HystrixCommand 实现吗?关于如何避免需要创建所有这 80 个 HystrixCommand 的任何建议?
好的,所以我设法解决了我的问题。
我犯了一个错误,没有命名 HystrixCommand。
A command name is, by default, derived from the class name:
getClass().getSimpleName();
所有服务都有一个 HystrixCommand,导致所有服务都断路。
通过命名 HystrixCommand,我可以通过服务实现我想要的隔离级别,即使相同的驱动程序 class 被许多不同的服务使用。我只需要根据外部服务的名称命名命令即可。
To explicitly define the name pass it in via the HystrixCommand or HystrixObservableCommand constructor:
public CommandHelloWorld(String name) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorld")));
this.name = name;
}
来源:https://github.com/Netflix/Hystrix/wiki/How-To-Use#command-name
我正在维护一个可以与至少 80 个外部服务通信的架构,并且我们在这些服务上使用 Hystrix。
这些服务有一些共同点:其中一些有相同的后端 - 这意味着与它们通信的方式是相同的,所以我们有一个驱动程序 class 与它们通信,唯一改变的是 ip 地址。我们在该驱动程序中使用了一个 HystrixCommand。
我的问题从这里开始。如果具有相同后端的那些服务之一变得不稳定,Hystrix 将切断所有其他服务,而不是我们想要的服务。
据我了解,我实际上需要为它们中的每一个创建一个 HystrixCommand。
这就是我需要做的?我需要创建 80 个 HystrixCommand 实现吗?关于如何避免需要创建所有这 80 个 HystrixCommand 的任何建议?
好的,所以我设法解决了我的问题。
我犯了一个错误,没有命名 HystrixCommand。
A command name is, by default, derived from the class name:
getClass().getSimpleName();
所有服务都有一个 HystrixCommand,导致所有服务都断路。
通过命名 HystrixCommand,我可以通过服务实现我想要的隔离级别,即使相同的驱动程序 class 被许多不同的服务使用。我只需要根据外部服务的名称命名命令即可。
To explicitly define the name pass it in via the HystrixCommand or HystrixObservableCommand constructor:
public CommandHelloWorld(String name) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorld")));
this.name = name;
}
来源:https://github.com/Netflix/Hystrix/wiki/How-To-Use#command-name