Commit 222f82f0 authored by AlexStocks's avatar AlexStocks

Add: use multiple service config

parent 8b875c4a
# rpc #
# Micro #
---
*getty rpc examples*
*getty micro examples*
## LICENSE ##
---
......@@ -10,6 +10,10 @@
## develop history ##
---
- 2018/08/06
- 2018/08/19
> Feature
* use multiple service config
- 2018/08/13
> Init
* add client/server
......@@ -11,6 +11,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"path"
)
......@@ -18,9 +19,10 @@ import (
import (
"github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/log"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
config "github.com/koding/multiconfig"
"gopkg.in/yaml.v2"
)
const (
......@@ -29,8 +31,8 @@ const (
)
type microConfig struct {
rpc.ServerConfig
Registry micro.RegistryConfig
rpc.ServerConfig `yaml:"core" json:"core, omitempty"`
Registry micro.ProviderRegistryConfig `yaml:"registry" json:"registry, omitempty"`
}
var (
......@@ -44,12 +46,25 @@ func initConf() {
panic(fmt.Sprintf("application configure file name is nil"))
return // I know it is of no usage. Just Err Protection.
}
if path.Ext(confFile) != ".toml" {
panic(fmt.Sprintf("application configure file name{%v} suffix must be .toml", confFile))
if path.Ext(confFile) != ".yml" {
panic(fmt.Sprintf("application configure file name{%v} suffix must be .yml", confFile))
return
}
conf = &microConfig{}
config.MustLoadWithPath(confFile, conf)
confFileStream, err := ioutil.ReadFile(confFile)
if err != nil {
panic(fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, jerrors.ErrorStack(err)))
return
}
err = yaml.Unmarshal(confFileStream, conf)
if err != nil {
panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err)))
return
}
gxlog.CError("conf:%#v", conf)
if err := conf.ServerConfig.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err))
return
......@@ -58,8 +73,7 @@ func initConf() {
panic(jerrors.ErrorStack(err))
return
}
// log
confFile = os.Getenv(APP_LOG_CONF_FILE)
if confFile == "" {
......
......@@ -21,7 +21,6 @@ import (
import (
"github.com/AlexStocks/getty-examples/micro/proto"
"github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/goext/log"
"github.com/AlexStocks/goext/net"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
......@@ -41,8 +40,6 @@ func main() {
initProfiling()
initServer()
gxlog.CInfo("%s starts successfull! its version=%s, its listen ends=%s:%s\n",
conf.AppName, Version, conf.Host, conf.Ports)
log.Info("%s starts successfull! its version=%s, its listen ends=%s:%s\n",
conf.AppName, Version, conf.Host, conf.Ports)
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "1.0.1"
Version = "1.0.2"
)
......@@ -12,6 +12,6 @@
export TARGET_EXEC_NAME="micro_server"
export BUILD_PACKAGE="app"
export TARGET_CONF_FILE="conf/config.toml"
export TARGET_CONF_FILE="conf/config.yml"
export TARGET_LOG_CONF_FILE="conf/log.xml"
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-SERVER"
Host = "127.0.0.1"
Ports = ["10000", "20000"]
ProfilePort = 10086
# client与server之间连接的超时时间
SessionTimeout = "20s"
SessionNumber = 700
# app
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 524288
PkgRQSize = 1024
PkgWQSize = 512
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-server"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "srv-node1"
Codec = "protobuf"
\ No newline at end of file
core:
app_name : "MICRO-SERVER"
host : "127.0.0.1"
ports : ["10000", "20000"]
profile_port : 10086
# client与server之间连接的超时时间
session_timeout : "20s"
session_number : 700
fail_fast_timeout : "3s"
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 524288
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
service_array:
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
\ No newline at end of file
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-SERVER"
Host = "127.0.0.1"
Ports = ["10000", "20000"]
ProfilePort = 10086
# client与server之间连接的超时时间
SessionTimeout = "20s"
SessionNumber = 700
# app
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 524288
PkgRQSize = 1024
PkgWQSize = 512
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-server"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "srv-node1"
Codec = "protobuf"
\ No newline at end of file
core:
app_name : "MICRO-SERVER"
host : "127.0.0.1"
ports : ["10000", "20000"]
profile_port : 10086
# client与server之间连接的超时时间
session_timeout : "20s"
session_number : 700
fail_fast_timeout : "3s"
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 524288
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
service_array:
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
\ No newline at end of file
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-SERVER"
Host = "127.0.0.1"
Ports = ["10000", "20000"]
ProfilePort = 10086
# client与server之间连接的超时时间
SessionTimeout = "20s"
SessionNumber = 700
# app
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 524288
PkgRQSize = 1024
PkgWQSize = 512
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-server"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "srv-node1"
Codec = "protobuf"
\ No newline at end of file
core:
app_name : "MICRO-SERVER"
host : "127.0.0.1"
ports : ["10000", "20000"]
profile_port : 10086
# client与server之间连接的超时时间
session_timeout : "20s"
session_number : 700
fail_fast_timeout : "3s"
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 524288
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
service_array:
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-pb"
protocol : "protobuf"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 10000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:10000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
-
local_host : "127.0.0.1"
local_port : 20000
group : "bj-yizhuang"
node_id : "srv-node-127.0.0.1:20000-json"
protocol : "json"
service : "TestService"
version : "v1.0"
\ No newline at end of file
Markdown is supported
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