Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: invoker & attachments & merge master #193

Merged
merged 27 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
da11226
Mod: move callService to invoker
fangyincheng Aug 3, 2019
1888a20
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Aug 6, 2019
c5ef8f4
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Aug 7, 2019
32b5e87
Mrg:merge upstream
fangyincheng Aug 30, 2019
a1b5db0
Fix:invoker bug
fangyincheng Aug 30, 2019
71242e9
Fix: gettyRPCClientPool.remove deadlock
AlexStocks Aug 31, 2019
395e227
Update README.md
hxmhlt Sep 2, 2019
ad148e1
Update README_CN.md
hxmhlt Sep 2, 2019
0ec3556
Add: support complete attachments
fangyincheng Sep 2, 2019
557d0a1
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Sep 2, 2019
a672bba
Del:delete wrong files
fangyincheng Sep 2, 2019
7a70fa1
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Sep 2, 2019
64a6cb8
Merge remote-tracking branch 'upstream/master' into develop
fangyincheng Sep 2, 2019
dde93bb
Fix: import format & update hessian2
fangyincheng Sep 2, 2019
f9b8a27
Fix: get attachments for comsumer
fangyincheng Sep 5, 2019
dbbc931
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Sep 6, 2019
5c0e14e
Fix: ut and import
fangyincheng Sep 6, 2019
c553ec8
Mod: examples readme
fangyincheng Sep 8, 2019
9a8310a
Mod: examples/README.md
fangyincheng Sep 8, 2019
114174d
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Sep 8, 2019
639aab6
Fix: format
fangyincheng Sep 8, 2019
9a7951e
Merge pull request #196 from fangyincheng/master
hxmhlt Sep 9, 2019
66c2333
Fix: attachments
fangyincheng Sep 9, 2019
b8461e4
Fix: ut
fangyincheng Sep 10, 2019
c469962
Merge remote-tracking branch 'upstream/develop' into develop
fangyincheng Sep 10, 2019
0f31de3
Merge remote-tracking branch 'upstream/master' into develop
fangyincheng Sep 10, 2019
ddcf560
Fix: delete unused file
fangyincheng Sep 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
---
Apache Dubbo Go Implementation.

![Apache Dubbo-go](./dubbogo.png "Apache Dubbo-go")

