AlexStocks commented on code in PR #1059:
URL: https://github.com/apache/dubbo-go-samples/pull/1059#discussion_r2985324833


##########
router/static_config/condition/consumer/cmd/client.go:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3"
+       "dubbo.apache.org/dubbo-go/v3/client"
+       "dubbo.apache.org/dubbo-go/v3/cluster/router"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       greet "github.com/apache/dubbo-go-samples/direct/proto"
+)
+
+const (
+       clientApplication = "static-condition-client"
+       directURL         = "tri://127.0.0.1:20000;tri://127.0.0.1:20001"
+)
+
+func main() {
+       ins, err := dubbo.NewInstance(
+               dubbo.WithName(clientApplication),
+               dubbo.WithRouter(
+                       router.WithScope("service"),
+                       router.WithKey(greet.GreetServiceName),
+                       router.WithPriority(100),
+                       router.WithForce(true),
+                       router.WithConditions([]string{
+                               "method = Greet => port = 20000",

Review Comment:
   我本地按 README 启动了 provider-node1、provider-node2 后复现了一次,consumer 还是打到了 
server-node-20001,和这里写的 port = 20000 相反,说明这条 condition rule 
现在并没有按预期生效。建议在合并前把规则调整到能稳定命中 20000 的写法,并补一个最小可运行校验,至少要能证明 README 
里的预期输出确实来自这条路由规则。



##########
router/static_config/condition/consumer/cmd/client.go:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3"
+       "dubbo.apache.org/dubbo-go/v3/client"
+       "dubbo.apache.org/dubbo-go/v3/cluster/router"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       greet "github.com/apache/dubbo-go-samples/direct/proto"
+)
+
+const (
+       clientApplication = "static-condition-client"
+       directURL         = "tri://127.0.0.1:20000;tri://127.0.0.1:20001"
+)
+
+func main() {
+       ins, err := dubbo.NewInstance(
+               dubbo.WithName(clientApplication),
+               dubbo.WithRouter(
+                       router.WithScope("service"),
+                       router.WithKey(greet.GreetServiceName),
+                       router.WithPriority(100),
+                       router.WithForce(true),
+                       router.WithConditions([]string{
+                               "method = Greet => port = 20000",
+                       }),
+               ),
+       )
+       if err != nil {
+               logger.Errorf("new instance failed: %v", err)
+               panic(err)
+       }
+
+       cli, err := ins.NewClient(client.WithClientURL(directURL))
+       if err != nil {
+               logger.Errorf("new client failed: %v", err)
+               panic(err)
+       }
+
+       svc, err := greet.NewGreetService(cli)
+       if err != nil {
+               logger.Errorf("new service failed: %v", err)
+               panic(err)
+       }
+
+       resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: 
"static condition router"})
+       if err != nil {
+               logger.Errorf("invoke failed: %v", err)

Review Comment:
   这里调用失败只打日志,进程仍然会以 0 退出。我本地在 provider 没启动时跑了一次 go run 
./consumer/cmd,命令返回码还是成功,这会让示例脚本和 CI 把失败当成通过。建议在 err != nil 分支里直接返回非零退出码,比如 
panic(err) 或 os.Exit(1)。



##########
router/static_config/tag/consumer/cmd/client.go:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3"
+       "dubbo.apache.org/dubbo-go/v3/client"
+       "dubbo.apache.org/dubbo-go/v3/cluster/router"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
+       "dubbo.apache.org/dubbo-go/v3/global"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       greet "github.com/apache/dubbo-go-samples/direct/proto"
+)
+
+const (
+       clientApplication = "static-tag-client"
+       tagName           = "gray"
+       grayAddress       = "127.0.0.1:20002"
+       directURL         = 
"tri://127.0.0.1:20000;tri://127.0.0.1:20002?dubbo.tag=gray"
+)
+
+func main() {
+       ins, err := dubbo.NewInstance(
+               dubbo.WithName(clientApplication),
+               dubbo.WithRouter(
+                       router.WithScope("application"),
+                       router.WithKey(clientApplication),
+                       router.WithPriority(100),
+                       router.WithForce(false),
+                       router.WithTags([]global.Tag{
+                               {
+                                       Name:      tagName,
+                                       Addresses: []string{grayAddress},
+                               },
+                       }),
+               ),
+       )
+       if err != nil {
+               logger.Errorf("new instance failed: %v", err)
+               panic(err)
+       }
+
+       cli, err := ins.NewClient(client.WithClientURL(directURL))
+       if err != nil {
+               logger.Errorf("new client failed: %v", err)
+               panic(err)
+       }
+
+       svc, err := greet.NewGreetService(cli)
+       if err != nil {
+               logger.Errorf("new service failed: %v", err)
+               panic(err)
+       }
+
+       ctx := context.WithValue(context.Background(), constant.AttachmentKey, 
map[string]string{
+               constant.Tagkey: tagName,
+       })
+
+       resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "static tag 
router"})
+       if err != nil {
+               logger.Errorf("invoke failed: %v", err)

Review Comment:
   这里和上面的 consumer 一样,调用失败只打日志,进程还是 0 退出。我本地在两个 provider 都没启动时跑过一次,go run 
./consumer/cmd 依然返回成功,外部脚本没法据此判断样例失败。建议把这个分支改成返回非零退出码,比如 panic(err) 或 
os.Exit(1)。



-- 
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]

Reply via email to