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/08 04:51:45 UTC
[GitHub] [dubbo-go-samples] xavier-niu commented on a change in pull request #229: Ftr: dubbo context sample
xavier-niu commented on a change in pull request #229:
URL: https://github.com/apache/dubbo-go-samples/pull/229#discussion_r704035363
##########
File path: context/dubbo/go-client/cmd/client.go
##########
@@ -20,50 +20,53 @@ 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 *ContextContent) (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
Review comment:
Please update comments for how to set up environment variable.
##########
File path: context/dubbo/go-client/conf/dubbogo.yml
##########
@@ -0,0 +1,37 @@
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ protocols:
+ dubbo:
+ name: dubbo
+ port: 20000
+ # 在 params 中定义当前使用的协议特有的网络配置
+ # 如该 sample 配置的是 dubbo 协议(底层使用 getty 通信库)的参数
Review comment:
Use english please.
##########
File path: context/dubbo/go-server/cmd/server.go
##########
@@ -26,30 +27,68 @@ import (
)
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/logger"
- _ "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"
-)
-import (
- pkg2 "github.com/apache/dubbo-go-samples/context/dubbo/go-server/pkg"
+ gxlog "github.com/dubbogo/gost/log"
)
var (
survivalTimeout = int(3e9)
)
+func init() {
+ config.SetProviderService(&UserProvider{})
+ // ------for hessian2------
+ hessian.RegisterPOJO(&ContextContent{})
+}
+
+type ContextContent struct {
+ Path string
+ InterfaceName string
+ DubboVersion string
+ LocalAddr string
+ RemoteAddr string
+ UserDefinedStrVal string
+ CtxStrVal string
+ CtxIntVal int64
+}
+
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetContext(ctx context.Context, req *ContextContent) (*ContextContent, error) {
+ gxlog.CInfo("req:%#v", req)
+ ctxAtta := ctx.Value(constant.DubboCtxKey("attachment")).(map[string]interface{})
+ userDefinedval := ctxAtta["user-defined-value"].(*ContextContent)
+ gxlog.CInfo("get user defined struct:%#v", userDefinedval)
+ rsp := ContextContent{
+ Path: ctxAtta["path"].(string),
+ InterfaceName: ctxAtta["interface"].(string),
+ DubboVersion: ctxAtta["dubbo"].(string),
+ LocalAddr: ctxAtta["local-addr"].(string),
+ RemoteAddr: ctxAtta["remote-addr"].(string),
+ UserDefinedStrVal: userDefinedval.InterfaceName,
+ CtxIntVal: ctxAtta["int-value"].(int64),
+ CtxStrVal: ctxAtta["string-value"].(string),
+ }
+ gxlog.CInfo("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (u *UserProvider) Reference() string {
+ return "userProvider"
+}
+
+func (u ContextContent) JavaClassName() string {
+ return "org.apache.dubbo.User"
Review comment:
same above
##########
File path: context/dubbo/go-server/conf/dubbogo.yml
##########
@@ -0,0 +1,33 @@
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ protocols:
+ dubbo:
+ name: dubbo
+ port: 20000
+ # 在 params 中定义当前使用的协议特有的网络配置
+ # 如该 sample 配置的是 dubbo 协议(底层使用 getty 通信库)
Review comment:
same above
##########
File path: context/dubbo/go-server/cmd/server.go
##########
@@ -26,30 +27,68 @@ import (
)
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/logger"
- _ "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"
-)
-import (
- pkg2 "github.com/apache/dubbo-go-samples/context/dubbo/go-server/pkg"
+ gxlog "github.com/dubbogo/gost/log"
)
var (
survivalTimeout = int(3e9)
)
+func init() {
+ config.SetProviderService(&UserProvider{})
+ // ------for hessian2------
+ hessian.RegisterPOJO(&ContextContent{})
+}
+
+type ContextContent struct {
+ Path string
+ InterfaceName string
+ DubboVersion string
+ LocalAddr string
+ RemoteAddr string
+ UserDefinedStrVal string
+ CtxStrVal string
+ CtxIntVal int64
+}
+
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetContext(ctx context.Context, req *ContextContent) (*ContextContent, error) {
+ gxlog.CInfo("req:%#v", req)
+ ctxAtta := ctx.Value(constant.DubboCtxKey("attachment")).(map[string]interface{})
+ userDefinedval := ctxAtta["user-defined-value"].(*ContextContent)
+ gxlog.CInfo("get user defined struct:%#v", userDefinedval)
+ rsp := ContextContent{
+ Path: ctxAtta["path"].(string),
+ InterfaceName: ctxAtta["interface"].(string),
+ DubboVersion: ctxAtta["dubbo"].(string),
+ LocalAddr: ctxAtta["local-addr"].(string),
+ RemoteAddr: ctxAtta["remote-addr"].(string),
+ UserDefinedStrVal: userDefinedval.InterfaceName,
+ CtxIntVal: ctxAtta["int-value"].(int64),
+ CtxStrVal: ctxAtta["string-value"].(string),
+ }
+ gxlog.CInfo("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (u *UserProvider) Reference() string {
+ return "userProvider"
+}
+
+func (u ContextContent) JavaClassName() string {
+ return "org.apache.dubbo.User"
+}
+
// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run
Review comment:
same above
##########
File path: context/dubbo/go-client/cmd/client.go
##########
@@ -20,50 +20,53 @@ 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 *ContextContent) (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"
Review comment:
Is the type of ContextContent `org.apache.dubbo.User`?
--
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