AlexStocks commented on code in PR #1060:
URL: https://github.com/apache/dubbo-go-samples/pull/1060#discussion_r3004326391
##########
filter/hystrix/README.md:
##########
@@ -0,0 +1,118 @@
+# Hystrix Filter Example
+
+[English](README.md) | [中文](README_zh.md)
+
+## Background
+
+This example demonstrates how to use the Hystrix filter in dubbo-go to
implement circuit breaker functionality. Hystrix is a latency and fault
tolerance library designed to isolate points of access to remote systems,
services, and 3rd party libraries, stop cascading failures, and enable
resilience in complex distributed systems.
+
+## Implementation
+
+### 1. Configure Hystrix Commands
+
+Use the `hystrix-go` API to configure circuit breaker commands. The resource
name format is:
+```
+dubbo:consumer:InterfaceName:group:version:Method
+```
+
+**Client Configuration** (`go-client/cmd/main.go`):
+```go
+import (
+ "github.com/afex/hystrix-go/hystrix"
+ _ "github.com/apache/dubbo-go-extensions/filter/hystrix"
+)
+
+func init() {
+ // Resource name format: dubbo:consumer:InterfaceName:group:version:Method
+ cmdName := "dubbo:consumer:greet.GreetService:::Greet"
+
+ hystrix.ConfigureCommand(cmdName, hystrix.CommandConfig{
+ Timeout: 1000, // timeout in milliseconds
+ MaxConcurrentRequests: 10, // max concurrent requests
+ RequestVolumeThreshold: 5, // minimum requests to trip the circuit
+ SleepWindow: 5000, // time to wait before attempting
recovery (ms)
+ ErrorPercentThreshold: 50, // error rate threshold (percentage)
+ })
+}
+```
+
+### 2. Use Hystrix Filter
+
+**Client** (`go-client/cmd/main.go`):
+```go
+import (
+ "dubbo.apache.org/dubbo-go/v3/client"
+)
+
+svc, err := greet.NewGreetService(cli, client.WithFilter("hystrix_consumer"))
+```
+
+## Configuration Parameters
+
+| Parameter | Description |
+|-----------|-------------|
+| `Timeout` | Command execution timeout in milliseconds |
+| `MaxConcurrentRequests` | Maximum number of concurrent requests allowed |
+| `RequestVolumeThreshold` | Minimum number of requests required to trip the
circuit (within sliding window) |
+| `SleepWindow` | Time to wait after circuit opens before attempting recovery
(milliseconds) |
+| `ErrorPercentThreshold` | Error rate threshold that triggers circuit opening
(percentage) |
+
+## How to Run
+
+### Prerequisites
+
+1. Start Zookeeper (default: `127.0.0.1:2181`)
Review Comment:
[P1] 这里的运行说明和示例代码不一致。客户端在 go-client/cmd/main.go 里通过
client.WithClientURL(127.0.0.1:20000) 直连 provider,并不依赖 Zookeeper;同时下面的命令还写死了
/home/zb/... 个人路径,用户无法直接复制执行。建议把前置条件改成“先启动 go-server 并确认 20000
端口就绪”,命令改成仓库相对路径,并同步更新 README_zh.md。
--
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]