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

Ftr: protocol_conf default values #221

Merged
merged 7 commits into from
Sep 28, 2019
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
44 changes: 23 additions & 21 deletions protocol/dubbo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,35 @@ var (
func init() {

// load clientconfig from consumer_config
protocolConf := config.GetConsumerConfig().ProtocolConf
if protocolConf == nil {
logger.Warnf("protocol_conf is nil")
return
}
dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO]
if dubboConf == nil {
logger.Warnf("dubboConf is nil")
// default use dubbo
consumerConfig := config.GetConsumerConfig()
if consumerConfig.ApplicationConfig == nil {
return
}

dubboConfByte, err := yaml.Marshal(dubboConf)
if err != nil {
panic(err)
}
conf := &ClientConfig{}
err = yaml.Unmarshal(dubboConfByte, conf)
if err != nil {
panic(err)
protocolConf := config.GetConsumerConfig().ProtocolConf
defaultClientConfig := GetDefaultClientConfig()
if protocolConf == nil {
logger.Info("protocol_conf default use dubbo config")
} else {
dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO]
if dubboConf == nil {
logger.Warnf("dubboConf is nil")
return
}
dubboConfByte, err := yaml.Marshal(dubboConf)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(dubboConfByte, &defaultClientConfig)
if err != nil {
panic(err)
}
}

if err := conf.CheckValidity(); err != nil {
clientConf = &defaultClientConfig
if err := clientConf.CheckValidity(); err != nil {
logger.Warnf("[CheckValidity] error: %v", err)
return
}

clientConf = conf
setClientGrpool()
}

Expand Down
51 changes: 51 additions & 0 deletions protocol/dubbo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,57 @@ type (
}
)

func GetDefaultClientConfig() ClientConfig {
return ClientConfig{
ReconnectInterval: 0,
ConnectionNum: 16,
HeartbeatPeriod: "5s",
SessionTimeout: "20s",
PoolSize: 64,
PoolTTL: 600,
GrPoolSize: 200,
QueueLen: 64,
QueueNumber: 10,
GettySessionParam: GettySessionParam{
CompressEncoding: false,
TcpNoDelay: true,
TcpKeepAlive: true,
KeepAlivePeriod: "120s",
TcpRBufSize: 262144,
TcpWBufSize: 65536,
PkgWQSize: 512,
TcpReadTimeout: "1s",
TcpWriteTimeout: "5s",
WaitTimeout: "1s",
MaxMsgLen: 102400,
SessionName: "client",
}}
}

func GetDefaultServerConfig() ServerConfig {
return ServerConfig{
SessionTimeout: "20s",
SessionNumber: 700,
GrPoolSize: 120,
QueueNumber: 6,
QueueLen: 64,
GettySessionParam: GettySessionParam{
CompressEncoding: false,
TcpNoDelay: true,
TcpKeepAlive: true,
KeepAlivePeriod: "120s",
TcpRBufSize: 262144,
TcpWBufSize: 65536,
PkgWQSize: 512,
TcpReadTimeout: "1s",
TcpWriteTimeout: "5s",
WaitTimeout: "1s",
MaxMsgLen: 102400,
SessionName: "server",
},
}
}

func (c *GettySessionParam) CheckValidity() error {
var err error

Expand Down
45 changes: 24 additions & 21 deletions protocol/dubbo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,35 @@ var (
func init() {

// load clientconfig from provider_config
protocolConf := config.GetProviderConfig().ProtocolConf
if protocolConf == nil {
logger.Warnf("protocol_conf is nil")
return
}
dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO]
if dubboConf == nil {
logger.Warnf("dubboConf is nil")
// default use dubbo
providerConfig := config.GetProviderConfig()
if providerConfig.ApplicationConfig == nil {
return
}

dubboConfByte, err := yaml.Marshal(dubboConf)
if err != nil {
panic(err)
}
conf := &ServerConfig{}
err = yaml.Unmarshal(dubboConfByte, conf)
if err != nil {
panic(err)
protocolConf := providerConfig.ProtocolConf
defaultServerConfig := GetDefaultServerConfig()
if protocolConf == nil {
logger.Info("protocol_conf default use dubbo config")
} else {
dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO]
if dubboConf == nil {
logger.Warnf("dubboConf is nil")
return
}

dubboConfByte, err := yaml.Marshal(dubboConf)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(dubboConfByte, &defaultServerConfig)
if err != nil {
panic(err)
}
}

if err := conf.CheckValidity(); err != nil {
srvConf = &defaultServerConfig
if err := srvConf.CheckValidity(); err != nil {
panic(err)
}

srvConf = conf
SetServerGrpool()
}

Expand Down