Skip to content

Commit 54460fb

Browse files
committedDec 6, 2021
Ftr: add grpc max size support
1 parent 4ad68a0 commit 54460fb

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
 

‎pkg/config/config.go

+30
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ type Option struct {
4040
HeaderGroup string
4141
HeaderAppVersion string
4242

43+
// grpc opts
44+
GRPCMaxCallSendMsgSize int
45+
GRPCMaxServerSendMsgSize int
46+
GRPCMaxCallRecvMsgSize int
47+
GRPCMaxServerRecvMsgSize int
48+
4349
// tracing
4450
JaegerAddress string
4551
JaegerServiceName string
@@ -166,6 +172,30 @@ func WithNumWorker(numWorkers uint32) OptionFunction {
166172
}
167173
}
168174

175+
func WithGRPCMaxCallSendMessageSize(maxCallSendMsgSize int) OptionFunction {
176+
return func(o *Option) {
177+
o.GRPCMaxCallSendMsgSize = maxCallSendMsgSize
178+
}
179+
}
180+
181+
func WithGRPCMaxCallRecvMessageSize(maxCallRecvMsgSize int) OptionFunction {
182+
return func(o *Option) {
183+
o.GRPCMaxCallRecvMsgSize = maxCallRecvMsgSize
184+
}
185+
}
186+
187+
func WithGRPCMaxServerSendMessageSize(maxServerSendMsgSize int) OptionFunction {
188+
return func(o *Option) {
189+
o.GRPCMaxServerSendMsgSize = maxServerSendMsgSize
190+
}
191+
}
192+
193+
func WithGRPCMaxServerRecvMessageSize(maxServerRecvMsgSize int) OptionFunction {
194+
return func(o *Option) {
195+
o.GRPCMaxServerRecvMsgSize = maxServerRecvMsgSize
196+
}
197+
}
198+
169199
func WithJaegerConfig(address, serviceName string, useAgent bool) OptionFunction {
170200
return func(o *Option) {
171201
o.JaegerAddress = address

‎pkg/triple/dubbo3_client.go

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ func NewTripleClient(impl interface{}, opt *config.Option) (*TripleClient, error
8585
)
8686
}
8787

88+
defaultCallOpts := make([]grpc.CallOption, 0)
89+
if opt.GRPCMaxCallSendMsgSize != 0 {
90+
defaultCallOpts = append(defaultCallOpts, grpc.MaxCallSendMsgSize(opt.GRPCMaxCallSendMsgSize))
91+
}
92+
if opt.GRPCMaxCallRecvMsgSize != 0 {
93+
defaultCallOpts = append(defaultCallOpts, grpc.MaxCallRecvMsgSize(opt.GRPCMaxCallRecvMsgSize))
94+
}
95+
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(defaultCallOpts...))
96+
8897
if opt.CodecType == constant.PBCodecName {
8998
// put dubbo3 network logic to tripleConn, creat pb stub invoker
9099
tripleClient.stubInvoker = reflect.ValueOf(getInvoker(impl, newTripleConn(opt.Location, dialOpts...)))

‎pkg/triple/dubbo3_server.go

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/dubbogo/grpc-go/encoding/msgpack"
3535
"github.com/dubbogo/grpc-go/encoding/proto_wrapper_api"
3636
"github.com/dubbogo/grpc-go/encoding/raw_proto"
37+
3738
perrors "github.com/pkg/errors"
3839
)
3940

@@ -204,6 +205,13 @@ func newGrpcServerWithCodec(opt *config.Option) *grpc.Server {
204205
)
205206
}
206207

208+
if opt.GRPCMaxServerRecvMsgSize != 0 {
209+
serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(opt.GRPCMaxServerSendMsgSize))
210+
}
211+
if opt.GRPCMaxCallSendMsgSize != 0 {
212+
serverOpts = append(serverOpts, grpc.MaxSendMsgSize(opt.GRPCMaxServerRecvMsgSize))
213+
}
214+
207215
var err error
208216
switch opt.CodecType {
209217
case constant.PBCodecName:

0 commit comments

Comments
 (0)
Please sign in to comment.