Skip to content

Commit

Permalink
feat:add keepalive config and pass through to grpc dial option (#87)
Browse files Browse the repository at this point in the history
* feat:add keepalive config to pass through to GRPC client config in dubbogo

* feat:add keepalive config to pass through to GRPC client
  • Loading branch information
No-SilverBullet authored Dec 2, 2024
1 parent df20316 commit 339a5a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/common/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package constant

import "time"
import (
"time"
)

// transfer
const (
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package config

import (
"time"
)

import (
"github.com/dubbogo/triple/pkg/common/constant"
loggerInterface "github.com/dubbogo/triple/pkg/common/logger"
"github.com/dubbogo/triple/pkg/common/logger/default_logger"
Expand Down Expand Up @@ -47,6 +49,8 @@ type Option struct {
GRPCMaxServerSendMsgSize int
GRPCMaxCallRecvMsgSize int
GRPCMaxServerRecvMsgSize int
GRPCKeepAliveTime time.Duration
GRPCKeepAliveTimeout time.Duration

// tracing
JaegerAddress string
Expand Down Expand Up @@ -207,6 +211,18 @@ func WithGRPCMaxServerRecvMessageSize(maxServerRecvMsgSize int) OptionFunction {
}
}

func WithGRPCKeepAliveTimeInterval(keepAliveInterval time.Duration) OptionFunction {
return func(o *Option) {
o.GRPCKeepAliveTime = keepAliveInterval
}
}

func WithGRPCKeepAliveTimeout(keepAliveTimeout time.Duration) OptionFunction {
return func(o *Option) {
o.GRPCKeepAliveTimeout = keepAliveTimeout
}
}

func WithJaegerConfig(address, serviceName string, useAgent bool) OptionFunction {
return func(o *Option) {
o.JaegerAddress = address
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"
)

import (
"github.com/stretchr/testify/assert"
)
Expand Down
9 changes: 9 additions & 0 deletions pkg/triple/dubbo3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/dubbogo/grpc-go/encoding/msgpack"
"github.com/dubbogo/grpc-go/encoding/raw_proto"
"github.com/dubbogo/grpc-go/encoding/tools"
"github.com/dubbogo/grpc-go/keepalive"
"github.com/dubbogo/grpc-go/status"

"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -110,6 +111,14 @@ func NewTripleClient(impl interface{}, opt *config.Option) (*TripleClient, error
defaultCallOpts = append(defaultCallOpts, grpc.MaxCallRecvMsgSize(opt.GRPCMaxCallRecvMsgSize))
}
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(defaultCallOpts...))
//keepalive
if opt.GRPCKeepAliveTime != 0 && opt.GRPCKeepAliveTimeout != 0 {
dialOpts = append(dialOpts, grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: opt.GRPCKeepAliveTime,
Timeout: opt.GRPCKeepAliveTimeout,
PermitWithoutStream: true,
}))
}

// codec
if opt.CodecType == constant.PBCodecName {
Expand Down
3 changes: 1 addition & 2 deletions pkg/triple/dubbo3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
hessian "github.com/apache/dubbo-go-hessian2"

"github.com/dubbogo/grpc-go"
"github.com/dubbogo/grpc-go/credentials"
"github.com/dubbogo/grpc-go/credentials/insecure"
"github.com/dubbogo/grpc-go/encoding"
hessianGRPCCodec "github.com/dubbogo/grpc-go/encoding/hessian"
Expand All @@ -40,8 +41,6 @@ import (
"github.com/dubbogo/grpc-go/encoding/raw_proto"

perrors "github.com/pkg/errors"

"github.com/dubbogo/grpc-go/credentials"
)

import (
Expand Down

0 comments on commit 339a5a6

Please sign in to comment.