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

Imp: receive heartbeat from server #302

Merged
merged 3 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions protocol/dubbo/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error {
return perrors.Errorf("opts[0] is not of type *Client")
}

pendingRsp, ok := client.pendingResponses.Load(SequenceType(p.Header.ID))
if !ok {
return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
if p.Header.Type&hessian.PackageRequest != 0x00 {
// size of this array must be '7'
// https://github.com/apache/dubbo-go-hessian2/blob/master/request.go#L272
p.Body = make([]interface{}, 7)
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
} else {
pendingRsp, ok := client.pendingResponses.Load(SequenceType(p.Header.ID))
if !ok {
return perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
}
p.Body = &hessian.Response{RspObj: pendingRsp.(*PendingResponse).response.reply}
}
p.Body = &hessian.Response{RspObj: pendingRsp.(*PendingResponse).response.reply}
}

// read body
Expand Down
24 changes: 15 additions & 9 deletions protocol/dubbo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@ 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)
if p.Header.Type&hessian.PackageResponse != 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)
}
h.conn.pool.rpcClient.removePendingResponse(SequenceType(p.Header.ID))
} else {
logger.Debugf("get rpc heartbeat request{header: %#v, service: %#v, body: %#v}", p.Header, p.Service, p.Body)
p.Header.ResponseStatus = hessian.Response_OK
reply(session, p, hessian.PackageHeartbeat)
}
h.conn.pool.rpcClient.removePendingResponse(SequenceType(p.Header.ID))
return
}
logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body)
Expand Down Expand Up @@ -199,7 +205,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
// heartbeat
if p.Header.Type&hessian.PackageHeartbeat != 0x00 {
logger.Debugf("get rpc heartbeat request{header: %#v, service: %#v, body: %#v}", p.Header, p.Service, p.Body)
h.reply(session, p, hessian.PackageHeartbeat)
reply(session, p, hessian.PackageHeartbeat)
return
}

Expand All @@ -226,7 +232,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
if !twoway {
return
}
h.reply(session, p, hessian.PackageResponse)
reply(session, p, hessian.PackageResponse)
}

}()
Expand All @@ -241,7 +247,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
logger.Errorf(err.Error())
p.Header.ResponseStatus = hessian.Response_OK
p.Body = err
h.reply(session, p, hessian.PackageResponse)
reply(session, p, hessian.PackageResponse)
return
}
invoker := exporter.(protocol.Exporter).GetInvoker()
Expand All @@ -266,7 +272,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
if !twoway {
return
}
h.reply(session, p, hessian.PackageResponse)
reply(session, p, hessian.PackageResponse)
}

func (h *RpcServerHandler) OnCron(session getty.Session) {
Expand Down Expand Up @@ -294,7 +300,7 @@ func (h *RpcServerHandler) OnCron(session getty.Session) {
}
}

func (h *RpcServerHandler) reply(session getty.Session, req *DubboPackage, tp hessian.PackageType) {
func reply(session getty.Session, req *DubboPackage, tp hessian.PackageType) {
resp := &DubboPackage{
Header: hessian.DubboHeader{
SerialID: req.Header.SerialID,
Expand Down
6 changes: 4 additions & 2 deletions protocol/dubbo/readwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface
return nil, 0, perrors.WithStack(err)
}

pkg.Err = pkg.Body.(*hessian.Response).Exception
pkg.Body = NewResponse(pkg.Body.(*hessian.Response).RspObj, pkg.Body.(*hessian.Response).Attachments)
if pkg.Header.Type&hessian.PackageRequest == 0x00 {
pkg.Err = pkg.Body.(*hessian.Response).Exception
pkg.Body = NewResponse(pkg.Body.(*hessian.Response).RspObj, pkg.Body.(*hessian.Response).Attachments)
}

return pkg, hessian.HEADER_LENGTH + pkg.Header.BodyLen, nil
}
Expand Down