diff --git a/cluster/support/failover_cluster_invoker.go b/cluster/support/failover_cluster_invoker.go index 39c3d28aa8b9437442700ff159e0cf46c0ad4c71..22c537acb67ebf70973c36dffc057015afe9e47c 100644 --- a/cluster/support/failover_cluster_invoker.go +++ b/cluster/support/failover_cluster_invoker.go @@ -80,6 +80,6 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr ip, _ := gxnet.GetLocalIP() return &protocol.RPCResult{Err: jerrors.Errorf("Failed to invoke the method %v in the service %v . Tried %v times of "+ "the providers %v (%v/%v)from the registry %v on the consumer %v using the dubbo version %v. Last error is %v.", - methodName, invocation, invoker.GetUrl().Service(), retries, providers, len(providers), len(invokers), invoker.directory.GetUrl(), ip, version.Version, result.Error().Error(), + methodName, invocation, invoker.GetUrl().Service(), retries, providers, len(providers), len(invokers), invoker.directory.GetUrl(), ip, version.Version, result.Error(), )} } diff --git a/common/constant/default.go b/common/constant/default.go index 3b2a654eb4c4edf145a6b73d1de2ded0dfc7a169..bfcf304805deecd666b92b03f0de231448fceba4 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -9,7 +9,7 @@ const ( DEFAULT_LOADBALANCE = "random" DEFAULT_RETRIES = 2 DEFAULT_PROTOCOL = "dubbo" - DEFAULT_VERSION = "0.0" + DEFAULT_VERSION = "" DEFAULT_REG_TIMEOUT = "10s" ) diff --git a/common/proxy/proxy.go b/common/proxy/proxy.go index c9a89d5a8e84609a22a8e6fec921762fe9f68d0b..65b0fbf13a7401a422a1bea624bb658bae43b514 100644 --- a/common/proxy/proxy.go +++ b/common/proxy/proxy.go @@ -62,6 +62,7 @@ func (p *Proxy) Implement(v config.RPCService) { result := p.invoke.Invoke(inv) var err error err = result.Error() + log.Info("[makeDubboCallProxy] err: %v", err) return []reflect.Value{reflect.ValueOf(&err).Elem()} } } diff --git a/config/support/provider_config.yml b/config/support/provider_config.yml index 48544e9dc447e413767103b5e09eac8378a09cbc..f6a4c593b04e2cda57dd422fa8f8ccfbf27272fa 100644 --- a/config/support/provider_config.yml +++ b/config/support/provider_config.yml @@ -51,6 +51,7 @@ services: protocols: - name: "dubbo" + # while using dubbo protocol, ip cannot is 127.0.0.1, because client of java-dubbo will get 'connection refuse' ip : "192.168.56.1" port : 20000 - name: "jsonrpc" diff --git a/config/url.go b/config/url.go index 3900e6d032d2ba71fc3f729d77219a338002169b..0d46f621ed8f5a9832dd8ee0a63bb15d65dd9910 100644 --- a/config/url.go +++ b/config/url.go @@ -216,8 +216,8 @@ func (c URL) String() string { func (c URL) Key() string { buildString := fmt.Sprintf( - "%s://%s:%s@%s:%s%s?group=%s&version=%s", - c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Path, c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, constant.DEFAULT_VERSION)) + "%s://%s:%s@%s:%s/%s?group=%s&version=%s", + c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/")), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, constant.DEFAULT_VERSION)) return buildString } diff --git a/examples/dubbo/go-client/app/client.go b/examples/dubbo/go-client/app/client.go index 0cd19e411706d4810b4cc3e31a1f8d5d530a7118..1b29bc00d8798ef70f1dbf9f46aa2d31c97f3c87 100644 --- a/examples/dubbo/go-client/app/client.go +++ b/examples/dubbo/go-client/app/client.go @@ -1,10 +1,9 @@ package main import ( + "context" "fmt" - "github.com/dubbo/dubbo-go/dubbo" - "github.com/dubbo/dubbo-go/plugins" - "github.com/dubbo/dubbo-go/registry/zookeeper" + "github.com/dubbogo/hessian2" "net/http" _ "net/http/pprof" "os" @@ -18,132 +17,62 @@ import ( "github.com/AlexStocks/goext/log" "github.com/AlexStocks/goext/net" log "github.com/AlexStocks/log4go" - jerrors "github.com/juju/errors" ) import ( - "github.com/dubbo/dubbo-go/client/invoker" - "github.com/dubbo/dubbo-go/examples" - "github.com/dubbo/dubbo-go/public" - "github.com/dubbo/dubbo-go/registry" + _ "github.com/dubbo/dubbo-go/protocol/dubbo" + _ "github.com/dubbo/dubbo-go/registry/protocol" + + _ "github.com/dubbo/dubbo-go/filter/imp" + + _ "github.com/dubbo/dubbo-go/cluster/loadbalance" + _ "github.com/dubbo/dubbo-go/cluster/support" + _ "github.com/dubbo/dubbo-go/registry/zookeeper" + + "github.com/dubbo/dubbo-go/config/support" ) var ( survivalTimeout int = 10e9 - clientInvoker *invoker.Invoker ) +// they are necessary: +// export CONF_CONSUMER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" func main() { - clientConfig := examples.InitClientConfig() - initProfiling(clientConfig) - initClient(clientConfig) + hessian.RegisterJavaEnum(Gender(MAN)) + hessian.RegisterJavaEnum(Gender(WOMAN)) + hessian.RegisterPOJO(&User{}) - time.Sleep(3e9) + conMap, _ := support.Load() + if conMap == nil { + panic("conMap is nil") + } - gxlog.CInfo("\n\n\nstart to test dubbo") - testDubborpc(clientConfig, "A003") + initProfiling() time.Sleep(3e9) - initSignal() -} - -func initClient(clientConfig *examples.ClientConfig) { - var ( - err error - codecType public.CodecType - ) - - if clientConfig == nil { - panic(fmt.Sprintf("clientConfig is nil")) - return - } - - // registry - clientRegistry, err := plugins.PluggableRegistries[clientConfig.Registry]( - registry.WithDubboType(registry.CONSUMER), - registry.WithApplicationConf(clientConfig.Application_Config), - zookeeper.WithRegistryConf(clientConfig.ZkRegistryConfig), - ) - if err != nil { - panic(fmt.Sprintf("fail to init registry.Registy, err:%s", jerrors.ErrorStack(err))) - return - } - - // consumer - clientConfig.RequestTimeout, err = time.ParseDuration(clientConfig.Request_Timeout) - if err != nil { - panic(fmt.Sprintf("time.ParseDuration(Request_Timeout{%#v}) = error{%v}", - clientConfig.Request_Timeout, err)) - return - } - clientConfig.ConnectTimeout, err = time.ParseDuration(clientConfig.Connect_Timeout) + gxlog.CInfo("\n\n\nstart to test dubbo") + user := &User{} + err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser(context.TODO(), []interface{}{"A003"}, user) if err != nil { - panic(fmt.Sprintf("time.ParseDuration(Connect_Timeout{%#v}) = error{%v}", - clientConfig.Connect_Timeout, err)) - return + panic(err) } + gxlog.CInfo("response result: %v", user) - for idx := range clientConfig.ServiceConfigList { - codecType = public.GetCodecType(clientConfig.ServiceConfigList[idx].Protocol()) - if codecType == public.CODECTYPE_UNKNOWN { - panic(fmt.Sprintf("unknown protocol %s", clientConfig.ServiceConfigList[idx].Protocol())) - } - } - - for _, service := range clientConfig.ServiceConfigList { - err = clientRegistry.Register(service) - if err != nil { - panic(fmt.Sprintf("registry.Register(service{%#v}) = error{%v}", service, jerrors.ErrorStack(err))) - return - } - } - - //read the client lb config in config.yml - configClientLB := plugins.PluggableLoadbalance[clientConfig.ClientLoadBalance]() - - //init dubbo rpc client & init invoker - var cltD *dubbo.Client - - cltD, err = dubbo.NewClient(&dubbo.ClientConfig{ - PoolSize: 64, - PoolTTL: 600, - ConnectionNum: 2, // 不能太大 - FailFastTimeout: "5s", - SessionTimeout: "20s", - HeartbeatPeriod: "5s", - GettySessionParam: dubbo.GettySessionParam{ - CompressEncoding: false, // 必须false - TcpNoDelay: true, - KeepAlivePeriod: "120s", - TcpRBufSize: 262144, - TcpKeepAlive: true, - TcpWBufSize: 65536, - PkgRQSize: 1024, - PkgWQSize: 512, - TcpReadTimeout: "1s", - TcpWriteTimeout: "5s", - WaitTimeout: "1s", - MaxMsgLen: 1024, - SessionName: "client", - }, - }) + gxlog.CInfo("\n\n\nstart to test dubbo illegal method") + err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user) if err != nil { - log.Error("hessian.NewClient(conf) = error:%s", jerrors.ErrorStack(err)) - return + panic(err) } - clientInvoker, err = invoker.NewInvoker(clientRegistry, - invoker.WithDubboClient(cltD), - invoker.WithLBSelector(configClientLB)) -} -func uninitClient() { - log.Close() + initSignal() } -func initProfiling(clientConfig *examples.ClientConfig) { - if !clientConfig.Pprof_Enabled { +func initProfiling() { + if !support.GetProviderConfig().Pprof_Enabled { return } const ( @@ -159,7 +88,7 @@ func initProfiling(clientConfig *examples.ClientConfig) { if err != nil { panic("cat not get local ip!") } - addr = ip + ":" + strconv.Itoa(clientConfig.Pprof_Port) + addr = ip + ":" + strconv.Itoa(support.GetProviderConfig().Pprof_Port) log.Info("App Profiling startup on address{%v}", addr+PprofPath) go func() { @@ -177,7 +106,7 @@ func initSignal() { log.Info("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: - // reload() + // reload() default: go time.AfterFunc(time.Duration(survivalTimeout)*time.Second, func() { log.Warn("app exit now by force...") @@ -185,7 +114,6 @@ func initSignal() { }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 - uninitClient() fmt.Println("app exit now...") return } diff --git a/examples/dubbo/go-client/app/test.go b/examples/dubbo/go-client/app/test.go deleted file mode 100644 index bea2d95d9af2a46d5e60a2ec540b685e1cc2289d..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-client/app/test.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "fmt" - _ "net/http/pprof" -) - -import ( - // "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" - "github.com/dubbogo/hessian2" - jerrors "github.com/juju/errors" -) - -import ( - "github.com/dubbo/dubbo-go/dubbo" - "github.com/dubbo/dubbo-go/examples" - "github.com/dubbo/dubbo-go/public" -) - -func testDubborpc(clientConfig *examples.ClientConfig, userKey string) { - var ( - err error - svc string - method string - serviceIdx int - user *DubboUser - ) - serviceIdx = -1 - svc = "com.ikurento.user.UserProvider" - for i := range clientConfig.ServiceConfigList { - if clientConfig.ServiceConfigList[i].Service() == svc && clientConfig.ServiceConfigList[i].Protocol() == public.CODECTYPE_DUBBO.String() { - serviceIdx = i - break - } - } - if serviceIdx == -1 { - panic(fmt.Sprintf("can not find service in config service list:%#v", clientConfig.ServiceConfigList)) - } - - // Create request - method = string("GetUser") - - // registry pojo - hessian.RegisterJavaEnum(Gender(MAN)) - hessian.RegisterJavaEnum(Gender(WOMAN)) - hessian.RegisterPOJO(&DubboUser{}) - - user = new(DubboUser) - defer clientInvoker.DubboClient.Close() - err = clientInvoker.DubboCall(1, clientConfig.ServiceConfigList[serviceIdx], method, []interface{}{userKey}, user, dubbo.WithCallRequestTimeout(10e9), dubbo.WithCallResponseTimeout(10e9), dubbo.WithCallSerialID(dubbo.S_Dubbo)) - // Call service - if err != nil { - log.Error("client.Call() return error:%+v", jerrors.ErrorStack(err)) - return - } - - log.Info("response result:%s", user) -} diff --git a/examples/dubbo/go-client/app/user.go b/examples/dubbo/go-client/app/user.go index bc2212f532e9e4d349d92df6fe55d2432931b07a..a0f1d0ae8b4fdc3b69c300651ad27aa0fdfcb131 100644 --- a/examples/dubbo/go-client/app/user.go +++ b/examples/dubbo/go-client/app/user.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "strconv" "time" @@ -10,8 +11,16 @@ import ( "github.com/dubbogo/hessian2" ) +import ( + "github.com/dubbo/dubbo-go/config/support" +) + type Gender hessian.JavaEnum +func init() { + support.SetConService(new(UserProvider)) +} + const ( MAN hessian.JavaEnum = iota WOMAN @@ -49,7 +58,8 @@ func (g Gender) EnumValue(s string) hessian.JavaEnum { return hessian.InvalidJavaEnum } -type DubboUser struct { +type User struct { + // !!! Cannot define lowercase names of variable Id string Name string Age int32 @@ -57,13 +67,26 @@ type DubboUser struct { Sex Gender // 注意此处,java enum Object <--> go string } -func (u DubboUser) String() string { +func (u User) String() string { return fmt.Sprintf( "User{Id:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", u.Id, u.Name, u.Age, u.Time, u.Sex, ) } -func (DubboUser) JavaClassName() string { +func (User) JavaClassName() string { return "com.ikurento.user.User" } + +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error + GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProvider) Service() string { + return "com.ikurento.user.UserProvider" +} + +func (u *UserProvider) Version() string { + return "" +} diff --git a/examples/dubbo/go-client/assembly/bin/load.sh b/examples/dubbo/go-client/assembly/bin/load.sh index 72127283082e62d9d2bdf2a4b4934db56674535b..5bba2a26c858dad918ccd6bc60881151d906d25c 100644 --- a/examples/dubbo/go-client/assembly/bin/load.sh +++ b/examples/dubbo/go-client/assembly/bin/load.sh @@ -23,8 +23,9 @@ else APP_NAME="APPLICATION_NAME.exe" fi -export APP_CONF_FILE=${PROJECT_HOME}"TARGET_CONF_FILE" +export CONF_CONSUMER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" +export CONF_DUBBO_CLIENT_FILE_PATH=${PROJECT_HOME}"TARGET_DUBBO_CONF_FILE" # export GOTRACEBACK=system # export GODEBUG=gctrace=1 diff --git a/examples/dubbo/go-client/assembly/common/app.properties b/examples/dubbo/go-client/assembly/common/app.properties index 8faa3cf4b7cab02291011695b149817d388f9308..07a1814d11b29ccbe5bfcab1e9375a8461e6f943 100644 --- a/examples/dubbo/go-client/assembly/common/app.properties +++ b/examples/dubbo/go-client/assembly/common/app.properties @@ -15,4 +15,4 @@ export BUILD_PACKAGE="app" export TARGET_CONF_FILE="conf/client.yml" export TARGET_LOG_CONF_FILE="conf/log.xml" -export TARGET_DUBBO_CONF_FILE="conf/getty.xml" +export TARGET_DUBBO_CONF_FILE="conf/dubbo-client.yml" diff --git a/examples/dubbo/go-client/assembly/common/build.sh b/examples/dubbo/go-client/assembly/common/build.sh index 00763725b821e54dd0f378b0ec60757837067ef9..c52eb039beb6c8d05e11d3c3f1c16dc9a4baffab 100644 --- a/examples/dubbo/go-client/assembly/common/build.sh +++ b/examples/dubbo/go-client/assembly/common/build.sh @@ -69,6 +69,13 @@ else sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* fi +# modify TARGET_DUBBO_CONF_FILE +if [ ${platform} == "Darwin" ]; then + sed -i "" "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* +else + sed -i "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* +fi + cp -r profiles/${PROFILE}/* ${CONF_DIR} cd ${TARGET_FOLDER} diff --git a/examples/dubbo/go-client/profiles/dev/client.yml b/examples/dubbo/go-client/profiles/dev/client.yml index 9e7f65f36870b13ef9cd433e98480e0bf4ff8d4c..34196bd4233b11b6bdbdb405f94063dd590bf4a8 100644 --- a/examples/dubbo/go-client/profiles/dev/client.yml +++ b/examples/dubbo/go-client/profiles/dev/client.yml @@ -7,13 +7,8 @@ pprof_port : 10086 # client request_timeout : "3500ms" net_io_timeout : "2s" -retries : 1 # connect timeout connect_timeout : "100ms" -selector : "cache" -selector_ttl : "10m" -registry : "zookeeper" -client_load_balance: "round_robin" # application config application_config: @@ -24,12 +19,29 @@ application_config: owner : "ZX" environment : "dev" -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - service : "com.ikurento.user.UserProvider" +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +references: +- registries : + - "hangzhouzk" + - "shanghaizk" + + protocol : "dubbo" + interface : "com.ikurento.user.UserProvider" + cluster: "failover" + methods : + - name: "GetUser" + retries: 3 diff --git a/examples/dubbo/go-client/profiles/dev/dubbo-client.yml b/examples/dubbo/go-client/profiles/dev/dubbo-client.yml new file mode 100644 index 0000000000000000000000000000000000000000..443031d567ec27fe4a2279f68f344618720c2098 --- /dev/null +++ b/examples/dubbo/go-client/profiles/dev/dubbo-client.yml @@ -0,0 +1,21 @@ + +connection_number: 2 +heartbeat_period: "5s" +session_timeout: "20s" +fail_fast_timeout: "5s" +pool_size: 64 +pool_ttl: 600 +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "client" diff --git a/examples/dubbo/go-client/profiles/release/client.yml b/examples/dubbo/go-client/profiles/release/client.yml index 4ce8a0d68ebf17fd464b785f8f652aff52a04c09..34196bd4233b11b6bdbdb405f94063dd590bf4a8 100644 --- a/examples/dubbo/go-client/profiles/release/client.yml +++ b/examples/dubbo/go-client/profiles/release/client.yml @@ -7,13 +7,8 @@ pprof_port : 10086 # client request_timeout : "3500ms" net_io_timeout : "2s" -retries : 1 # connect timeout connect_timeout : "100ms" -selector : "cache" -selector_ttl : "10m" -registry : "zookeeper" -client_load_balance: "round_robin" # application config application_config: @@ -22,14 +17,31 @@ application_config: module : "dubbogo user-info client" version : "0.0.1" owner : "ZX" - environment : "product" + environment : "dev" -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - service : "com.ikurento.user.UserProvider" +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +references: +- registries : + - "hangzhouzk" + - "shanghaizk" + + protocol : "dubbo" + interface : "com.ikurento.user.UserProvider" + cluster: "failover" + methods : + - name: "GetUser" + retries: 3 diff --git a/examples/dubbo/go-client/profiles/release/dubbo-client.yml b/examples/dubbo/go-client/profiles/release/dubbo-client.yml new file mode 100644 index 0000000000000000000000000000000000000000..443031d567ec27fe4a2279f68f344618720c2098 --- /dev/null +++ b/examples/dubbo/go-client/profiles/release/dubbo-client.yml @@ -0,0 +1,21 @@ + +connection_number: 2 +heartbeat_period: "5s" +session_timeout: "20s" +fail_fast_timeout: "5s" +pool_size: 64 +pool_ttl: 600 +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "client" diff --git a/examples/dubbo/go-client/profiles/test/client.yml b/examples/dubbo/go-client/profiles/test/client.yml index 4e7e7a572bd2faea22fdee48f53dd50671eeb16b..34196bd4233b11b6bdbdb405f94063dd590bf4a8 100644 --- a/examples/dubbo/go-client/profiles/test/client.yml +++ b/examples/dubbo/go-client/profiles/test/client.yml @@ -7,13 +7,8 @@ pprof_port : 10086 # client request_timeout : "3500ms" net_io_timeout : "2s" -retries : 1 # connect timeout connect_timeout : "100ms" -selector : "cache" -selector_ttl : "10m" -registry : "zookeeper" -client_load_balance: "round_robin" # application config application_config: @@ -22,14 +17,31 @@ application_config: module : "dubbogo user-info client" version : "0.0.1" owner : "ZX" - environment : "test" + environment : "dev" -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - service : "com.ikurento.user.UserProvider" +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +references: +- registries : + - "hangzhouzk" + - "shanghaizk" + + protocol : "dubbo" + interface : "com.ikurento.user.UserProvider" + cluster: "failover" + methods : + - name: "GetUser" + retries: 3 diff --git a/examples/dubbo/go-client/profiles/test/dubbo-client.yml b/examples/dubbo/go-client/profiles/test/dubbo-client.yml new file mode 100644 index 0000000000000000000000000000000000000000..443031d567ec27fe4a2279f68f344618720c2098 --- /dev/null +++ b/examples/dubbo/go-client/profiles/test/dubbo-client.yml @@ -0,0 +1,21 @@ + +connection_number: 2 +heartbeat_period: "5s" +session_timeout: "20s" +fail_fast_timeout: "5s" +pool_size: 64 +pool_ttl: 600 +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "client" diff --git a/examples/dubbo/go-server/app/config.go b/examples/dubbo/go-server/app/config.go deleted file mode 100644 index cc1422d681ee6f077a4dd41b7581fb7074cf202f..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-server/app/config.go +++ /dev/null @@ -1,129 +0,0 @@ -package main - -import ( - "fmt" - "github.com/dubbo/dubbo-go/plugins" - "io/ioutil" - "os" - "path" - "time" -) - -import ( - "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" - jerrors "github.com/juju/errors" - yaml "gopkg.in/yaml.v2" -) - -import ( - "github.com/dubbo/dubbo-go/registry" - "github.com/dubbo/dubbo-go/registry/zookeeper" - "github.com/dubbo/dubbo-go/server" -) - -const ( - APP_CONF_FILE string = "APP_CONF_FILE" - APP_LOG_CONF_FILE string = "APP_LOG_CONF_FILE" -) - -var ( - conf *ServerConfig -) - -type ( - ServerConfig struct { - // pprof - Pprof_Enabled bool `default:"false" yaml:"pprof_enabled" json:"pprof_enabled,omitempty"` - Pprof_Port int `default:"10086" yaml:"pprof_port" json:"pprof_port,omitempty"` - - // transport & registry - Transport string `default:"http" yaml:"transport" json:"transport,omitempty"` - NetTimeout string `default:"100ms" yaml:"net_timeout" json:"net_timeout,omitempty"` // in ms - netTimeout time.Duration - // application - Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` - // Registry_Address string `default:"192.168.35.3:2181"` - Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` - ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` - - ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` - ServiceConfigList []registry.ReferenceConfig `yaml:"-"` - ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` - Server_List []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"` - } -) - -func initServerConf() *ServerConfig { - var ( - err error - confFile string - ) - - confFile = os.Getenv(APP_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("application configure file name is nil")) - return nil - } - if path.Ext(confFile) != ".yml" { - panic(fmt.Sprintf("application configure file name{%v} suffix must be .yml", confFile)) - return nil - } - - conf = &ServerConfig{} - confFileStream, err := ioutil.ReadFile(confFile) - if err != nil { - panic(fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, jerrors.ErrorStack(err))) - return nil - } - err = yaml.Unmarshal(confFileStream, conf) - if err != nil { - panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err))) - return nil - } - if conf.netTimeout, err = time.ParseDuration(conf.NetTimeout); err != nil { - panic(fmt.Sprintf("time.ParseDuration(NetTimeout:%#v) = error:%s", conf.NetTimeout, err)) - return nil - } - if conf.ZkRegistryConfig.Timeout, err = time.ParseDuration(conf.ZkRegistryConfig.TimeoutStr); err != nil { - panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", - conf.ZkRegistryConfig.TimeoutStr, err)) - return nil - } - - // set designated service_config_type to default - plugins.SetDefaultProviderServiceConfig(conf.ServiceConfigType) - for _, service := range conf.ServiceConfigMapList { - - svc := plugins.DefaultProviderServiceConfig()() - svc.SetProtocol(service["protocol"]) - svc.SetService(service["service"]) - conf.ServiceConfigList = append(conf.ServiceConfigList, svc) - } - - gxlog.CInfo("config{%#v}\n", conf) - - return conf -} - -func configInit() error { - var ( - confFile string - ) - - initServerConf() - - confFile = os.Getenv(APP_LOG_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("log configure file name is nil")) - return nil - } - if path.Ext(confFile) != ".xml" { - panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) - return nil - } - - log.LoadConfiguration(confFile) - - return nil -} diff --git a/examples/dubbo/go-server/app/server.go b/examples/dubbo/go-server/app/server.go index bfc039bf407fba0ab33c3c0f490fa903e01229ee..61099fc368f1af90be15d717d4cd5c172d863166 100644 --- a/examples/dubbo/go-server/app/server.go +++ b/examples/dubbo/go-server/app/server.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/dubbogo/hessian2" "net/http" _ "net/http/pprof" "os" @@ -14,119 +15,49 @@ import ( "github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/time" log "github.com/AlexStocks/log4go" - "github.com/dubbogo/hessian2" - jerrors "github.com/juju/errors" ) import ( - "github.com/dubbo/dubbo-go/dubbo" - "github.com/dubbo/dubbo-go/plugins" - "github.com/dubbo/dubbo-go/registry" - "github.com/dubbo/dubbo-go/registry/zookeeper" + "github.com/dubbo/dubbo-go/config/support" + + _ "github.com/dubbo/dubbo-go/protocol/dubbo" + _ "github.com/dubbo/dubbo-go/protocol/jsonrpc" + _ "github.com/dubbo/dubbo-go/registry/protocol" + + _ "github.com/dubbo/dubbo-go/filter/imp" + + _ "github.com/dubbo/dubbo-go/cluster/loadbalance" + _ "github.com/dubbo/dubbo-go/cluster/support" + _ "github.com/dubbo/dubbo-go/registry/zookeeper" ) var ( survivalTimeout = int(3e9) - servo *dubbo.Server ) +// they are necessary: +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" func main() { - var ( - err error - ) - - err = configInit() - if err != nil { - log.Error("configInit() = error{%#v}", err) - return - } - initProfiling() + // ------for hessian2------ hessian.RegisterJavaEnum(Gender(MAN)) hessian.RegisterJavaEnum(Gender(WOMAN)) - hessian.RegisterPOJO(&DubboUser{}) - - servo = initServer() - err = servo.Register(&UserProvider{}) - if err != nil { - panic(err) - return - } - servo.Start() - - initSignal() -} - -func initServer() *dubbo.Server { - var ( - srv *dubbo.Server - ) - - if conf == nil { - panic(fmt.Sprintf("conf is nil")) - return nil - } - - // registry - - regs, err := plugins.PluggableRegistries[conf.Registry]( - registry.WithDubboType(registry.PROVIDER), - registry.WithApplicationConf(conf.Application_Config), - zookeeper.WithRegistryConf(conf.ZkRegistryConfig), - ) + hessian.RegisterPOJO(&User{}) + // ------------ - if err != nil || regs == nil { - panic(fmt.Sprintf("fail to init registry.Registy, err:%s", jerrors.ErrorStack(err))) - return nil + _, proMap := support.Load() + if proMap == nil { + panic("proMap is nil") } - // generate server config - serverConfig := make([]dubbo.ServerConfig, len(conf.Server_List)) - for i := 0; i < len(conf.Server_List); i++ { - serverConfig[i] = dubbo.ServerConfig{ - SessionNumber: 700, - FailFastTimeout: "5s", - SessionTimeout: "20s", - GettySessionParam: dubbo.GettySessionParam{ - CompressEncoding: false, // 必须false - TcpNoDelay: true, - KeepAlivePeriod: "120s", - TcpRBufSize: 262144, - TcpKeepAlive: true, - TcpWBufSize: 65536, - PkgRQSize: 1024, - PkgWQSize: 512, - TcpReadTimeout: "1s", - TcpWriteTimeout: "5s", - WaitTimeout: "1s", - MaxMsgLen: 1024, - SessionName: "server", - }, - } - serverConfig[i].IP = conf.Server_List[i].IP - serverConfig[i].Port = conf.Server_List[i].Port - serverConfig[i].Protocol = conf.Server_List[i].Protocol - } - - // provider - srv = dubbo.NewServer( - dubbo.Registry(regs), - dubbo.ConfList(serverConfig), - dubbo.ServiceConfList(conf.ServiceConfigList), - ) - - return srv -} + initProfiling() -func uninitServer() { - if servo != nil { - servo.Stop() - } - log.Close() + initSignal() } func initProfiling() { - if !conf.Pprof_Enabled { + if !support.GetProviderConfig().Pprof_Enabled { return } const ( @@ -142,7 +73,7 @@ func initProfiling() { if err != nil { panic("cat not get local ip!") } - addr = ip + ":" + strconv.Itoa(conf.Pprof_Port) + addr = ip + ":" + strconv.Itoa(support.GetProviderConfig().Pprof_Port) log.Info("App Profiling startup on address{%v}", addr+PprofPath) go func() { @@ -159,7 +90,7 @@ func initSignal() { log.Info("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: - // reload() + // reload() default: go gxtime.Future(survivalTimeout, func() { log.Warn("app exit now by force...") @@ -167,7 +98,6 @@ func initSignal() { }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 - uninitServer() fmt.Println("provider app exit now...") return } diff --git a/examples/dubbo/go-server/app/user.go b/examples/dubbo/go-server/app/user.go index fa4f9f992eb8d50ee962527c6b7551125ec2da02..e8c7539f675e7c7fe3346607dc4beee2b47d3a33 100644 --- a/examples/dubbo/go-server/app/user.go +++ b/examples/dubbo/go-server/app/user.go @@ -1,7 +1,6 @@ package main import ( - // "encoding/json" "context" "fmt" "strconv" @@ -13,8 +12,16 @@ import ( "github.com/dubbogo/hessian2" ) +import ( + "github.com/dubbo/dubbo-go/config/support" +) + type Gender hessian.JavaEnum +func init() { + support.SetProService(new(UserProvider)) +} + const ( MAN hessian.JavaEnum = iota WOMAN @@ -53,7 +60,7 @@ func (g Gender) EnumValue(s string) hessian.JavaEnum { } type ( - DubboUser struct { + User struct { // !!! Cannot define lowercase names of variable Id string Name string @@ -63,42 +70,42 @@ type ( } UserProvider struct { - user map[string]DubboUser + user map[string]User } ) -func (u DubboUser) String() string { - return fmt.Sprintf( - "User{Id:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", - u.Id, u.Name, u.Age, u.Time, u.Sex, - ) -} - -func (DubboUser) JavaClassName() string { - return "com.ikurento.user.User" -} - var ( - DefaultUser = DubboUser{ + DefaultUser = User{ Id: "0", Name: "Alex Stocks", Age: 31, Sex: Gender(MAN), } - userMap = UserProvider{user: make(map[string]DubboUser)} + userMap = UserProvider{user: make(map[string]User)} ) func init() { - //DefaultUser.Sex = DefaultUser.sex.String() userMap.user["A000"] = DefaultUser - userMap.user["A001"] = DubboUser{Id: "001", Name: "ZhangSheng", Age: 18, Sex: Gender(MAN)} - userMap.user["A002"] = DubboUser{Id: "002", Name: "Lily", Age: 20, Sex: Gender(WOMAN)} - userMap.user["A003"] = DubboUser{Id: "113", Name: "Moorse", Age: 30, Sex: Gender(WOMAN)} + userMap.user["A001"] = User{Id: "001", Name: "ZhangSheng", Age: 18, Sex: Gender(MAN)} + userMap.user["A002"] = User{Id: "002", Name: "Lily", Age: 20, Sex: Gender(WOMAN)} + userMap.user["A003"] = User{Id: "113", Name: "Moorse", Age: 30, Sex: Gender(WOMAN)} for k, v := range userMap.user { + v.Time = time.Now() userMap.user[k] = v } } -func (u *UserProvider) getUser(userId string) (*DubboUser, error) { +func (u User) String() string { + return fmt.Sprintf( + "User{Id:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", + u.Id, u.Name, u.Age, u.Time, u.Sex, + ) +} + +func (u User) JavaClassName() string { + return "com.ikurento.user.User" +} + +func (u *UserProvider) getUser(userId string) (*User, error) { if user, ok := userMap.user[userId]; ok { return &user, nil } @@ -106,13 +113,10 @@ func (u *UserProvider) getUser(userId string) (*DubboUser, error) { return nil, fmt.Errorf("invalid user id:%s", userId) } -/* - !!! req must be []interface{} -*/ -func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *DubboUser) error { +func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { var ( err error - user *DubboUser + user *User ) gxlog.CInfo("req:%#v", req) @@ -120,6 +124,11 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *Dubb if err == nil { *rsp = *user gxlog.CInfo("rsp:%#v", rsp) + // s, _ := json.Marshal(rsp) + // fmt.Println("hello0:", string(s)) + + // s, _ = json.Marshal(*rsp) + // fmt.Println("hello1:", string(s)) } return err } diff --git a/examples/dubbo/go-server/assembly/bin/load.sh b/examples/dubbo/go-server/assembly/bin/load.sh index e202ff65f436f08191ae5364378f659de858777a..f89c45255f4184c1ceece951c58252e56c4bd984 100644 --- a/examples/dubbo/go-server/assembly/bin/load.sh +++ b/examples/dubbo/go-server/assembly/bin/load.sh @@ -20,8 +20,9 @@ if [[ ${OS_NAME} != "Windows" ]]; then PROJECT_HOME=${PROJECT_HOME}"/" fi -export APP_CONF_FILE=${PROJECT_HOME}"TARGET_CONF_FILE" +export CONF_PROVIDER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" +export CONF_DUBBO_SERVER_FILE_PATH=${PROJECT_HOME}"TARGET_DUBBO_CONF_FILE" usage() { echo "Usage: $0 start" diff --git a/examples/dubbo/go-server/assembly/common/app.properties b/examples/dubbo/go-server/assembly/common/app.properties index d230d5efc4ee84c4a99e1b27e7b49d97046d91a3..53eb3a553864e0aea2f103a579ed6d1312b433d0 100644 --- a/examples/dubbo/go-server/assembly/common/app.properties +++ b/examples/dubbo/go-server/assembly/common/app.properties @@ -15,3 +15,4 @@ BUILD_PACKAGE="app" TARGET_CONF_FILE="conf/server.yml" TARGET_LOG_CONF_FILE="conf/log.xml" +TARGET_DUBBO_CONF_FILE="conf/dubbo-server.yml" diff --git a/examples/dubbo/go-server/assembly/common/build.sh b/examples/dubbo/go-server/assembly/common/build.sh index a41fbbac321b74849d71b28a65f8b7c5de13cf0f..ddc40e4e0c36432eb0a2a73f06f7dd6b4343f354 100644 --- a/examples/dubbo/go-server/assembly/common/build.sh +++ b/examples/dubbo/go-server/assembly/common/build.sh @@ -65,6 +65,12 @@ if [ "$(uname)" == "Darwin" ]; then else sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* fi +#modify TARGET_DUBBO_CONF_FILE +if [ "$(uname)" == "Darwin" ]; then + sed -i "" "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* +else + sed -i "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* +fi cp -r profiles/${PROFILE}/* ${CONF_DIR} diff --git a/examples/jsonrpc/go-server/profiles/dev/dubbo-server.yml b/examples/dubbo/go-server/profiles/dev/dubbo-server.yml similarity index 100% rename from examples/jsonrpc/go-server/profiles/dev/dubbo-server.yml rename to examples/dubbo/go-server/profiles/dev/dubbo-server.yml diff --git a/examples/dubbo/go-server/profiles/dev/server.yml b/examples/dubbo/go-server/profiles/dev/server.yml index 3eb4df6112275fd9ffebe7a416c39a1259867512..f055b1610caf5333b6fa2bd50c91a18088556386 100644 --- a/examples/dubbo/go-server/profiles/dev/server.yml +++ b/examples/dubbo/go-server/profiles/dev/server.yml @@ -8,6 +8,7 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: organization : "ikurento.com" @@ -17,23 +18,42 @@ application_config: owner : "ZX" environment : "dev" -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - # 相当于dubbo.xml中的interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - # 如果是127.0.0.1, java-client将无法连接到go-server - ip : "192.168.56.1" - port : 20000 - # 本server能够提供所有支持同样的Protocol的servicelist的服务 - protocol : "dubbo" +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo" + # 相当于dubbo.xml中的interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "192.168.56.1" + port : 20000 +#- name: "jsonrpc" +# ip: "127.0.0.1" +# port: 20001 + diff --git a/examples/jsonrpc/go-server/profiles/release/dubbo-server.yml b/examples/dubbo/go-server/profiles/release/dubbo-server.yml similarity index 100% rename from examples/jsonrpc/go-server/profiles/release/dubbo-server.yml rename to examples/dubbo/go-server/profiles/release/dubbo-server.yml diff --git a/examples/dubbo/go-server/profiles/release/server.yml b/examples/dubbo/go-server/profiles/release/server.yml index e61274ea0977f2a193572cddc2ec996e07c220b0..f055b1610caf5333b6fa2bd50c91a18088556386 100644 --- a/examples/dubbo/go-server/profiles/release/server.yml +++ b/examples/dubbo/go-server/profiles/release/server.yml @@ -8,6 +8,7 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: organization : "ikurento.com" @@ -15,24 +16,44 @@ application_config: module : "dubbogo user-info server" version : "0.0.1" owner : "ZX" - environment : "product" - -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - # 相当于dubbo.xml中的interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - ip : "127.0.0.1" - port : 20000 - # 本server能够提供所有支持同样的Protocol的servicelist的服务 - protocol : "dubbo" + environment : "dev" + +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo" + # 相当于dubbo.xml中的interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "192.168.56.1" + port : 20000 +#- name: "jsonrpc" +# ip: "127.0.0.1" +# port: 20001 + diff --git a/examples/jsonrpc/go-server/profiles/test/dubbo-server.yml b/examples/dubbo/go-server/profiles/test/dubbo-server.yml similarity index 100% rename from examples/jsonrpc/go-server/profiles/test/dubbo-server.yml rename to examples/dubbo/go-server/profiles/test/dubbo-server.yml diff --git a/examples/dubbo/go-server/profiles/test/server.yml b/examples/dubbo/go-server/profiles/test/server.yml index cc73b9b642f2ba7f36c781f72e153b0547e7e8ce..f055b1610caf5333b6fa2bd50c91a18088556386 100644 --- a/examples/dubbo/go-server/profiles/test/server.yml +++ b/examples/dubbo/go-server/profiles/test/server.yml @@ -8,6 +8,7 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: organization : "ikurento.com" @@ -15,24 +16,44 @@ application_config: module : "dubbogo user-info server" version : "0.0.1" owner : "ZX" - environment : "test" - -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "dubbo" - # 相当于dubbo.xml中的interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - ip : "127.0.0.1" - port : 20000 - # 本server能够提供所有支持同样的Protocol的servicelist的服务 - protocol : "dubbo" + environment : "dev" + +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo" + # 相当于dubbo.xml中的interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "192.168.56.1" + port : 20000 +#- name: "jsonrpc" +# ip: "127.0.0.1" +# port: 20001 + diff --git a/examples/jsonrpc/go-client/app/client.go b/examples/jsonrpc/go-client/app/client.go index f75749b44609a85635cbac6cca6b285f9d57c94b..f120a54455a8389328ca3884a0d9715c2e21ef4e 100644 --- a/examples/jsonrpc/go-client/app/client.go +++ b/examples/jsonrpc/go-client/app/client.go @@ -37,7 +37,6 @@ var ( // they are necessary: // export CONF_CONSUMER_FILE_PATH="xxx" -// export CONF_PROVIDER_FILE_PATH="xxx" // export APP_LOG_CONF_FILE="xxx" func main() { diff --git a/examples/jsonrpc/go-client/assembly/bin/load.sh b/examples/jsonrpc/go-client/assembly/bin/load.sh index 72127283082e62d9d2bdf2a4b4934db56674535b..63bb08a3b1ff8f0790df1b2a04285bbfefe10407 100644 --- a/examples/jsonrpc/go-client/assembly/bin/load.sh +++ b/examples/jsonrpc/go-client/assembly/bin/load.sh @@ -23,7 +23,7 @@ else APP_NAME="APPLICATION_NAME.exe" fi -export APP_CONF_FILE=${PROJECT_HOME}"TARGET_CONF_FILE" +export CONF_CONSUMER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" # export GOTRACEBACK=system # export GODEBUG=gctrace=1 diff --git a/examples/jsonrpc/go-client/profiles/release/client.yml b/examples/jsonrpc/go-client/profiles/release/client.yml index ddfcc614fc92db1efac780e83144bb2971d5a04b..3b923bc48cdf40de7c6c7a91bcd1f9bfd85a6dfa 100644 --- a/examples/jsonrpc/go-client/profiles/release/client.yml +++ b/examples/jsonrpc/go-client/profiles/release/client.yml @@ -12,12 +12,12 @@ connect_timeout : "100ms" # application config application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "dev" + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info client" + version : "0.0.1" + owner : "ZX" + environment : "dev" registries : - id: "hangzhouzk" @@ -27,17 +27,18 @@ registries : username: "" password: "" -#- id: "shanghaizk" -# type: "zookeeper" -# timeout : "3s" -# address: "127.0.0.1:2181" -# username: "" -# password: "" +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" references: - registries : - "hangzhouzk" - # - "shanghaizk" + - "shanghaizk" + protocol : "jsonrpc" interface : "com.ikurento.user.UserProvider" cluster: "failover" diff --git a/examples/jsonrpc/go-client/profiles/test/client.yml b/examples/jsonrpc/go-client/profiles/test/client.yml index ddfcc614fc92db1efac780e83144bb2971d5a04b..3b923bc48cdf40de7c6c7a91bcd1f9bfd85a6dfa 100644 --- a/examples/jsonrpc/go-client/profiles/test/client.yml +++ b/examples/jsonrpc/go-client/profiles/test/client.yml @@ -12,12 +12,12 @@ connect_timeout : "100ms" # application config application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info client" - version : "0.0.1" - owner : "ZX" - environment : "dev" + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info client" + version : "0.0.1" + owner : "ZX" + environment : "dev" registries : - id: "hangzhouzk" @@ -27,17 +27,18 @@ registries : username: "" password: "" -#- id: "shanghaizk" -# type: "zookeeper" -# timeout : "3s" -# address: "127.0.0.1:2181" -# username: "" -# password: "" +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" references: - registries : - "hangzhouzk" - # - "shanghaizk" + - "shanghaizk" + protocol : "jsonrpc" interface : "com.ikurento.user.UserProvider" cluster: "failover" diff --git a/examples/jsonrpc/go-server/app/server.go b/examples/jsonrpc/go-server/app/server.go index 24be42b57d8d68c12d56f8d423cf1567a3b42706..de0adfa82e51920b57ead590fed15959ebdf3ba0 100644 --- a/examples/jsonrpc/go-server/app/server.go +++ b/examples/jsonrpc/go-server/app/server.go @@ -19,7 +19,6 @@ import ( import ( "github.com/dubbo/dubbo-go/config/support" - _ "github.com/dubbo/dubbo-go/protocol/dubbo" _ "github.com/dubbo/dubbo-go/protocol/jsonrpc" _ "github.com/dubbo/dubbo-go/registry/protocol" @@ -35,7 +34,6 @@ var ( ) // they are necessary: -// export CONF_CONSUMER_FILE_PATH="xxx" // export CONF_PROVIDER_FILE_PATH="xxx" // export APP_LOG_CONF_FILE="xxx" func main() { diff --git a/examples/jsonrpc/go-server/assembly/bin/load.sh b/examples/jsonrpc/go-server/assembly/bin/load.sh index f89c45255f4184c1ceece951c58252e56c4bd984..b1e7a976665722a525c9633c682f6e3e9a5e4cab 100644 --- a/examples/jsonrpc/go-server/assembly/bin/load.sh +++ b/examples/jsonrpc/go-server/assembly/bin/load.sh @@ -22,7 +22,6 @@ fi export CONF_PROVIDER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" -export CONF_DUBBO_SERVER_FILE_PATH=${PROJECT_HOME}"TARGET_DUBBO_CONF_FILE" usage() { echo "Usage: $0 start" diff --git a/examples/jsonrpc/go-server/assembly/common/app.properties b/examples/jsonrpc/go-server/assembly/common/app.properties index 53eb3a553864e0aea2f103a579ed6d1312b433d0..d230d5efc4ee84c4a99e1b27e7b49d97046d91a3 100644 --- a/examples/jsonrpc/go-server/assembly/common/app.properties +++ b/examples/jsonrpc/go-server/assembly/common/app.properties @@ -15,4 +15,3 @@ BUILD_PACKAGE="app" TARGET_CONF_FILE="conf/server.yml" TARGET_LOG_CONF_FILE="conf/log.xml" -TARGET_DUBBO_CONF_FILE="conf/dubbo-server.yml" diff --git a/examples/jsonrpc/go-server/assembly/common/build.sh b/examples/jsonrpc/go-server/assembly/common/build.sh index ddc40e4e0c36432eb0a2a73f06f7dd6b4343f354..a41fbbac321b74849d71b28a65f8b7c5de13cf0f 100644 --- a/examples/jsonrpc/go-server/assembly/common/build.sh +++ b/examples/jsonrpc/go-server/assembly/common/build.sh @@ -65,12 +65,6 @@ if [ "$(uname)" == "Darwin" ]; then else sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* fi -#modify TARGET_DUBBO_CONF_FILE -if [ "$(uname)" == "Darwin" ]; then - sed -i "" "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* -else - sed -i "s~TARGET_DUBBO_CONF_FILE~${TARGET_DUBBO_CONF_FILE}~g" ${BIN_DIR}/bin/* -fi cp -r profiles/${PROFILE}/* ${CONF_DIR} diff --git a/examples/jsonrpc/go-server/profiles/dev/server.yml b/examples/jsonrpc/go-server/profiles/dev/server.yml index 45a0c4612064570d0e0bdccc17ea2607bf7c067f..b9e836fb679ce962835bf1ddf0178af0f9ff66e9 100644 --- a/examples/jsonrpc/go-server/profiles/dev/server.yml +++ b/examples/jsonrpc/go-server/profiles/dev/server.yml @@ -50,9 +50,9 @@ services: loadbalance: "random" protocols: -- name: "dubbo" - ip : "127.0.0.1" - port : 20000 +#- name: "dubbo" +# ip : "127.0.0.1" +# port : 20000 - name: "jsonrpc" ip: "127.0.0.1" port: 20001 diff --git a/examples/jsonrpc/go-server/profiles/release/server.yml b/examples/jsonrpc/go-server/profiles/release/server.yml index db0753cb8a74e6dbe1ebe6ca712e169567fa6beb..0fb9d5d55d7f02dfb0ea86a0844e57deb43796a2 100644 --- a/examples/jsonrpc/go-server/profiles/release/server.yml +++ b/examples/jsonrpc/go-server/profiles/release/server.yml @@ -11,12 +11,12 @@ net_timeout : "3s" path: "" # application config application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "pro" + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info server" + version : "0.0.1" + owner : "ZX" + environment : "dev" registries : - id: "hangzhouzk" @@ -26,20 +26,20 @@ registries : username: "" password: "" -#- id: "shanghaizk" -# type: "zookeeper" -# timeout : "3s" -# address: "127.0.0.1:2182" -# username: "" -# password: "" +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" services: - registries: - "hangzhouzk" -# - "shanghaizk" - protocol : "dubbo,jsonrpc" - # 相当于dubbo.xml中的interface + - "shanghaizk" + protocol : "jsonrpc" + # 相当于dubbo.xml中的interface interface : "com.ikurento.user.UserProvider" loadbalance: "random" warmup: "100" @@ -50,9 +50,9 @@ services: loadbalance: "random" protocols: -- name: "dubbo" - ip : "127.0.0.1" - port : 20000 +#- name: "dubbo" +# ip : "127.0.0.1" +# port : 20000 - name: "jsonrpc" ip: "127.0.0.1" port: 20001 diff --git a/examples/jsonrpc/go-server/profiles/test/server.yml b/examples/jsonrpc/go-server/profiles/test/server.yml index a12531164a573cfb5e7fe83ba47a4507f6abe7f3..0fb9d5d55d7f02dfb0ea86a0844e57deb43796a2 100644 --- a/examples/jsonrpc/go-server/profiles/test/server.yml +++ b/examples/jsonrpc/go-server/profiles/test/server.yml @@ -16,7 +16,7 @@ application_config: module : "dubbogo user-info server" version : "0.0.1" owner : "ZX" - environment : "test" + environment : "dev" registries : - id: "hangzhouzk" @@ -26,19 +26,19 @@ registries : username: "" password: "" -#- id: "shanghaizk" -# type: "zookeeper" -# timeout : "3s" -# address: "127.0.0.1:2182" -# username: "" -# password: "" +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" services: - registries: - "hangzhouzk" -# - "shanghaizk" - protocol : "dubbo,jsonrpc" + - "shanghaizk" + protocol : "jsonrpc" # 相当于dubbo.xml中的interface interface : "com.ikurento.user.UserProvider" loadbalance: "random" @@ -50,9 +50,9 @@ services: loadbalance: "random" protocols: -- name: "dubbo" - ip : "127.0.0.1" - port : 20000 +#- name: "dubbo" +# ip : "127.0.0.1" +# port : 20000 - name: "jsonrpc" ip: "127.0.0.1" port: 20001 diff --git a/examples/jsonrpc/java-client/src/main/resources/dubbo.properties b/examples/jsonrpc/java-client/src/main/resources/dubbo.properties deleted file mode 100644 index fc7b9aedd4260e82ab5f88327dca8728092c51b4..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/java-client/src/main/resources/dubbo.properties +++ /dev/null @@ -1,13 +0,0 @@ -### dubboע���������� ### -dubbo.container = log4j,spring -dubbo.application.name = user-info-client -dubbo.application.owner = AlexStocks -dubbo.application.environment = product -dubbo.registry.address = zookeeper://127.0.0.1:2181 -dubbo.monitor.protocol = zookeeper -dubbo.consumer.timeout = 10000 -dubbo.provider.timeout = 10000 -dubbo.protocol.name = jsonrpc - -dubbo.log4j.file = logs/client.log -dubbo.log4j.level = WARN diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 3823674e209480b3cadb12c073c9fc451c3c8ef3..4ce4b4429242b6c06aa02118d6b34c1e22711ec3 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -198,7 +198,7 @@ func (c *Client) call(ct CallType, addr string, svcUrl config.URL, method string p := &DubboPackage{} p.Service.Path = strings.TrimPrefix(svcUrl.Path, "/") - p.Service.Target = strings.TrimPrefix(svcUrl.Path, "/") + p.Service.Target = svcUrl.GetParam(constant.INTERFACE_KEY, "") p.Service.Version = svcUrl.GetParam(constant.VERSION_KEY, constant.DEFAULT_VERSION) p.Service.Method = method p.Service.Timeout = opts.RequestTimeout diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index 02c7785103d383c46b821848eecc9fabf3664cd3..278881820e864f643d8a6cf69432d0b089012cd6 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -53,13 +53,16 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { } else { result.Err = di.client.CallOneway(url.Location, url, inv.MethodName(), inv.Arguments()) } + log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest) } else { if inv.Reply() == nil { result.Err = Err_No_Reply } else { + result.Err = di.client.Call(url.Location, url, inv.MethodName(), inv.Arguments(), inv.Reply()) result.Rest = inv.Reply() // reply should be set to result.Rest when sync } + log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest) } return &result diff --git a/protocol/jsonrpc/jsonrpc_invoker.go b/protocol/jsonrpc/jsonrpc_invoker.go index 9e5313c7ef7da7d46c81675be4a709f1a4e7560f..5aaf955c1748694f97d5dee6f1a53c9a790de74b 100644 --- a/protocol/jsonrpc/jsonrpc_invoker.go +++ b/protocol/jsonrpc/jsonrpc_invoker.go @@ -46,6 +46,7 @@ func (ji *JsonrpcInvoker) Invoke(invocation protocol.Invocation) protocol.Result log.Error("client.Call() return error:%+v", jerrors.ErrorStack(err)) result.Err = err } else { + log.Debug("result: %v", inv.Reply()) result.Rest = inv.Reply() } diff --git a/registry/directory/directory.go b/registry/directory/directory.go index aed91a67be31c1571a65d4efe0c13357ad2d8867..9124d94a0bddc18a769af8865ae9d156ac08408b 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -175,7 +175,6 @@ func (dir *RegistryDirectory) uncacheInvoker(url config.URL) *sync.Map { } func (dir *RegistryDirectory) cacheInvoker(url config.URL) *sync.Map { - referenceUrl := dir.GetUrl().SubURL newCacheInvokers := dir.cacheInvokersMap //check the url's protocol is equal to the protocol which is configured in reference config or referenceUrl is not care about protocol