Apache/Dubbo-go image, licensed under [Creative Commons 3.0 Attributions license](https://creativecommons.org/licenses/by/3.0/).

## License

Expand Down
3 changes: 0 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

---
Apache Dubbo Go 语言实现
![Apache Dubbo-go](./dubbogo.png "Apache Dubbo-go")

Apache/Dubbo-go image, licensed under [Creative Commons 3.0 Attributions license](https://creativecommons.org/licenses/by/3.0/).

## 证书 ##

Expand Down
94 changes: 92 additions & 2 deletions common/proxy/proxy_factory/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@

package proxy_factory

import (
"reflect"
"strings"
)

import (
perrors "github.com/pkg/errors"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/proxy"
"github.com/apache/dubbo-go/protocol"
)
Expand Down Expand Up @@ -51,6 +61,86 @@ 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: call service
return protocol.NewBaseInvoker(url)
return &ProxyInvoker{
BaseInvoker: *protocol.NewBaseInvoker(url),
}
}

type ProxyInvoker struct {
protocol.BaseInvoker
}

func (pi *ProxyInvoker) Invoke(invocation protocol.Invocation) protocol.Result {
result := &protocol.RPCResult{}
result.SetAttachments(invocation.Attachments())

url := pi.GetUrl()

methodName := invocation.MethodName()
proto := url.Protocol
path := strings.TrimPrefix(url.Path, "/")
args := invocation.Arguments()

// get service
svc := common.ServiceMap.GetService(proto, path)
if svc == nil {
logger.Errorf("cannot find service [%s] in %s", path, proto)
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
result.SetError(perrors.Errorf("cannot find service [%s] in %s", path, proto))
return result
}

// get method
method := svc.Method()[methodName]
if method == nil {
logger.Errorf("cannot find method [%s] of service [%s] in %s", methodName, path, proto)
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
result.SetError(perrors.Errorf("cannot find method [%s] of service [%s] in %s", methodName, path, proto))
return result
}

in := []reflect.Value{svc.Rcvr()}
if method.CtxType() != nil {
in = append(in, method.SuiteContext(nil)) // todo: ctx will be used later.
}

// prepare argv
if (len(method.ArgsType()) == 1 || len(method.ArgsType()) == 2 && method.ReplyType() == nil) && method.ArgsType()[0].String() == "[]interface {}" {
in = append(in, reflect.ValueOf(args))
} else {
for i := 0; i < len(args); i++ {
t := reflect.ValueOf(args[i])
if !t.IsValid() {
at := method.ArgsType()[i]
if at.Kind() == reflect.Ptr {
at = at.Elem()
}
t = reflect.New(at)
}
in = append(in, t)
}
}

// prepare replyv
var replyv reflect.Value
if method.ReplyType() == nil && len(method.ArgsType()) > 0 {
replyv = reflect.New(method.ArgsType()[len(method.ArgsType())-1].Elem())
in = append(in, replyv)
}

returnValues := method.Method().Func.Call(in)

var retErr interface{}
if len(returnValues) == 1 {
retErr = returnValues[0].Interface()
} else {
replyv = returnValues[0]
retErr = returnValues[1].Interface()
}
if retErr != nil {
result.SetError(retErr.(error))
} else {
if replyv.IsValid() && (replyv.Kind() != reflect.Ptr || replyv.Kind() == reflect.Ptr && replyv.Elem().IsValid()) {
result.SetResult(replyv.Interface())
}
}
return result
}
82 changes: 44 additions & 38 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,80 @@
# examples

Examples of go-for-apache-dubbo
Examples of dubbo-go

## dubbo
## What does this contain

#### Build by these command
* helloworld

java server
```bash
cd dubbo/java-server
sh build.sh
```
A simplest example. It contain 'go-client', 'go-server', 'java-server' of dubbo protocol.

java client
```bash
cd dubbo/java-client
sh build.sh
```
* general

go server
A general example. It had validated zookeeper registry and different parameter lists of service.
And it has a comprehensive testing with dubbo/jsonrpc protocol. You can refer to it to create your first complete dubbo-go project.

* sh ./assembly/\[os]/\[environment].sh
```bash
cd dubbo/go-server
# $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]
sh ./assembly/$ARCH/$ENV.sh
```
* generic

go client
```bash
cd dubbo/go-client
# $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]
sh ./assembly/$ARCH/$ENV.sh
```
A generic reference example. It show how to use generic reference of dubbo-go.

* configcenter

Some examples of different config center. There is only one -- zookeeper at present.

#### Run by these command:
## How to build and run

> Take `helloworld` as an example

java server

```bash
cd dubbo/java-server/target
cd helloworld/dubbo/java-server
sh build.sh

cd ./target
tar -zxvf user-info-server-0.2.0-assembly.tar.gz
cd ./user-info-server-0.2.0
sh ./bin/server.sh start
```

java client

```bash
cd dubbo/java-client/target
cd helloworld/dubbo/java-client
sh build.sh

cd ./target
tar -zxvf user-info-client-0.2.0-assembly.tar.gz
cd ./user-info-client-0.2.0
sh ./bin/server.sh start
```

go server

* $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]

```bash
cd dubbo/go-server/target/linux/user_info_server-0.3.1-20190517-0930-release
#conf suffix appoint config file,
#such as server_zookeeper.yml when "sh ./bin/load.sh start is zookeeper",
#default server.yml
sh ./bin/load.sh start [conf suffix]
cd helloworld/dubbo/go-server
sh ./assembly/$ARCH/$ENV.sh

cd ./target/linux/user_info_server-0.3.1-20190517-0930-release
# $SUFFIX is a suffix of config file,
# such as server_zookeeper.yml when $SUFFIX is "zookeeper",
# if $SUFFIX = "", default server.yml
sh ./bin/load.sh start $SUFFIX
```

go client

* $ARCH = [linux, mac, windows] and $ENV = [dev, release, test]

