You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/07 12:25:03 UTC

[GitHub] [dubbo-go-samples] Mulavar commented on a change in pull request #229: Ftr: dubbo context sample

Mulavar commented on a change in pull request #229:
URL: https://github.com/apache/dubbo-go-samples/pull/229#discussion_r703462046



##########
File path: context/dubbo/go-server/conf/dubbogo.yml
##########
@@ -0,0 +1,33 @@
+dubbo:
+  registries:
+    "demoZK":

Review comment:
       去掉引号

##########
File path: context/dubbo/go-client/cmd/client.go
##########
@@ -20,54 +20,57 @@ package main
 import (
 	"context"
 	"os"
-	"time"
 )
 
 import (
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
-	_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
 	"dubbo.apache.org/dubbo-go/v3/config"
-	_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
-
+	_ "dubbo.apache.org/dubbo-go/v3/imports"
 	hessian "github.com/apache/dubbo-go-hessian2"
-
 	"github.com/dubbogo/gost/log"
 )
 
-import (
-	pkg2 "github.com/apache/dubbo-go-samples/context/dubbo/go-client/pkg"
-)
+type UserProvider struct {
+	GetContext func(ctx context.Context, req []interface{}) (rsp *ContextContent, err error)

Review comment:
       尽量不要用[]interface{} 使用具体的类型

##########
File path: context/dubbo/go-client/cmd/client.go
##########
@@ -20,54 +20,57 @@ package main
 import (
 	"context"
 	"os"
-	"time"
 )
 
 import (
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
 	"dubbo.apache.org/dubbo-go/v3/common/constant"
-	_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
 	"dubbo.apache.org/dubbo-go/v3/config"
-	_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-	_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
-	_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
-
+	_ "dubbo.apache.org/dubbo-go/v3/imports"
 	hessian "github.com/apache/dubbo-go-hessian2"
-
 	"github.com/dubbogo/gost/log"
 )
 
-import (
-	pkg2 "github.com/apache/dubbo-go-samples/context/dubbo/go-client/pkg"
-)
+type UserProvider struct {
+	GetContext func(ctx context.Context, req []interface{}) (rsp *ContextContent, err error)
+}
+
+func (u *UserProvider) Reference() string {
+	return "userProvider"
+}
 
-var userProvider = new(pkg2.UserProvider)
+type ContextContent struct {
+	Path              string
+	InterfaceName     string
+	DubboVersion      string
+	LocalAddr         string
+	RemoteAddr        string
+	UserDefinedStrVal string
+	CtxStrVal         string
+	CtxIntVal         int64
+}
 
-func init() {
-	config.SetConsumerService(userProvider)
-	hessian.RegisterPOJO(&pkg2.ContextContent{})
+func (*ContextContent) JavaClassName() string {
+	return "org.apache.dubbo.User"
 }
 
 // need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run
 func main() {
-	hessian.RegisterPOJO(&pkg2.ContextContent{})
+	var userProvider = &UserProvider{}
+	config.SetConsumerService(userProvider)
+	hessian.RegisterPOJO(&ContextContent{})
 	config.Load()
-	time.Sleep(3 * time.Second)
-
 	gxlog.CInfo("\n\n\nstart to test dubbo")
-	rspContent := &pkg2.ContextContent{}
+
 	atta := make(map[string]interface{})
 	atta["string-value"] = "string-demo"
 	atta["int-value"] = 1231242
-	atta["user-defined-value"] = pkg2.ContextContent{InterfaceName: "test.interface.name"}
+	atta["user-defined-value"] = ContextContent{InterfaceName: "test.interface.name"}
 	reqContext := context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), atta)
-	err := userProvider.GetContext(reqContext, []interface{}{"A001"}, rspContent)

Review comment:
       同上




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org