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: config center apollo #250

Merged
merged 30 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const (

const (
CONFIG_NAMESPACE_KEY = "config.namespace"
CONFIG_GROUP_KEY = "config.group"
CONFIG_CLUSTER_KEY = "config.cluster"
CONFIG_CHECK_KEY = "config.check"
CONFIG_TIMEOUT_KET = "config.timeout"
CONFIG_VERSION_KEY = "configVersion"
COMPATIBLE_CONFIG_KEY = "compatible_config"
Expand Down
2 changes: 1 addition & 1 deletion config/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type BaseConfig struct {
}

func (c *BaseConfig) startConfigCenter(ctx context.Context) error {
url, err := common.NewURL(ctx, c.ConfigCenterConfig.Address, common.WithProtocol(c.ConfigCenterConfig.Protocol))
url, err := common.NewURL(ctx, c.ConfigCenterConfig.Address, common.WithProtocol(c.ConfigCenterConfig.Protocol), common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions config/base_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/apache/dubbo-go/common/config"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config_center"
_ "github.com/apache/dubbo-go/config_center/apollo"
)

func Test_refresh(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ package config

import (
"context"
"net/url"
"time"
)

import (
"github.com/creasty/defaults"
zouyx marked this conversation as resolved.
Show resolved Hide resolved
)

import (
"github.com/apache/dubbo-go/common/constant"
)

type ConfigCenterConfig struct {
context context.Context
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Expand All @@ -35,6 +40,7 @@ type ConfigCenterConfig struct {
Username string `yaml:"username" json:"username,omitempty"`
Password string `yaml:"password" json:"password,omitempty"`
ConfigFile string `default:"dubbo.properties" yaml:"config_file" json:"config_file,omitempty"`
Namespace string `default:"dubbo.properties" yaml:"namespace" json:"namespace,omitempty"`
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
AppConfigFile string `default:"dubbo.properties" yaml:"app_config_file" json:"app_config_file,omitempty"`
zouyx marked this conversation as resolved.
Show resolved Hide resolved
TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"`
timeout time.Duration
Expand All @@ -50,3 +56,11 @@ func (c *ConfigCenterConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
}
return nil
}

func (c *ConfigCenterConfig) GetUrlMap() url.Values {
urlMap := url.Values{}
urlMap.Set(constant.CONFIG_NAMESPACE_KEY, c.Namespace)
urlMap.Set(constant.CONFIG_GROUP_KEY, c.Group)
zouyx marked this conversation as resolved.
Show resolved Hide resolved
urlMap.Set(constant.CONFIG_CLUSTER_KEY, c.Cluster)
return urlMap
}
52 changes: 52 additions & 0 deletions config/testdata/consumer_config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
filter=
request_timeout=100ms
connect_timeout=100ms
check=true
application.organization=ikurento.com
application.name=BDTService
application.module=dubbogo user-info client
application.version=0.0.1
application.owner=ZX
application.environment=dev
registries.hangzhouzk.protocol=zookeeper
registries.hangzhouzk.timeout=3s
registries.hangzhouzk.address=127.0.0.1:2181
registries.hangzhouzk.username=
registries.hangzhouzk.password=
registries.shanghaizk.protocol=zookeeper
registries.shanghaizk.timeout=3s
registries.shanghaizk.address=127.0.0.1:2182
registries.shanghaizk.username=
registries.shanghaizk.password=
references.UserProvider.registry=hangzhouzk,shanghaizk
references.UserProvider.filter=
references.UserProvider.version=1.0
references.UserProvider.group=as
references.UserProvider.interface=com.ikurento.user.UserProvider
references.UserProvider.url=dubbo://127.0.0.1:20000/UserProvider
references.UserProvider.cluster=failover
references.UserProvider.methods[0].name=GetUser
references.UserProvider.methods[0].retries=3
references.UserProvider.params.serviceid=soa.com.ikurento.user.UserProvider
references.UserProvider.params.forks=5
protocol_conf.dubbo.reconnect_interval=0
protocol_conf.dubbo.connection_number=2
protocol_conf.dubbo.heartbeat_period=5s
protocol_conf.dubbo.session_timeout=20s
protocol_conf.dubbo.pool_size=64
protocol_conf.dubbo.pool_ttl=600
protocol_conf.dubbo.gr_pool_size=1200
protocol_conf.dubbo.queue_len=64
protocol_conf.dubbo.queue_number=60
protocol_conf.dubbo.getty_session_param.compress_encoding=false
protocol_conf.dubbo.getty_session_param.tcp_no_delay=true
protocol_conf.dubbo.getty_session_param.tcp_keep_alive=true
protocol_conf.dubbo.getty_session_param.keep_alive_period=120s
protocol_conf.dubbo.getty_session_param.tcp_r_buf_size=262144
protocol_conf.dubbo.getty_session_param.tcp_w_buf_size=65536
protocol_conf.dubbo.getty_session_param.pkg_wq_size=512
protocol_conf.dubbo.getty_session_param.tcp_read_timeout=1s
protocol_conf.dubbo.getty_session_param.tcp_write_timeout=5s
protocol_conf.dubbo.getty_session_param.wait_timeout=1s
protocol_conf.dubbo.getty_session_param.max_msg_len=1024
protocol_conf.dubbo.getty_session_param.session_name=client
24 changes: 24 additions & 0 deletions config/testdata/consumer_config_with_configcenter_apollo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# use apollo config center for fetch config file
# default config file namespace is dubbo.properties
# consumer config file Ref:consumer_config.properties
# provider config file Ref:provider_config.properties
config_center:
protocol: apollo
address: 106.12.25.204:8080
group: testApplication_yang
cluster: dev
# 'namespace' can be used for router rule , default value is dubbo.properties
# but if you want to change router rule config file ,just open this item
# namespace: governance.properties
# 'config_file' is not necessary ,default : dubbo.properties
# but if you want to change config file ,just open this item
# config_file: mockDubbog.properties

# application config required
application:
organization: "ikurento.com"
name: "BDTService"
module: "dubbogo user-info server"
version: "0.0.1"
owner: "ZX"
environment: "dev"
58 changes: 58 additions & 0 deletions config/testdata/provider_config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
filter=
application.organization=ikurento.com
application.name=BDTService
application.module=dubbogo user-info server
application.version=0.0.1
application.owner=ZX
application.environment=dev
registries.hangzhouzk.protocol=zookeeper
registries.hangzhouzk.timeout=3s
registries.hangzhouzk.address=127.0.0.1:2181
registries.hangzhouzk.username=
registries.hangzhouzk.password=
registries.shanghaizk.protocol=zookeeper
registries.shanghaizk.timeout=3s
registries.shanghaizk.address=127.0.0.1:2182
registries.shanghaizk.username=
registries.shanghaizk.password=
services.UserProvider.registry=hangzhouzk,shanghaizk
services.UserProvider.filter=
services.UserProvider.tps.limiter=default
services.UserProvider.tps.limit.interval=60000
services.UserProvider.tps.limit.rate=200
services.UserProvider.tps.limit.strategy=slidingWindow
services.UserProvider.tps.limit.rejected.handler=default
services.UserProvider.execute.limit=200
services.UserProvider.execute.limit.rejected.handler=default
services.UserProvider.protocol=dubbo
services.UserProvider.interface=com.ikurento.user.UserProvider
services.UserProvider.loadbalance=random
services.UserProvider.version=1.0
services.UserProvider.group=as
services.UserProvider.warmup=100
services.UserProvider.cluster=failover
services.UserProvider.methods[0].name=GetUser
services.UserProvider.methods[0].retries=1
services.UserProvider.methods[0].loadbalance=random
services.UserProvider.methods[0].execute.limit=200
services.UserProvider.methods[0].execute.limit.rejected.handler=default
protocols.dubbo.name=dubbo
protocols.dubbo.ip=127.0.0.1
protocols.dubbo.port=20000
protocol_conf.dubbo.session_number=700
protocol_conf.dubbo.session_timeout=20s
protocol_conf.dubbo.gr_pool_size=120
protocol_conf.dubbo.queue_len=64
protocol_conf.dubbo.queue_number=6
protocol_conf.dubbo.getty_session_param.compress_encoding=false
protocol_conf.dubbo.getty_session_param.tcp_no_delay=true
protocol_conf.dubbo.getty_session_param.tcp_keep_alive=true
protocol_conf.dubbo.getty_session_param.keep_alive_period=120s
protocol_conf.dubbo.getty_session_param.tcp_r_buf_size=262144
protocol_conf.dubbo.getty_session_param.tcp_w_buf_size=65536
protocol_conf.dubbo.getty_session_param.pkg_wq_size=512
protocol_conf.dubbo.getty_session_param.tcp_read_timeout=1s
protocol_conf.dubbo.getty_session_param.tcp_write_timeout=5s
protocol_conf.dubbo.getty_session_param.wait_timeout=1s
protocol_conf.dubbo.getty_session_param.max_msg_len=1024
protocol_conf.dubbo.getty_session_param.session_name=server
45 changes: 45 additions & 0 deletions config_center/apollo/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apollo

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/extension"
. "github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser"
)

func init() {
extension.SetConfigCenterFactory("apollo", createDynamicConfigurationFactory)
}

func createDynamicConfigurationFactory() DynamicConfigurationFactory {
return &apolloConfigurationFactory{}
}

type apolloConfigurationFactory struct{}

func (f *apolloConfigurationFactory) GetDynamicConfiguration(url *common.URL) (DynamicConfiguration, error) {
dynamicConfiguration, err := newApolloConfiguration(url)
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
zouyx marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}
dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{})
return dynamicConfiguration, err

}
Loading