```bash
cd dubbo/go-client/target/linux/user_info_client-0.3.1-20190517-0921-release
cd helloworld/dubbo/go-client
sh ./assembly/$ARCH/$ENV.sh

cd ./target/linux/user_info_client-0.3.1-20190517-0921-release
# $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
Similar to dubbo
28 changes: 14 additions & 14 deletions examples/general/dubbo/go-client/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/registry/protocol"

_ "github.com/apache/dubbo-go/filter/impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"

_ "github.com/apache/dubbo-go/cluster/cluster_impl"
_ "github.com/apache/dubbo-go/cluster/loadbalance"
Expand Down Expand Up @@ -168,15 +168,15 @@ func test1() {

time.Sleep(3e9)

println("\n\n\nstart to test dubbo")
println("\n\n\nstart to test1 dubbo")
user := &User{}
err = userProvider1.GetUser(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
panic(err)
}
println("response result: %v", user)

println("\n\n\nstart to test dubbo - GetUser0")
println("\n\n\nstart to test1 dubbo - GetUser0")
ret, err := userProvider1.GetUser0("A003", "Moorse")
if err != nil {
panic(err)
Expand All @@ -190,7 +190,7 @@ func test1() {
}
println("response result: %v", ret1)

println("\n\n\nstart to test dubbo - getUser")
println("\n\n\nstart to test1 dubbo - getUser")
user = &User{}
var i int32 = 1
err = userProvider1.GetUser2(context.TODO(), []interface{}{i}, user)
Expand All @@ -206,15 +206,15 @@ func test1() {
}
println("succ!")

println("\n\n\nstart to test dubbo - getErr")
println("\n\n\nstart to test1 dubbo - getErr")
user = &User{}
err = userProvider1.GetErr(context.TODO(), []interface{}{"A003"}, user)
if err == nil {
panic("err is nil")
}
println("getErr - error: %v", err)

println("\n\n\nstart to test dubbo illegal method")
println("\n\n\nstart to test1 dubbo illegal method")
err = userProvider1.GetUser1(context.TODO(), []interface{}{"A003"}, user)
if err == nil {
panic("err is nil")
Expand All @@ -232,29 +232,29 @@ func test2() {

time.Sleep(3e9)

println("\n\n\nstart to test dubbo")
println("\n\n\nstart to test2 dubbo")
user := &User{}
err = userProvider2.GetUser(context.TODO(), []interface{}{"A003"}, user)
if err != nil {
panic(err)
}
println("response result: %v", user)

println("\n\n\nstart to test dubbo - GetUser0")
println("\n\n\nstart to test2 dubbo - GetUser0")
ret, err := userProvider2.GetUser0("A003", "Moorse")
if err != nil {
panic(err)
}
println("response result: %v", ret)

println("\n\n\nstart to test dubbo - GetUsers")
println("\n\n\nstart to test2 dubbo - GetUsers")
ret1, err := userProvider2.GetUsers([]interface{}{[]interface{}{"A002", "A003"}})
if err != nil {
panic(err)
}
println("response result: %v", ret1)

println("\n\n\nstart to test dubbo - getUser")
println("\n\n\nstart to test2 dubbo - getUser")
user = &User{}
var i int32 = 1
err = userProvider2.GetUser2(context.TODO(), []interface{}{i}, user)
Expand All @@ -263,22 +263,22 @@ func test2() {
}
println("response result: %v", user)

println("\n\n\nstart to test dubbo - GetUser3")
println("\n\n\nstart to test2 dubbo - GetUser3")
err = userProvider2.GetUser3()
if err != nil {
panic(err)
}
println("succ!")

println("\n\n\nstart to test dubbo - getErr")
println("\n\n\nstart to test2 dubbo - getErr")
user = &User{}
err = userProvider2.GetErr(context.TODO(), []interface{}{"A003"}, user)
if err == nil {
panic("err is nil")
}
println("getErr - error: %v", err)

println("\n\n\nstart to test dubbo illegal method")
println("\n\n\nstart to test2 dubbo illegal method")
err = userProvider2.GetUser1(context.TODO(), []interface{}{"A003"}, user)
if err == nil {
panic("err is nil")
Expand Down
3 changes: 2 additions & 1 deletion filter/impl/echo_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func (ef *EchoFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invoc
logger.Debugf("%v,%v", invocation.MethodName(), len(invocation.Arguments()))
if invocation.MethodName() == constant.ECHO && len(invocation.Arguments()) == 1 {
return &protocol.RPCResult{
Rest: invocation.Arguments()[0],
Rest: invocation.Arguments()[0],
Attrs: invocation.Attachments(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/Workiva/go-datastructures v1.0.50
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e // indirect
github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190731020727-1697039810c8
github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190909140437-80cbb25cbb22
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
Expand Down
Loading