Skip to content
Snippets Groups Projects
Commit 54f42990 authored by vito.he's avatar vito.he
Browse files

Mod:resolve conflict

parents 22771a27 10d0f0f1
No related branches found
No related tags found
No related merge requests found
Showing
with 224 additions and 149 deletions
......@@ -27,7 +27,6 @@ const (
DEFAULT_LOADBALANCE = "random"
DEFAULT_RETRIES = 2
DEFAULT_PROTOCOL = "dubbo"
DEFAULT_VERSION = ""
DEFAULT_REG_TIMEOUT = "10s"
DEFAULT_CLUSTER = "failover"
)
......@@ -38,3 +37,7 @@ const (
DEFAULT_REFERENCE_FILTERS = ""
ECHO = "$echo"
)
const (
ANY_VALUE = "*"
)
......@@ -44,6 +44,7 @@ const (
WEIGHT_KEY = "weight"
WARMUP_KEY = "warmup"
RETRIES_KEY = "retries"
BEAN_NAME = "bean.name"
)
const (
......
......@@ -56,7 +56,7 @@ func init() {
logConfFile := os.Getenv(constant.APP_LOG_CONF_FILE)
err := InitLog(logConfFile)
if err != nil {
log.Printf("[InitLog] error: %v", err)
log.Printf("[InitLog] warn: %v", err)
}
}
......@@ -110,7 +110,7 @@ func InitLogger(conf *zap.Config) {
} else {
zapLoggerConfig = *conf
}
zapLogger, _ := zapLoggerConfig.Build()
zapLogger, _ := zapLoggerConfig.Build(zap.AddCallerSkip(1))
logger = zapLogger.Sugar()
}
......
......@@ -19,6 +19,7 @@ package proxy
import (
"reflect"
"sync"
)
import (
......@@ -34,6 +35,8 @@ type Proxy struct {
invoke protocol.Invoker
callBack interface{}
attachments map[string]string
once sync.Once
}
var typError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem()).Type()
......@@ -78,23 +81,31 @@ func (p *Proxy) Implement(v common.RPCService) {
methodName = "$echo"
}
start := 0
end := len(in)
if in[0].Type().String() == "context.Context" {
start += 1
}
if len(outs) == 1 {
end -= 1
reply = in[len(in)-1]
} else {
if len(outs) == 2 {
if outs[0].Kind() == reflect.Ptr {
reply = reflect.New(outs[0].Elem())
} else {
reply = reflect.New(outs[0])
}
} else {
reply = valueOf
}
start := 0
end := len(in)
if end > 0 {
if in[0].Type().String() == "context.Context" {
start += 1
}
if len(outs) == 1 && in[end-1].Type().Kind() == reflect.Ptr {
end -= 1
reply = in[len(in)-1]
}
}
if v, ok := in[start].Interface().([]interface{}); ok && end-start == 1 {
if end-start <= 0 {
inArr = []interface{}{}
} else if v, ok := in[start].Interface().([]interface{}); ok && end-start == 1 {
inArr = v
} else {
inArr = make([]interface{}, end-start)
......@@ -134,7 +145,6 @@ func (p *Proxy) Implement(v common.RPCService) {
}
f := valueOfElem.Field(i)
if f.Kind() == reflect.Func && f.IsValid() && f.CanSet() {
inNum := t.Type.NumIn()
outNum := t.Type.NumOut()
if outNum != 1 && outNum != 2 {
......@@ -149,12 +159,6 @@ func (p *Proxy) Implement(v common.RPCService) {
continue
}
// reply must be Ptr when outNum == 1
if outNum == 1 && t.Type.In(inNum-1).Kind() != reflect.Ptr {
logger.Warnf("reply type of method %q is not a pointer", t.Name)
continue
}
var funcOuts = make([]reflect.Type, outNum)
for i := 0; i < outNum; i++ {
funcOuts[i] = t.Type.Out(i)
......@@ -166,7 +170,9 @@ func (p *Proxy) Implement(v common.RPCService) {
}
}
p.rpc = v
p.once.Do(func() {
p.rpc = v
})
}
......
......@@ -51,6 +51,6 @@ func (factory *DefaultProxyFactory) GetProxy(invoker protocol.Invoker, url *comm
return proxy.NewProxy(invoker, nil, attachments)
}
func (factory *DefaultProxyFactory) GetInvoker(url common.URL) protocol.Invoker {
//TODO:yincheng need to do the service invoker refactor
// todo: call service
return protocol.NewBaseInvoker(url)
}
......@@ -21,22 +21,25 @@ import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/protocol"
"github.com/stretchr/testify/assert"
)
func Test_GetProxy(t *testing.T) {
proxyFactory := NewDefaultProxyFactory()
url := common.NewURLWithOptions("testservice")
url := common.NewURLWithOptions()
proxy := proxyFactory.GetProxy(protocol.NewBaseInvoker(*url), url)
assert.NotNil(t, proxy)
}
func Test_GetInvoker(t *testing.T) {
proxyFactory := NewDefaultProxyFactory()
url := common.NewURLWithOptions("testservice")
url := common.NewURLWithOptions()
invoker := proxyFactory.GetInvoker(*url)
assert.True(t, invoker.IsAvailable())
}
......@@ -36,9 +36,10 @@ import (
type TestService struct {
MethodOne func(context.Context, int, bool, *interface{}) error
MethodTwo func([]interface{}, *interface{}) error
MethodTwo func([]interface{}) error
MethodThree func(int, bool) (interface{}, error)
MethodFour func(int, bool) (*interface{}, error) `dubbo:"methodFour"`
MethodFive func() error
Echo func(interface{}, *interface{}) error
}
......@@ -64,19 +65,25 @@ func TestProxy_Implement(t *testing.T) {
p := NewProxy(invoker, nil, map[string]string{constant.ASYNC_KEY: "false"})
s := &TestService{}
p.Implement(s)
err := p.Get().(*TestService).MethodOne(nil, 0, false, nil)
assert.NoError(t, err)
err = p.Get().(*TestService).MethodTwo(nil, nil)
err = p.Get().(*TestService).MethodTwo(nil)
assert.NoError(t, err)
ret, err := p.Get().(*TestService).MethodThree(0, false)
assert.NoError(t, err)
assert.Nil(t, ret) // ret is nil, because it doesn't be injection yet
ret2, err := p.Get().(*TestService).MethodFour(0, false)
assert.NoError(t, err)
assert.Equal(t, "*interface {}", reflect.TypeOf(ret2).String())
err = p.Get().(*TestService).Echo(nil, nil)
assert.NoError(t, err)
err = p.Get().(*TestService).MethodFive()
assert.NoError(t, err)
// inherit & lowercase
p.rpc = nil
type S1 struct {
......@@ -108,24 +115,14 @@ func TestProxy_Implement(t *testing.T) {
p.Implement(s2)
assert.Nil(t, s2.MethodOne)
// reply type
// returns type
p.rpc = nil
type S3 struct {
TestService
MethodOne func(context.Context, []interface{}, struct{}) error
MethodOne func(context.Context, []interface{}, *struct{}) interface{}
}
s3 := &S3{TestService: *s}
p.Implement(s3)
assert.Nil(t, s3.MethodOne)
// returns type
p.rpc = nil
type S4 struct {
TestService
MethodOne func(context.Context, []interface{}, *struct{}) interface{}
}
s4 := &S4{TestService: *s}
p.Implement(s4)
assert.Nil(t, s4.MethodOne)
}
......@@ -40,6 +40,12 @@ type RPCService interface {
Version() string
}
// for lowercase func
// func MethodMapper() map[string][string] {
// return map[string][string]{}
// }
const METHOD_MAPPER = "MethodMapper"
var (
// Precompute the reflect type for error. Can't use error directly
// because Typeof takes an empty interface value. This is annoying.
......@@ -210,20 +216,26 @@ func isExportedOrBuiltinType(t reflect.Type) bool {
// suitableMethods returns suitable Rpc methods of typ
func suitableMethods(typ reflect.Type) (string, map[string]*MethodType) {
methods := make(map[string]*MethodType)
mts := ""
var mts []string
logger.Debugf("[%s] NumMethod is %d", typ.String(), typ.NumMethod())
method, ok := typ.MethodByName(METHOD_MAPPER)
var methodMapper map[string]string
if ok && method.Type.NumIn() == 1 && method.Type.NumOut() == 1 && method.Type.Out(0).String() == "map[string]string" {
methodMapper = method.Func.Call([]reflect.Value{reflect.New(typ.Elem())})[0].Interface().(map[string]string)
}
for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m)
method = typ.Method(m)
if mt := suiteMethod(method); mt != nil {
methods[method.Name] = mt
if m == 0 {
mts += method.Name
} else {
mts += "," + method.Name
methodName, ok := methodMapper[method.Name]
if !ok {
methodName = method.Name
}
methods[methodName] = mt
mts = append(mts, methodName)
}
}
return mts, methods
return strings.Join(mts, ","), methods
}
// suiteMethod returns a suitable Rpc methodType
......@@ -256,12 +268,7 @@ func suiteMethod(method reflect.Method) *MethodType {
}
// replyType
if outNum == 1 {
if mtype.In(inNum-1).Kind() != reflect.Ptr {
logger.Errorf("reply type of method %q is not a pointer %v", mname, replyType)
return nil
}
} else {
if outNum == 2 {
replyType = mtype.Out(0)
if !isExportedOrBuiltinType(replyType) {
logger.Errorf("reply type of method %s not exported{%v}", mname, replyType)
......@@ -272,7 +279,7 @@ func suiteMethod(method reflect.Method) *MethodType {
index := 1
// ctxType
if mtype.In(1).String() == "context.Context" {
if inNum > 1 && mtype.In(1).String() == "context.Context" {
ctxType = mtype.In(1)
index = 2
}
......
......@@ -30,18 +30,26 @@ import (
type TestService struct {
}
func (s *TestService) MethodOne(ctx context.Context, args []interface{}, rsp *struct{}) error {
func (s *TestService) MethodOne(ctx context.Context, arg1, arg2, arg3 interface{}) error {
return nil
}
func (s *TestService) MethodTwo(args []interface{}) (struct{}, error) {
func (s *TestService) MethodTwo(arg1, arg2, arg3 interface{}) (interface{}, error) {
return struct{}{}, nil
}
func (s *TestService) MethodThree() error {
return nil
}
func (s *TestService) Service() string {
return "com.test.Path"
}
func (s *TestService) Version() string {
return ""
}
func (s *TestService) MethodMapper() map[string]string {
return map[string]string{
"MethodTwo": "methodTwo",
}
}
type testService struct {
}
......@@ -49,15 +57,12 @@ type testService struct {
func (s *testService) Method1(ctx context.Context, args testService, rsp *struct{}) error {
return nil
}
func (s *testService) Method2(ctx context.Context, args []interface{}, rsp struct{}) error {
return nil
}
func (s *testService) Method3(ctx context.Context, args []interface{}) (testService, error) {
func (s *testService) Method2(ctx context.Context, args []interface{}) (testService, error) {
return testService{}, nil
}
func (s *testService) Method4(ctx context.Context, args []interface{}, rsp *struct{}) {
func (s *testService) Method3(ctx context.Context, args []interface{}, rsp *struct{}) {
}
func (s *testService) Method5(ctx context.Context, args []interface{}, rsp *struct{}) *testService {
func (s *testService) Method4(ctx context.Context, args []interface{}, rsp *struct{}) *testService {
return nil
}
func (s *testService) Service() string {
......@@ -87,7 +92,7 @@ func TestServiceMap_Register(t *testing.T) {
s := &TestService{}
methods, err = ServiceMap.Register("testporotocol", s)
assert.NoError(t, err)
assert.Equal(t, "MethodOne,MethodTwo", methods)
assert.Equal(t, "MethodOne,MethodThree,methodTwo", methods)
// repeat
methods, err = ServiceMap.Register("testporotocol", s)
......@@ -139,10 +144,11 @@ func TestSuiteMethod(t *testing.T) {
assert.True(t, ok)
methodType := suiteMethod(method)
method = methodType.Method()
assert.Equal(t, "func(*common.TestService, context.Context, []interface {}, *struct {}) error", method.Type.String())
assert.Equal(t, "func(*common.TestService, context.Context, interface {}, interface {}, interface {}) error", method.Type.String())
at := methodType.ArgsType()
assert.Equal(t, "[]interface {}", at[0].String())
assert.Equal(t, "*struct {}", at[1].String())
assert.Equal(t, "interface {}", at[0].String())
assert.Equal(t, "interface {}", at[1].String())
assert.Equal(t, "interface {}", at[2].String())
ct := methodType.CtxType()
assert.Equal(t, "context.Context", ct.String())
rt := methodType.ReplyType()
......@@ -152,12 +158,25 @@ func TestSuiteMethod(t *testing.T) {
assert.True(t, ok)
methodType = suiteMethod(method)
method = methodType.Method()
assert.Equal(t, "func(*common.TestService, []interface {}) (struct {}, error)", method.Type.String())
assert.Equal(t, "func(*common.TestService, interface {}, interface {}, interface {}) (interface {}, error)", method.Type.String())
at = methodType.ArgsType()
assert.Equal(t, "interface {}", at[0].String())
assert.Equal(t, "interface {}", at[1].String())
assert.Equal(t, "interface {}", at[2].String())
assert.Nil(t, methodType.CtxType())
rt = methodType.ReplyType()
assert.Equal(t, "interface {}", rt.String())
method, ok = reflect.TypeOf(s).MethodByName("MethodThree")
assert.True(t, ok)
methodType = suiteMethod(method)
method = methodType.Method()
assert.Equal(t, "func(*common.TestService) error", method.Type.String())
at = methodType.ArgsType()
assert.Equal(t, "[]interface {}", at[0].String())
assert.Equal(t, 0, len(at))
assert.Nil(t, methodType.CtxType())
rt = methodType.ReplyType()
assert.Equal(t, "struct {}", rt.String())
assert.Nil(t, rt)
// wrong number of in return
s1 := &testService{}
......@@ -172,26 +191,20 @@ func TestSuiteMethod(t *testing.T) {
methodType = suiteMethod(method)
assert.Nil(t, methodType)
// replyType != Ptr
method, ok = reflect.TypeOf(s1).MethodByName("Method2")
assert.True(t, ok)
methodType = suiteMethod(method)
assert.Nil(t, methodType)
// Reply not exported
method, ok = reflect.TypeOf(s1).MethodByName("Method3")
method, ok = reflect.TypeOf(s1).MethodByName("Method2")
assert.True(t, ok)
methodType = suiteMethod(method)
assert.Nil(t, methodType)
// no return
method, ok = reflect.TypeOf(s1).MethodByName("Method4")
method, ok = reflect.TypeOf(s1).MethodByName("Method3")
assert.True(t, ok)
methodType = suiteMethod(method)
assert.Nil(t, methodType)
// return value is not error
method, ok = reflect.TypeOf(s1).MethodByName("Method5")
method, ok = reflect.TypeOf(s1).MethodByName("Method4")
assert.True(t, ok)
methodType = suiteMethod(method)
assert.Nil(t, methodType)
......
......@@ -18,6 +18,7 @@
package common
import (
"bytes"
"context"
"fmt"
"math"
......@@ -128,16 +129,14 @@ func WithPort(port string) option {
}
}
//func WithPath(path string) option {
// return func(url *URL) {
// url.Path = path
// }
//}
func NewURLWithOptions(service string, opts ...option) *URL {
url := &URL{
Path: "/" + service,
func WithPath(path string) option {
return func(url *URL) {
url.Path = "/" + strings.TrimPrefix(path, "/")
}
}
func NewURLWithOptions(opts ...option) *URL {
url := &URL{}
for _, opt := range opts {
opt(url)
}
......@@ -212,32 +211,27 @@ func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error)
return s, nil
}
//
//func (c URL) Key() string {
// return fmt.Sprintf(
// "%s://%s:%s@%s:%s/%s",
// c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Path)
//}
func (c URL) URLEqual(url URL) bool {
c.Ip = ""
c.Port = ""
url.Ip = ""
url.Port = ""
if c.Key() != url.Key() {
cGroup := c.GetParam(constant.GROUP_KEY, "")
urlGroup := url.GetParam(constant.GROUP_KEY, "")
cKey := c.Key()
urlKey := url.Key()
if cGroup == constant.ANY_VALUE {
cKey = strings.Replace(cKey, "group=*", "group="+urlGroup, 1)
} else if urlGroup == constant.ANY_VALUE {
urlKey = strings.Replace(urlKey, "group=*", "group="+cGroup, 1)
}
if cKey != urlKey {
return false
}
return true
}
//func (c SubURL) String() string {
// return fmt.Sprintf(
// "DefaultServiceURL{protocol:%s, Location:%s, Path:%s, Ip:%s, Port:%s, "+
// "Timeout:%s, Version:%s, Group:%s, Params:%+v}",
// c.protocol, c.Location, c.Path, c.Ip, c.Port,
// c.Timeout, c.Version, c.Group, c.Params)
//}
func (c URL) String() string {
buildString := fmt.Sprintf(
"%s://%s:%s@%s:%s%s?",
......@@ -248,10 +242,33 @@ 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.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/")), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, constant.DEFAULT_VERSION))
"%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s",
c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""))
return buildString
//return c.ServiceKey()
}
func (c URL) ServiceKey() string {
intf := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
if intf == "" {
return ""
}
buf := &bytes.Buffer{}
group := c.GetParam(constant.GROUP_KEY, "")
if group != "" {
buf.WriteString(group)
buf.WriteString("/")
}
buf.WriteString(intf)
version := c.GetParam(constant.VERSION_KEY, "")
if version != "" && version != "0.0.0" {
buf.WriteString(":")
buf.WriteString(version)
}
return buf.String()
}
func (c URL) Context() context.Context {
......@@ -259,11 +276,11 @@ func (c URL) Context() context.Context {
}
func (c URL) Service() string {
service := strings.TrimPrefix(c.Path, "/")
service := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
if service != "" {
return service
} else if c.SubURL != nil {
service = strings.TrimPrefix(c.SubURL.Path, "/")
service = c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
if service != "" { //if url.path is "" then return suburl's path, special for registry Url
return service
}
......
......@@ -24,15 +24,18 @@ import (
)
import (
"github.com/apache/dubbo-go/common/constant"
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common/constant"
)
func TestNewURLWithOptions(t *testing.T) {
methods := []string{"Methodone,methodtwo"}
params := url.Values{}
params.Set("key", "value")
u := NewURLWithOptions("com.test.Service",
u := NewURLWithOptions(WithPath("com.test.Service"),
WithUsername("username"),
WithPassword("password"),
WithProtocol("testprotocol"),
......
......@@ -25,6 +25,7 @@ import (
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/version"
......@@ -56,8 +57,7 @@ func init() {
}
// Dubbo Init
func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
func Load() {
var refMap map[string]*ReferenceConfig
var srvMap map[string]*ServiceConfig
......@@ -71,6 +71,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
refMap = make(map[string]*ReferenceConfig)
for _, ref := range consumerConfig.References {
rpcService := GetConsumerService(ref.InterfaceName)
if rpcService == nil {
logger.Warnf("%s is not exsist!", ref.InterfaceName)
continue
......@@ -78,6 +79,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
ref.Refer()
ref.Implement(rpcService)
refMap[ref.InterfaceName] = ref
}
//wait for invoker is available, if wait over default 3s, then panic
var count int
......@@ -131,6 +133,14 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) {
srvMap[svs.InterfaceName] = svs
}
}
}
// get rpc service for consumer
func GetRPCService(name string) common.RPCService {
return consumerConfig.References[name].GetRPCService()
}
return refMap, srvMap
// create rpc service for consumer
func RPCService(service common.RPCService) {
providerConfig.Services[service.Service()].Implement(service)
}
......@@ -60,16 +60,22 @@ func TestLoad(t *testing.T) {
doInit()
doinit()
SetConsumerService(&MockService{})
SetProviderService(&MockService{})
ms := &MockService{}
SetConsumerService(ms)
SetProviderService(ms)
extension.SetProtocol("registry", GetProtocol)
extension.SetCluster("registryAware", cluster_impl.NewRegistryAwareCluster)
extension.SetProxyFactory("default", proxy_factory.NewDefaultProxyFactory)
refConfigs, svcConfigs := Load()
assert.NotEqual(t, 0, len(refConfigs))
assert.NotEqual(t, 0, len(svcConfigs))
Load()
assert.Equal(t, ms, GetRPCService(ms.Service()))
ms2 := &struct {
MockService
}{}
RPCService(ms2)
assert.NotEqual(t, ms2, GetRPCService(ms2.Service()))
conServices = map[string]common.RPCService{}
proServices = map[string]common.RPCService{}
......
......@@ -77,7 +77,7 @@ func (refconfig *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) erro
}
func (refconfig *ReferenceConfig) Refer() {
url := common.NewURLWithOptions(refconfig.InterfaceName, common.WithProtocol(refconfig.Protocol), common.WithParams(refconfig.getUrlMap()))
url := common.NewURLWithOptions(common.WithPath(refconfig.InterfaceName), common.WithProtocol(refconfig.Protocol), common.WithParams(refconfig.getUrlMap()))
//1. user specified URL, could be peer-to-peer address, or register center's address.
if refconfig.Url != "" {
......
......@@ -103,7 +103,7 @@ func (srvconfig *ServiceConfig) Export() error {
//if contextPath == "" {
// contextPath = providerConfig.Path
//}
url := common.NewURLWithOptions(srvconfig.InterfaceName,
url := common.NewURLWithOptions(common.WithPath(srvconfig.InterfaceName),
common.WithProtocol(proto.Name),
common.WithIp(proto.Ip),
common.WithPort(proto.Port),
......
......@@ -19,19 +19,19 @@ sh build.sh
```
go server
* sh ./assembly/\[os]/\[environment].sh
```bash
cd dubbo/go-server
#linux, mac windows represent the os
#release, dev and test represent the environment
sh ./assembly/linux/release.sh
# $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]
sh ./assembly/$ARCH/$ENV.sh
```
go client
```bash
cd dubbo/go-client
#linux, mac windows represent the os
#release, dev and test represent the environment
sh ./assembly/linux/release.sh
# $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]
sh ./assembly/$ARCH/$ENV.sh
```
#### Run by these command:
......@@ -53,8 +53,6 @@ sh ./bin/server.sh start
```
go server
> It must not listen on IP 127.0.0.1 when called by java-client.
> You should change IP in dubbo/go-server/target/linux/user_info_server-0.3.1-20190517-0930-release/conf/server.yml
```bash
cd dubbo/go-server/target/linux/user_info_server-0.3.1-20190517-0930-release
#conf suffix appoint config file,
......@@ -66,10 +64,10 @@ sh ./bin/load.sh start [conf suffix]
go client
```bash
cd dubbo/go-client/target/linux/user_info_client-0.3.1-20190517-0921-release
#conf suffix appoint config file,
#such as client_zookeeper.yml when "sh ./bin/load.sh start is zookeeper",
#default client.yml
sh ./bin/load_user_info_client.sh start [conf suffix]
# $SUFFIX is a suffix of config file,
# such as client_zookeeper.yml when $SUFFIX = zookeeper",
# if $SUFFIX = "", config file is client.yml
sh ./bin/load_user_info_client.sh start $SUFFIX
```
## jsonrpc
......
......@@ -57,13 +57,10 @@ func main() {
hessian.RegisterJavaEnum(Gender(WOMAN))
hessian.RegisterPOJO(&User{})
conMap, _ := config.Load()
if conMap == nil {
panic("conMap is nil")
}
config.Load()
println("\n\n\necho")
res, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).Echo(context.TODO(), "OK")
res, err := userProvider.Echo(context.TODO(), "OK")
if err != nil {
panic(err)
}
......@@ -73,44 +70,51 @@ func main() {
println("\n\n\nstart to test dubbo")
user := &User{}
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser(context.TODO(), []interface{}{"A003"}, user)
err = userProvider.GetUser(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
panic(err)
}
println("response result: %v", user)
println("\n\n\nstart to test dubbo - GetUser0")
ret, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser0("A003", "Moorse")
ret, err := userProvider.GetUser0("A003", "Moorse")
if err != nil {
panic(err)
}
println("response result: %v", ret)
println("\n\n\nstart to test dubbo - GetUsers")
ret1, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUsers([]interface{}{[]interface{}{"A002", "A003"}})
ret1, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}})
if err != nil {
panic(err)
}
println("response result: %v", ret1)
println("\n\n\nstart to test dubbo - getUser2")
println("\n\n\nstart to test dubbo - getUser")
user = &User{}
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser2(context.TODO(), []interface{}{1}, user)
var i int32 = 1
err = userProvider.GetUser2(context.TODO(), []interface{}{i}, user)
if err != nil {
println("getUser - error: %v", err)
} else {
println("response result: %v", user)
panic(err)
}
println("response result: %v", user)
println("\n\n\nstart to test dubbo - GetUser3")
err = userProvider.GetUser3()
if err != nil {
panic(err)
}
println("succ!")
println("\n\n\nstart to test dubbo - getErr")
user = &User{}
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetErr(context.TODO(), []interface{}{"A003"}, user)
err = userProvider.GetErr(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
println("getErr - error: %v", err)
}
println("\n\n\nstart to test dubbo illegal method")
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user)
err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
panic(err)
}
......
......@@ -34,8 +34,10 @@ import (
type Gender hessian.JavaEnum
var userProvider = new(UserProvider)
func init() {
config.SetConsumerService(new(UserProvider))
config.SetConsumerService(userProvider)
}
const (
......@@ -101,7 +103,8 @@ type UserProvider struct {
GetUser func(ctx context.Context, req []interface{}, rsp *User) error
GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error
GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"`
GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"`
GetUser3 func() error
Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
}
......
......@@ -33,6 +33,8 @@ registries :
references:
"UserProvider":
protocol : "dubbo"
# version: "2.0"
# group: "as"
interface : "com.ikurento.user.UserProvider"
cluster: "failover"
methods :
......
......@@ -33,6 +33,8 @@ registries :
references:
"UserProvider":
protocol : "dubbo"
# version: "2.0"
# group: "as"
interface : "com.ikurento.user.UserProvider"
cluster: "failover"
methods :
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment