Alanxtl commented on code in PR #32: URL: https://github.com/apache/dubbo-go-extensions/pull/32#discussion_r4431841939
########## filter/hystrix/README_CN.md: ########## @@ -2,91 +2,94 @@ [English](./README.md) | 简体中文 -基于 [hystrix-go](https://github.com/afex/hystrix-go) 的 dubbo-go 熔断器过滤器。 +Hystrix 过滤器为 dubbo-go consumer 和 provider 提供熔断能力。通过 dubbo-go extension API 配置后,扩展会自动把对应的 filter 加入 client 或 server 的 filter chain。 ## 安装 ```bash go get github.com/apache/dubbo-go-extensions/filter/hystrix ``` -## 使用方法 - -### 消费者端 (Consumer Side) +## Consumer 配置 ```go -import ( - "context" - "github.com/afex/hystrix-go/hystrix" - _ "github.com/apache/dubbo-go-extensions/filter/hystrix" - "dubbo.apache.org/dubbo-go/v3" - "dubbo.apache.org/dubbo-go/v3/client" - "dubbo.apache.org/dubbo-go/v3/registry" +cli, err := ins.NewClient( + client.WithExtension( + hystrix.WithConfig( + hystrix.WithCommandName("greet.GreetService:::Greet"), + hystrix.WithTimeout(1000), + hystrix.WithMaxConcurrentRequests(10), + hystrix.WithRequestVolumeThreshold(5), + hystrix.WithSleepWindow(5000), + hystrix.WithErrorPercentThreshold(50), + ), + ), ) Review Comment: 这个import这块也加一下 ########## filter/hystrix/README_CN.md: ########## @@ -2,91 +2,94 @@ [English](./README.md) | 简体中文 -基于 [hystrix-go](https://github.com/afex/hystrix-go) 的 dubbo-go 熔断器过滤器。 +Hystrix 过滤器为 dubbo-go consumer 和 provider 提供熔断能力。通过 dubbo-go extension API 配置后,扩展会自动把对应的 filter 加入 client 或 server 的 filter chain。 ## 安装 ```bash go get github.com/apache/dubbo-go-extensions/filter/hystrix ``` -## 使用方法 - -### 消费者端 (Consumer Side) +## Consumer 配置 ```go -import ( - "context" - "github.com/afex/hystrix-go/hystrix" - _ "github.com/apache/dubbo-go-extensions/filter/hystrix" - "dubbo.apache.org/dubbo-go/v3" - "dubbo.apache.org/dubbo-go/v3/client" - "dubbo.apache.org/dubbo-go/v3/registry" +cli, err := ins.NewClient( + client.WithExtension( + hystrix.WithConfig( + hystrix.WithCommandName("greet.GreetService:::Greet"), + hystrix.WithTimeout(1000), + hystrix.WithMaxConcurrentRequests(10), + hystrix.WithRequestVolumeThreshold(5), + hystrix.WithSleepWindow(5000), + hystrix.WithErrorPercentThreshold(50), + ), + ), ) - -func init() { - // 为服务方法配置 hystrix 命令 - // 资源名称格式: dubbo:consumer:接口名:group:version:方法名 - cmdName := "dubbo:consumer:greet.GreetService:::Greet" - - hystrix.ConfigureCommand(cmdName, hystrix.CommandConfig{ - Timeout: 1000, - MaxConcurrentRequests: 10, - RequestVolumeThreshold: 5, - SleepWindow: 5000, - ErrorPercentThreshold: 50, - }) -} - -func main() { - ins, _ := dubbo.NewInstance( - dubbo.WithRegistry( - registry.WithZookeeper(), - registry.WithAddress("127.0.0.1:2181"), - ), - ) - cli, _ := ins.NewClient() - svc, _ := greet.NewGreetService(cli, client.WithFilter("hystrix_consumer")) - - resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "test"}) -} ``` -### 提供者端 (Provider Side) +导入 `github.com/apache/dubbo-go-extensions/filter/hystrix` 并使用其配置选项即可。扩展会自动配置 Hystrix command,并添加 consumer filter。 + +## Provider 配置 ```go -import ( - _ "github.com/apache/dubbo-go-extensions/filter/hystrix" - "dubbo.apache.org/dubbo-go/v3/server" +srv, err := server.NewServer( + server.WithExtension( + hystrix.WithConfig( + hystrix.WithCommandName("greet.GreetService:::Greet"), + hystrix.WithTimeout(1000), + hystrix.WithMaxConcurrentRequests(10), + hystrix.WithRequestVolumeThreshold(5), + hystrix.WithSleepWindow(5000), + hystrix.WithErrorPercentThreshold(50), + ), + ), ) Review Comment: ditto -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
