Skip to content
Snippets Groups Projects
Commit 00e2933a authored by fangyincheng's avatar fangyincheng
Browse files

Imp:improve config & update getty & add connect timeout

parent 5cd0d986
No related branches found
No related tags found
No related merge requests found
Showing
with 21 additions and 37 deletions
......@@ -85,8 +85,6 @@ func InitLog(logConfFile string) error {
InitLogger(conf)
// set getty log
getty.SetLogger(logger)
return nil
}
......@@ -112,6 +110,9 @@ func InitLogger(conf *zap.Config) {
}
zapLogger, _ := zapLoggerConfig.Build(zap.AddCallerSkip(1))
logger = zapLogger.Sugar()
// set getty log
getty.SetLogger(logger)
}
func SetLogger(log Logger) {
......
......@@ -46,11 +46,11 @@ func init() {
confConFile = os.Getenv(constant.CONF_CONSUMER_FILE_PATH)
confProFile = os.Getenv(constant.CONF_PROVIDER_FILE_PATH)
if errCon := consumerInit(confConFile); errCon != nil {
if errCon := ConsumerInit(confConFile); errCon != nil {
log.Printf("[consumerInit] %#v", errCon)
consumerConfig = nil
}
if errPro := providerInit(confProFile); errPro != nil {
if errPro := ProviderInit(confProFile); errPro != nil {
log.Printf("[providerInit] %#v", errPro)
providerConfig = nil
}
......@@ -58,11 +58,6 @@ func init() {
// Dubbo Init
func Load() {
var (
refMap map[string]*ReferenceConfig
srvMap map[string]*ServiceConfig
)
// reference config
if consumerConfig == nil {
logger.Warnf("consumerConfig is nil!")
......@@ -70,7 +65,6 @@ func Load() {
if err := configCenterRefreshConsumer(); err != nil {
logger.Errorf("[consumer config center refresh] %#v", err)
}
refMap = make(map[string]*ReferenceConfig)
for key, ref := range consumerConfig.References {
rpcService := GetConsumerService(key)
......@@ -81,8 +75,6 @@ func Load() {
ref.id = key
ref.Refer()
ref.Implement(rpcService)
refMap[key] = ref
}
//wait for invoker is available, if wait over default 3s, then panic
var count int
......@@ -122,7 +114,6 @@ func Load() {
if err := configCenterRefreshProvider(); err != nil {
logger.Errorf("[provider config center refresh] %#v", err)
}
srvMap = make(map[string]*ServiceConfig)
for key, svs := range providerConfig.Services {
rpcService := GetProviderService(key)
if rpcService == nil {
......@@ -134,7 +125,6 @@ func Load() {
if err := svs.Export(); err != nil {
panic(fmt.Sprintf("service %s export failed! ", key))
}
srvMap[key] = svs
}
}
}
......@@ -146,5 +136,5 @@ func GetRPCService(name string) common.RPCService {
// create rpc service for consumer
func RPCService(service common.RPCService) {
providerConfig.Services[service.Reference()].Implement(service)
consumerConfig.References[service.Reference()].Implement(service)
}
......@@ -45,9 +45,9 @@ func TestConfigLoader(t *testing.T) {
assert.Nil(t, providerConfig)
assert.Equal(t, ProviderConfig{}, GetProviderConfig())
err = consumerInit(conPath)
err = ConsumerInit(conPath)
assert.NoError(t, err)
err = providerInit(proPath)
err = ProviderInit(proPath)
assert.NoError(t, err)
assert.NotNil(t, consumerConfig)
......@@ -129,10 +129,10 @@ func TestConfigLoaderWithConfigCenter(t *testing.T) {
assert.Nil(t, providerConfig)
assert.Equal(t, ProviderConfig{}, GetProviderConfig())
err = consumerInit(conPath)
err = ConsumerInit(conPath)
configCenterRefreshConsumer()
assert.NoError(t, err)
err = providerInit(proPath)
err = ProviderInit(proPath)
configCenterRefreshProvider()
assert.NoError(t, err)
......
......@@ -61,6 +61,7 @@ func (*ConsumerConfig) Prefix() string {
func SetConsumerConfig(c ConsumerConfig) {
consumerConfig = &c
}
func GetConsumerConfig() ConsumerConfig {
if consumerConfig == nil {
logger.Warnf("consumerConfig is nil!")
......@@ -69,7 +70,7 @@ func GetConsumerConfig() ConsumerConfig {
return *consumerConfig
}
func consumerInit(confConFile string) error {
func ConsumerInit(confConFile string) error {
if confConFile == "" {
return perrors.Errorf("application configure(consumer) file name is nil")
}
......
......@@ -63,7 +63,7 @@ func GetProviderConfig() ProviderConfig {
return *providerConfig
}
func providerInit(confProFile string) error {
func ProviderInit(confProFile string) error {
if len(confProFile) == 0 {
return perrors.Errorf("application configure(provider) file name is nil")
}
......
......@@ -61,8 +61,9 @@ func (c *ReferenceConfig) Prefix() string {
return constant.ReferenceConfigPrefix + c.InterfaceName + "."
}
func NewReferenceConfig(ctx context.Context) *ReferenceConfig {
return &ReferenceConfig{context: ctx}
// The only way to get a new ReferenceConfig
func NewReferenceConfig(id string, ctx context.Context) *ReferenceConfig {
return &ReferenceConfig{id: id, context: ctx}
}
func (refconfig *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
......
......@@ -68,8 +68,12 @@ func (c *ServiceConfig) Prefix() string {
return constant.ServiceConfigPrefix + c.InterfaceName + "."
}
func NewServiceConfig() *ServiceConfig {
// The only way to get a new ServiceConfig
func NewServiceConfig(id string, context context.Context) *ServiceConfig {
return &ServiceConfig{
context: context,
id: id,
unexported: atomic.NewBool(false),
exported: atomic.NewBool(false),
}
......
......@@ -54,7 +54,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -21,7 +21,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -55,7 +55,6 @@ protocols:
protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
......
......@@ -66,7 +66,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -66,7 +66,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -66,7 +66,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -76,7 +76,6 @@ protocols:
protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
......
......@@ -75,7 +75,6 @@ protocols:
protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
......
......@@ -75,7 +75,6 @@ protocols:
protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
......
......@@ -21,7 +21,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -21,7 +21,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -21,7 +21,6 @@ protocol_conf:
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
......
......@@ -23,7 +23,6 @@ services:
protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment