feat(router): add router examples#1032
Conversation
Alanxtl
left a comment
There was a problem hiding this comment.
- pls provied README_CN
- 这个新的示例可以作为一个集成测试吗
好的,我看看 |
* complete update logic * import format * add docker compose * docker-health-check * warp * fix all samples * import format * delete use less files * Update integrate_test.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| for { | ||
| time.Sleep(5 * time.Second) // sleep 5 seconds | ||
| rep, err := srv.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"}) | ||
| printRes(rep, err) | ||
| } |
There was a problem hiding this comment.
别弄成死循环 死循环的话集成测试怎么退出啊
另一个示例的死循环也改一下
There was a problem hiding this comment.
如果不使用死循环,有什么更佳的方法吗?
There was a problem hiding this comment.
// 1. 准备信号监听
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
// 2. 初始化 Ticker
ticker := time.NewTicker(5 * time.Second)
// 【关键】使用 defer 确保函数退出时,计时器资源被释放
// 无论是由于 return 还是 panic,这行都会执行
defer ticker.Stop()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
fmt.Println("服务运行中,按 Ctrl+C 安全退出...")
// 3. 主循环
done := false
for !done {
select {
case <-sigs:
fmt.Println("\n[信号] 接收到退出请求,清理资源中...")
// 停止向通道发送心跳,虽然 defer 也会做,但这里显式停止是好习惯
ticker.Stop()
done = true // 跳出循环
case <-ticker.C:
// 正常执行业务逻辑
rep, err := srv.Greet(ctx, &greet.GreetRequest{Name: "hello world"})
printRes(rep, err)
}
}
问下 gpt 或者 doubao,上面这种优雅退出代码很多
| array+=("java_interop/service_discovery/service") | ||
|
|
||
| # router | ||
| array+=("router/tag") |
There was a problem hiding this comment.
哦哦 另外两个需要在配置中心手动操作是吧
那不用加到集成测试里面了
如果这样的话 死循环确实也没啥问题
router/condition/README_CN.md
Outdated
|
|
||
| ```shell | ||
| $ go run ./go-server/cmd/server.go # 20000端口 | ||
| $ go run ./go-copy-server/cmd/server_copy.go # 20001端口 |
|
|
||
| } | ||
|
|
||
| func printRes(rep *greet.GreetResponse, err error) { |
There was a problem hiding this comment.
Pull request overview
This PR adds new Dubbo-go router sample projects (tag / condition / script) using the Triple protocol, and wires the tag router sample into the repository’s integration test run list. It also updates the top-level README(s) and router-specific README(s) to document the new samples.
Changes:
- Add
router/tagsample (proto + Go client + two Go providers: tagged and non-tagged). - Add
router/conditionandrouter/scriptsamples (two providers + client + Nacos config instructions). - Update sample indexes/READMEs and add
router/tagtostart_integrate_test.sh.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| start_integrate_test.sh | Adds router/tag to the integration test sample list. |
| router/tag/proto/greet.triple.go | Generated Triple stubs for the tag-router example. |
| router/tag/proto/greet.proto | Proto contract for the tag-router greet service. |
| router/tag/proto/greet.pb.go | Generated protobuf Go types for the tag-router example. |
| router/tag/go-tag-server/cmd/server_tag.go | Tagged provider implementation for tag routing demo. |
| router/tag/go-server/cmd/server.go | Non-tagged provider implementation for tag routing demo. |
| router/tag/go-client/cmd/client.go | Consumer that invokes with tag/force attachments for routing. |
| router/tag/README.md | English runbook for the tag-router sample. |
| router/tag/README_CN.md | Chinese runbook for the tag-router sample. |
| router/script/go-server/cmd/server.go | Script-router provider (node 1). |
| router/script/go-node2-server/cmd/server_node2.go | Script-router provider (node 2). |
| router/script/go-client/cmd/client.go | Script-router client that loops and observes routing behavior. |
| router/script/README.md | English runbook + Nacos YAML example for script router. |
| router/script/README_CN.md | Chinese runbook + Nacos YAML example for script router. |
| router/condition/go-server/cmd/server.go | Condition-router provider (node 1). |
| router/condition/go-node2-server/cmd/server_node2.go | Condition-router provider (node 2). |
| router/condition/go-client/cmd/client.go | Condition-router client that loops and observes routing behavior. |
| router/condition/README.md | English runbook + Nacos YAML example for condition router. |
| router/condition/README_CN.md | Chinese runbook + Nacos YAML example for condition router. |
| router/README.md | Router samples landing page (English). |
| router/README_CN.md | Router samples landing page (Chinese). |
| README.md | Adds router section to the repository sample index. |
| README_CN.md | Adds router section to the repository sample index (Chinese). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
router/README.md
Outdated
|
|
||
| ## Description | ||
|
|
||
| This directory includes four types of dubbo-go router function. No newline at end of file |
There was a problem hiding this comment.
This README says there are "four types" of router examples, but the directory currently contains tag/condition/script (3). Please update the count or rephrase (e.g., "multiple types") to match the actual contents.
| This directory includes four types of dubbo-go router function. | |
| This directory includes multiple types of dubbo-go router function. |
router/tag/go-client/cmd/client.go
Outdated
| // temporarily cancel checking for result, for PR # 3208 (https://github.com/apache/dubbo-go/pull/3208) | ||
| // hasn't been merged to main branch yet, thus tag router still not works properly. | ||
|
|
||
| //checkRes(exp, resp.GetGreeting(), err) | ||
| printRes(resp, err) |
There was a problem hiding this comment.
checkRes is commented out with a note about an upstream PR, so the example no longer verifies the routing behavior and the exp argument is effectively dead. Consider either restoring the assertion (once the dependency is available) or removing the exp parameter / checkRes helper to keep the sample deterministic and easier to maintain.
README.md
Outdated
| * `retry`: Demonstrates retry mechanisms in Dubbo-go RPC calls. | ||
| * `router`: Various Dubbo-go router examples. | ||
| * `router/tag`: Dubbo-go tag router examples. | ||
| * `router/condition`: Dubbo-to condition router examples. |
There was a problem hiding this comment.
The router list has a typo: "Dubbo-to" should be "Dubbo-go".
| * `router/condition`: Dubbo-to condition router examples. | |
| * `router/condition`: Dubbo-go condition router examples. |
| * `retry`:Dubbo-go RPC 调用重试机制示例。 | ||
| * `router`: Dubbo-go 各种 Router 调用示例。 | ||
| * `router/tag`: Dubbo-go 的 tag router 使用示例。 | ||
| * `router/condition`: Dubbo-go 的 condition router 使用示例。 |
There was a problem hiding this comment.
The Chinese sample index under router lists tag/condition, but this PR also adds a router/script example directory. Consider adding a router/script entry here to keep the index complete.
| * `router/condition`: Dubbo-go 的 condition router 使用示例。 | |
| * `router/condition`: Dubbo-go 的 condition router 使用示例。 | |
| * `router/script`: Dubbo-go 的 script router 使用示例。 |
router/tag/README_CN.md
Outdated
| $ go run ./go-server/cmd/server.go # 无标签server | ||
| $ go run ./go-tag-server/cmdserver_tag.go # 有标签server |
There was a problem hiding this comment.
The command path for the tagged server looks incorrect (./go-tag-server/cmdserver_tag.go). It should point to the actual file under go-tag-server/cmd/ so users can run the example as documented.
| $ go run ./go-server/cmd/server.go # 无标签server | |
| $ go run ./go-tag-server/cmdserver_tag.go # 有标签server | |
| $ go run ./go-server/cmd/server.go # 无标签server | |
| $ go run ./go-tag-server/cmd/server_tag.go # 有标签server |
| if err := srv.Serve(); err != nil { | ||
| logger.Errorf("server serve failed: %v", err) | ||
| if strings.Contains(err.Error(), "client not connected") { | ||
| logger.Errorf("hint: Nacos client not connected (gRPC). Check %s is reachable and gRPC port %d is open (Nacos 2.x default).", RegistryAddress, TriPort) |
There was a problem hiding this comment.
This hint message uses TriPort (the service port) as the "Nacos gRPC port". Nacos 2.x gRPC is typically on 9848 (when the HTTP port is 8848), so this hint is misleading. Consider using a dedicated nacosGrpcPort value instead of TriPort.
| if err := srv.Serve(); err != nil { | ||
| logger.Errorf("server serve failed: %v", err) | ||
| if strings.Contains(err.Error(), "client not connected") { | ||
| logger.Errorf("hint: Nacos client not connected (gRPC). Check %s is reachable and gRPC port %d is open (Nacos 2.x default).", RegistryAddress, TriPort) |
There was a problem hiding this comment.
This hint message uses TriPort (the service port) as the "Nacos gRPC port". Nacos 2.x gRPC is typically on 9848 (when the HTTP port is 8848), so this hint is misleading. Consider using a dedicated nacosGrpcPort value instead of TriPort.
| if err := srv.Serve(); err != nil { | ||
| logger.Errorf("server serve failed: %v", err) | ||
| if strings.Contains(err.Error(), "client not connected") { | ||
| logger.Errorf("hint: Nacos client not connected (gRPC). Check %s is reachable and gRPC port %d is open (Nacos 2.x default).", RegistryAddress, TriPort) |
There was a problem hiding this comment.
This hint message uses TriPort (the service port) as the "Nacos gRPC port". Nacos 2.x gRPC is typically on 9848 (when the HTTP port is 8848), so this hint is misleading. Consider using a dedicated nacosGrpcPort value instead of TriPort.
| if err := srv.Serve(); err != nil { | ||
| logger.Errorf("server serve failed: %v", err) | ||
| if strings.Contains(err.Error(), "client not connected") { | ||
| logger.Errorf("hint: Nacos client not connected (gRPC). Check %s is reachable and gRPC port %d is open (Nacos 2.x default).", RegistryAddress, TriPort) |
There was a problem hiding this comment.
This hint message uses TriPort (the service port) as the "Nacos gRPC port". Nacos 2.x gRPC is typically on 9848 (when the HTTP port is 8848), so this hint is misleading. Consider using a dedicated nacosGrpcPort value instead of TriPort.
| registry.WithNacos(), | ||
| registry.WithAddress(RegistryAddress), | ||
| ), | ||
| dubbo.WithConfigCenter( // configure config center to enable condition router |
There was a problem hiding this comment.
The comment says this config-center setup is to enable the "condition router", but this example is for the script router. Please adjust the comment to avoid misleading readers.
| dubbo.WithConfigCenter( // configure config center to enable condition router | |
| dubbo.WithConfigCenter( // configure config center for script router |
About
apache/dubbo-go#3208
This PR adds tag router and condition router examples. It uses Triple protocol to demonstrate router function.
detail