Skip to content

Commit

Permalink
Add:reference & service protocol default
Browse files Browse the repository at this point in the history
  • Loading branch information
hxmhlt committed Sep 12, 2019
1 parent 895e7c3 commit 414b7ae
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 3 deletions.
16 changes: 15 additions & 1 deletion config/provider_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ import (
"github.com/stretchr/testify/assert"
)

func TestProviderInit(t *testing.T) {
func TestConsumerInit(t *testing.T) {
conPath, err := filepath.Abs("./testdata/consumer_config_with_configcenter.yml")
assert.NoError(t, err)
assert.NoError(t, ConsumerInit(conPath))
assert.Equal(t, "default", consumerConfig.ProxyFactory)
assert.Equal(t, "dubbo.properties", consumerConfig.ConfigCenterConfig.ConfigFile)
assert.Equal(t, "100ms", consumerConfig.Connect_Timeout)
}

func TestConsumerInitWithDefaultProtocol(t *testing.T) {
conPath, err := filepath.Abs("./testdata/consumer_config_withoutProtocol.yml")
assert.NoError(t, err)
assert.NoError(t, ConsumerInit(conPath))
assert.Equal(t, "dubbo", consumerConfig.References["UserProvider"].Protocol)
}

func TestProviderInitWithDefaultProtocol(t *testing.T) {
conPath, err := filepath.Abs("./testdata/provider_config_withoutProtocol.yml")
assert.NoError(t, err)
assert.NoError(t, ProviderInit(conPath))
assert.Equal(t, "dubbo", providerConfig.Services["UserProvider"].Protocol)
}
2 changes: 1 addition & 1 deletion config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ReferenceConfig struct {
Check *bool `yaml:"check" json:"check,omitempty" property:"check"`
Url string `yaml:"url" json:"url,omitempty" property:"url"`
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Protocol string `yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
Protocol string `default:"dubbo" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"`
Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Expand Down
2 changes: 1 addition & 1 deletion config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ServiceConfig struct {
context context.Context
id string
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ','
Protocol string `default:"dubbo" required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ','
InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"`
Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"`
Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Expand Down
77 changes: 77 additions & 0 deletions config/testdata/consumer_config_withoutProtocol.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# dubbo client yaml configure file

filter: ""

# client
request_timeout : "100ms"
# connect timeout
connect_timeout : "100ms"
check: true
# application config
application_config:
organization : "ikurento.com"
name : "BDTService"
module : "dubbogo user-info client"
version : "0.0.1"
owner : "ZX"
environment : "dev"

registries :

"hangzhouzk":
protocol: "zookeeper"
timeout : "3s"
address: "127.0.0.1:2181"
username: ""
password: ""
"shanghaizk":
protocol: "zookeeper"
timeout : "3s"
address: "127.0.0.1:2182"
username: ""
password: ""

references:
"UserProvider":
registry: "hangzhouzk,shanghaizk"
filter: ""
version: "1.0"
group: "as"
interface : "com.ikurento.user.UserProvider"
url: "dubbo://127.0.0.1:20000/UserProvider"
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
params:
"serviceid":
"soa.com.ikurento.user.UserProvider"
"forks": 5

protocol_conf:
dubbo:
reconnect_interval: 0
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
pool_size: 64
pool_ttl: 600
# gr_pool_size is recommended to be set to [cpu core number] * 100
gr_pool_size: 1200
# queue_len is recommended to be set to 64 or 128
queue_len: 64
# queue_number is recommended to be set to gr_pool_size / 20
queue_number: 60
getty_session_param:
compress_encoding: false
tcp_no_delay: true
tcp_keep_alive: true
keep_alive_period: "120s"
tcp_r_buf_size: 262144
tcp_w_buf_size: 65536
pkg_wq_size: 512
tcp_read_timeout: "1s"
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
session_name: "client"
76 changes: 76 additions & 0 deletions config/testdata/provider_config_withoutProtocol.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# dubbo server yaml configure file

filter: ""
# application config
application_config:
organization : "ikurento.com"
name : "BDTService"
module : "dubbogo user-info server"
version : "0.0.1"
owner : "ZX"
environment : "dev"

registries :
"hangzhouzk":
protocol: "zookeeper"
timeout : "3s"
address: "127.0.0.1:2181"
username: ""
password: ""
"shanghaizk":
protocol: "zookeeper"
timeout : "3s"
address: "127.0.0.1:2182"
username: ""
password: ""


services:
"UserProvider":
registry: "hangzhouzk,shanghaizk"
filter: ""
# equivalent to interface of dubbo.xml
interface : "com.ikurento.user.UserProvider"
loadbalance: "random"
version: "1.0"
group: "as"
warmup: "100"
cluster: "failover"
methods:
- name: "GetUser"
retries: 1
loadbalance: "random"

protocols:
"dubbo":
name: "dubbo"
# while using dubbo protocol, ip cannot is 127.0.0.1, because client of java-dubbo will get 'connection refuse'
ip : "127.0.0.1"
port : 20000
#- name: "jsonrpc"
# ip: "127.0.0.1"
# port: 20001

protocol_conf:
dubbo:
session_number: 700
session_timeout: "20s"
# gr_pool_size is recommended to be set to [cpu core number] * 10
gr_pool_size: 120
# queue_len is recommended to be set to 64 or 128
queue_len: 64
# queue_number is recommended to be set to gr_pool_size / 20
queue_number: 6
getty_session_param:
compress_encoding: false
tcp_no_delay: true
tcp_keep_alive: true
keep_alive_period: "120s"
tcp_r_buf_size: 262144
tcp_w_buf_size: 65536
pkg_wq_size: 512
tcp_read_timeout: "1s"
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
session_name: "server"

0 comments on commit 414b7ae

Please sign in to comment.