diff --git a/examples/dubbo/go-client/app/client.go b/examples/dubbo/go-client/app/client.go index 6167fbc8e7b0743f807775d1c414110159d01449..25b3263ac5c916df585031438b9c489b83cefb3c 100644 --- a/examples/dubbo/go-client/app/client.go +++ b/examples/dubbo/go-client/app/client.go @@ -93,7 +93,7 @@ func main() { } println("response result: %v", ret1) - println("\n\n\nstart to test dubbo - getUser") + println("\n\n\nstart to test dubbo - getUser2") user = &User{} err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser2(context.TODO(), []interface{}{1}, user) if err != nil { diff --git a/go.mod b/go.mod index e88b8da6cbad1e775dc185652fb1c1e2d0be4da0..4c2276429ae315a44c282a8af9fb7e6d7ee1be8e 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/apache/dubbo-go require ( github.com/dubbogo/getty v1.0.7 - github.com/dubbogo/hessian2 v1.0.0 + github.com/dubbogo/hessian2 v1.0.1 github.com/pkg/errors v0.8.1 github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec github.com/stretchr/testify v1.3.0 diff --git a/go.sum b/go.sum index 8c83a280a2f61bc3bba7fcfafe355f1906883b0f..a4fd7f5099b5521b03e03cf5958c641991433d39 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dubbogo/getty v1.0.7 h1:5Hg+JwXyCKm9Yr4yJkm98ahhnoa8c2h6br5QJxwQ+YU= github.com/dubbogo/getty v1.0.7/go.mod h1:cRMSuoCmwc5lULFFnYZTxyCfZhObmRTNbS7XRnPNHSo= -github.com/dubbogo/hessian2 v1.0.0 h1:KM7BKAUZ+2sjv1nAV9JwJNPMK0T+sHYiSe7Gls1GFS4= -github.com/dubbogo/hessian2 v1.0.0/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM= +github.com/dubbogo/hessian2 v1.0.1 h1:ztI7gJxR3Isxrrl2jE1IZKX61eNR93eRKGhn49vPEX8= +github.com/dubbogo/hessian2 v1.0.1/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 38aed1063c7ec200b6b0654dcb3a5e8ac8138b86..d22ac91ed562468a40daf693948d79962bf07e0d 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -25,7 +25,7 @@ import ( import ( "github.com/dubbogo/getty" - hessian "github.com/dubbogo/hessian2" + "github.com/dubbogo/hessian2" perrors "github.com/pkg/errors" "go.uber.org/atomic" "gopkg.in/yaml.v2" diff --git a/protocol/dubbo/codec.go b/protocol/dubbo/codec.go index b578fb79be34ace109d1b534172751016945c5e5..9551c2b0b7b742228ae69701a9d86975d2c85e52 100644 --- a/protocol/dubbo/codec.go +++ b/protocol/dubbo/codec.go @@ -79,10 +79,6 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { // read header err := codec.ReadHeader(&p.Header) if err != nil { - if p.Header.Type&hessian.PackageError != hessian.PackageType(hessian.Zero) { - p.Body = &hessian.Response{Exception: err} - return nil - } return perrors.WithStack(err) } @@ -95,12 +91,9 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { pendingRsp := client.GetPendingResponse(SequenceType(p.Header.ID)) if pendingRsp == nil { return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID) + } else { + p.Body = &hessian.Response{RspObj: pendingRsp.reply} } - p.Body = &hessian.Response{RspObj: pendingRsp.reply} - } - - if p.Header.Type&hessian.PackageHeartbeat != 0x00 { - return nil } // read body diff --git a/protocol/dubbo/listener.go b/protocol/dubbo/listener.go index 6a58de24bb49cc27f2a6fe3851e4973a5ebed19f..ea8c38db9817ae2df078ef9b21caaf7b13751b3e 100644 --- a/protocol/dubbo/listener.go +++ b/protocol/dubbo/listener.go @@ -86,9 +86,12 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) { if p.Header.Type&hessian.PackageHeartbeat != 0x00 { logger.Debugf("get rpc heartbeat response{header: %#v, body: %#v}", p.Header, p.Body) + if p.Err != nil { + logger.Errorf("rpc heartbeat response{error: %#v}", p.Err) + } return } - //logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body) + logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body) h.conn.updateSession(session) @@ -203,7 +206,6 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { // not twoway if p.Header.Type&hessian.PackageRequest_TwoWay == 0x00 { twoway = false - h.reply(session, p, hessian.PackageResponse) } invoker := h.exporter.GetInvoker() diff --git a/protocol/dubbo/readwriter.go b/protocol/dubbo/readwriter.go index fd7c7c317d7eca8be9df7f7646b9d191300233fc..6d789ae13e458249747f660c406ab2fe4c6463f0 100644 --- a/protocol/dubbo/readwriter.go +++ b/protocol/dubbo/readwriter.go @@ -65,6 +65,7 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface pkg.Err = pkg.Body.(*hessian.Response).Exception pkg.Body = pkg.Body.(*hessian.Response).RspObj + return pkg, hessian.HEADER_LENGTH + pkg.Header.BodyLen, nil } @@ -112,40 +113,43 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface return nil, 0, perrors.WithStack(err) } - // convert params of request - req := pkg.Body.([]interface{}) // length of body should be 7 - if len(req) > 0 { - var dubboVersion, argsTypes string - var args []interface{} - var attachments map[interface{}]interface{} - if req[0] != nil { - dubboVersion = req[0].(string) - } - if req[1] != nil { - pkg.Service.Path = req[1].(string) - } - if req[2] != nil { - pkg.Service.Version = req[2].(string) - } - if req[3] != nil { - pkg.Service.Method = req[3].(string) - } - if req[4] != nil { - argsTypes = req[4].(string) - } - if req[5] != nil { - args = req[5].([]interface{}) - } - if req[6] != nil { - attachments = req[6].(map[interface{}]interface{}) - } - pkg.Service.Interface = attachments[constant.INTERFACE_KEY].(string) - pkg.Body = map[string]interface{}{ - "dubboVersion": dubboVersion, - "argsTypes": argsTypes, - "args": args, - "service": common.ServiceMap.GetService(DUBBO, pkg.Service.Interface), - "attachments": attachments, + + if pkg.Header.Type&hessian.PackageHeartbeat == 0x00 { + // convert params of request + req := pkg.Body.([]interface{}) // length of body should be 7 + if len(req) > 0 { + var dubboVersion, argsTypes string + var args []interface{} + var attachments map[interface{}]interface{} + if req[0] != nil { + dubboVersion = req[0].(string) + } + if req[1] != nil { + pkg.Service.Path = req[1].(string) + } + if req[2] != nil { + pkg.Service.Version = req[2].(string) + } + if req[3] != nil { + pkg.Service.Method = req[3].(string) + } + if req[4] != nil { + argsTypes = req[4].(string) + } + if req[5] != nil { + args = req[5].([]interface{}) + } + if req[6] != nil { + attachments = req[6].(map[interface{}]interface{}) + } + pkg.Service.Interface = attachments[constant.INTERFACE_KEY].(string) + pkg.Body = map[string]interface{}{ + "dubboVersion": dubboVersion, + "argsTypes": argsTypes, + "args": args, + "service": common.ServiceMap.GetService(DUBBO, pkg.Service.Interface), + "attachments": attachments, + } } }