Skip to content

Commit 2954fad

Browse files
committed
Fix:heartbeat and exception
1 parent 9f0a843 commit 2954fad

File tree

7 files changed

+49
-50
lines changed

7 files changed

+49
-50
lines changed

examples/dubbo/go-client/app/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func main() {
9393
}
9494
println("response result: %v", ret1)
9595

96-
println("\n\n\nstart to test dubbo - getUser")
96+
println("\n\n\nstart to test dubbo - getUser2")
9797
user = &User{}
9898
err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser2(context.TODO(), []interface{}{1}, user)
9999
if err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/apache/dubbo-go
22

33
require (
44
github.com/dubbogo/getty v1.0.7
5-
github.com/dubbogo/hessian2 v1.0.0
5+
github.com/dubbogo/hessian2 v1.0.1
66
github.com/pkg/errors v0.8.1
77
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
88
github.com/stretchr/testify v1.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/dubbogo/getty v1.0.7 h1:5Hg+JwXyCKm9Yr4yJkm98ahhnoa8c2h6br5QJxwQ+YU=
55
github.com/dubbogo/getty v1.0.7/go.mod h1:cRMSuoCmwc5lULFFnYZTxyCfZhObmRTNbS7XRnPNHSo=
6-
github.com/dubbogo/hessian2 v1.0.0 h1:KM7BKAUZ+2sjv1nAV9JwJNPMK0T+sHYiSe7Gls1GFS4=
7-
github.com/dubbogo/hessian2 v1.0.0/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM=
6+
github.com/dubbogo/hessian2 v1.0.1 h1:ztI7gJxR3Isxrrl2jE1IZKX61eNR93eRKGhn49vPEX8=
7+
github.com/dubbogo/hessian2 v1.0.1/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM=
88
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
99
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
1010
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=

protocol/dubbo/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
import (
2727
"github.com/dubbogo/getty"
28-
hessian "github.com/dubbogo/hessian2"
28+
"github.com/dubbogo/hessian2"
2929
perrors "github.com/pkg/errors"
3030
"go.uber.org/atomic"
3131
"gopkg.in/yaml.v2"

protocol/dubbo/codec.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error {
7979
// read header
8080
err := codec.ReadHeader(&p.Header)
8181
if err != nil {
82-
if p.Header.Type&hessian.PackageError != hessian.PackageType(hessian.Zero) {
83-
p.Body = &hessian.Response{Exception: err}
84-
return nil
85-
}
8682
return perrors.WithStack(err)
8783
}
8884

@@ -95,12 +91,9 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error {
9591
pendingRsp := client.GetPendingResponse(SequenceType(p.Header.ID))
9692
if pendingRsp == nil {
9793
return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
94+
} else {
95+
p.Body = &hessian.Response{RspObj: pendingRsp.reply}
9896
}
99-
p.Body = &hessian.Response{RspObj: pendingRsp.reply}
100-
}
101-
102-
if p.Header.Type&hessian.PackageHeartbeat != 0x00 {
103-
return nil
10497
}
10598

10699
// read body

protocol/dubbo/listener.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
8686

8787
if p.Header.Type&hessian.PackageHeartbeat != 0x00 {
8888
logger.Debugf("get rpc heartbeat response{header: %#v, body: %#v}", p.Header, p.Body)
89+
if p.Err != nil {
90+
logger.Errorf("rpc heartbeat response{error: %#v}", p.Err)
91+
}
8992
return
9093
}
91-
//logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body)
94+
logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body)
9295

9396
h.conn.updateSession(session)
9497

@@ -203,7 +206,6 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
203206
// not twoway
204207
if p.Header.Type&hessian.PackageRequest_TwoWay == 0x00 {
205208
twoway = false
206-
h.reply(session, p, hessian.PackageResponse)
207209
}
208210

209211
invoker := h.exporter.GetInvoker()

protocol/dubbo/readwriter.go

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface
6565

6666
pkg.Err = pkg.Body.(*hessian.Response).Exception
6767
pkg.Body = pkg.Body.(*hessian.Response).RspObj
68+
6869
return pkg, hessian.HEADER_LENGTH + pkg.Header.BodyLen, nil
6970
}
7071

@@ -112,40 +113,43 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
112113

113114
return nil, 0, perrors.WithStack(err)
114115
}
115-
// convert params of request
116-
req := pkg.Body.([]interface{}) // length of body should be 7
117-
if len(req) > 0 {
118-
var dubboVersion, argsTypes string
119-
var args []interface{}
120-
var attachments map[interface{}]interface{}
121-
if req[0] != nil {
122-
dubboVersion = req[0].(string)
123-
}
124-
if req[1] != nil {
125-
pkg.Service.Path = req[1].(string)
126-
}
127-
if req[2] != nil {
128-
pkg.Service.Version = req[2].(string)
129-
}
130-
if req[3] != nil {
131-
pkg.Service.Method = req[3].(string)
132-
}
133-
if req[4] != nil {
134-
argsTypes = req[4].(string)
135-
}
136-
if req[5] != nil {
137-
args = req[5].([]interface{})
138-
}
139-
if req[6] != nil {
140-
attachments = req[6].(map[interface{}]interface{})
141-
}
142-
pkg.Service.Interface = attachments[constant.INTERFACE_KEY].(string)
143-
pkg.Body = map[string]interface{}{
144-
"dubboVersion": dubboVersion,
145-
"argsTypes": argsTypes,
146-
"args": args,
147-
"service": common.ServiceMap.GetService(DUBBO, pkg.Service.Interface),
148-
"attachments": attachments,
116+
117+
if pkg.Header.Type&hessian.PackageHeartbeat == 0x00 {
118+
// convert params of request
119+
req := pkg.Body.([]interface{}) // length of body should be 7
120+
if len(req) > 0 {
121+
var dubboVersion, argsTypes string
122+
var args []interface{}
123+
var attachments map[interface{}]interface{}
124+
if req[0] != nil {
125+
dubboVersion = req[0].(string)
126+
}
127+
if req[1] != nil {
128+
pkg.Service.Path = req[1].(string)
129+
}
130+
if req[2] != nil {
131+
pkg.Service.Version = req[2].(string)
132+
}
133+
if req[3] != nil {
134+
pkg.Service.Method = req[3].(string)
135+
}
136+
if req[4] != nil {
137+
argsTypes = req[4].(string)
138+
}
139+
if req[5] != nil {
140+
args = req[5].([]interface{})
141+
}
142+
if req[6] != nil {
143+
attachments = req[6].(map[interface{}]interface{})
144+
}
145+
pkg.Service.Interface = attachments[constant.INTERFACE_KEY].(string)
146+
pkg.Body = map[string]interface{}{
147+
"dubboVersion": dubboVersion,
148+
"argsTypes": argsTypes,
149+
"args": args,
150+
"service": common.ServiceMap.GetService(DUBBO, pkg.Service.Interface),
151+
"attachments": attachments,
152+
}
149153
}
150154
}
151155

0 commit comments

Comments
 (0)