Commit 8b875c4a authored by AlexStocks's avatar AlexStocks

Mod: run client/server

parent d861f584
...@@ -49,9 +49,13 @@ func initConf() { ...@@ -49,9 +49,13 @@ func initConf() {
return return
} }
conf = new(rpc.ClientConfig) conf = &microConfig{}
config.MustLoadWithPath(confFile, conf) config.MustLoadWithPath(confFile, conf)
if err := conf.CheckValidity(); err != nil { if err := conf.ClientConfig.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err))
return
}
if err := conf.Registry.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err)) panic(jerrors.ErrorStack(err))
return return
} }
......
...@@ -19,7 +19,8 @@ import ( ...@@ -19,7 +19,8 @@ import (
) )
import ( import (
"github.com/AlexStocks/getty-examples/rpc/proto" "github.com/AlexStocks/getty-examples/micro/proto"
"github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/getty/rpc" "github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/net"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
...@@ -31,7 +32,7 @@ const ( ...@@ -31,7 +32,7 @@ const (
) )
var ( var (
client *rpc.Client client *micro.Client
) )
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
...@@ -44,7 +45,6 @@ func main() { ...@@ -44,7 +45,6 @@ func main() {
initProfiling() initProfiling()
initClient() initClient()
// gxlog.CInfo("%s starts successfull! its version=%s\n", conf.AppName, Version)
log.Info("%s starts successfull! its version=%s\n", conf.AppName, Version) log.Info("%s starts successfull! its version=%s\n", conf.AppName, Version)
go test() go test()
...@@ -66,7 +66,7 @@ func initProfiling() { ...@@ -66,7 +66,7 @@ func initProfiling() {
func initClient() { func initClient() {
var err error var err error
client, err = rpc.NewClient(conf) client, err = micro.NewClient(&conf.ClientConfig, &conf.Registry)
if err != nil { if err != nil {
panic(jerrors.ErrorStack(err)) panic(jerrors.ErrorStack(err))
} }
...@@ -108,28 +108,28 @@ func initSignal() { ...@@ -108,28 +108,28 @@ func initSignal() {
} }
func testJSON() { func testJSON() {
ts := rpc_examples.TestService{} ts := micro_examples.TestService{}
testReq := rpc_examples.TestReq{"aaa", "bbb", "ccc"} testReq := micro_examples.TestReq{"aaa", "bbb", "ccc"}
testRsp := rpc_examples.TestRsp{} testRsp := micro_examples.TestRsp{}
err := client.Call(rpc.CodecJson, "127.0.0.1:20000", ts.Service(), "Test", &testReq, &testRsp) err := client.Call(nil, rpc.CodecJson, ts.Service(), ts.Version(), "Test", &testReq, &testRsp)
if err != nil { if err != nil {
log.Error("client.Call(Json, TestService::Test) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(Json, TestService::Test) = error:%s", jerrors.ErrorStack(err))
return return
} }
log.Info("TestService::Test(Json, param:%#v) = res:%s", testReq, testRsp) log.Info("TestService::Test(Json, param:%#v) = res:%s", testReq, testRsp)
addReq := rpc_examples.AddReq{1, 10} addReq := micro_examples.AddReq{1, 10}
addRsp := rpc_examples.AddRsp{} addRsp := micro_examples.AddRsp{}
err = client.Call(rpc.CodecJson, "127.0.0.1:10000", ts.Service(), "Add", &addReq, &addRsp) err = client.Call(nil, rpc.CodecJson, ts.Service(), ts.Version(), "Add", &addReq, &addRsp)
if err != nil { if err != nil {
log.Error("client.Call(Json, TestService::Add) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(Json, TestService::Add) = error:%s", jerrors.ErrorStack(err))
return return
} }
log.Info("TestService::Add(Json, req:%#v) = res:%#v", addReq, addRsp) log.Info("TestService::Add(Json, req:%#v) = res:%#v", addReq, addRsp)
errReq := rpc_examples.ErrReq{1} errReq := micro_examples.ErrReq{1}
errRsp := rpc_examples.ErrRsp{} errRsp := micro_examples.ErrRsp{}
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", ts.Service(), "Err", &errReq, &errRsp) err = client.Call(nil, rpc.CodecJson, ts.Service(), ts.Version(), "Err", &errReq, &errRsp)
if err != nil { if err != nil {
// error test case, this invocation should step into this branch. // error test case, this invocation should step into this branch.
log.Error("client.Call(Json, TestService::Err) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(Json, TestService::Err) = error:%s", jerrors.ErrorStack(err))
...@@ -139,28 +139,28 @@ func testJSON() { ...@@ -139,28 +139,28 @@ func testJSON() {
} }
func testProtobuf() { func testProtobuf() {
ts := rpc_examples.TestService{} ts := micro_examples.TestService{}
testReq := rpc_examples.TestReq{"aaa", "bbb", "ccc"} testReq := micro_examples.TestReq{"aaa", "bbb", "ccc"}
testRsp := rpc_examples.TestRsp{} testRsp := micro_examples.TestRsp{}
err := client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", ts.Service(), "Test", &testReq, &testRsp) err := client.Call(nil, rpc.CodecProtobuf, ts.Service(), ts.Version(), "Test", &testReq, &testRsp)
if err != nil { if err != nil {
log.Error("client.Call(protobuf, TestService::Test) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(protobuf, TestService::Test) = error:%s", jerrors.ErrorStack(err))
return return
} }
log.Info("TestService::Test(protobuf, param:%#v) = res:%s", testReq, testRsp) log.Info("TestService::Test(protobuf, param:%#v) = res:%s", testReq, testRsp)
addReq := rpc_examples.AddReq{1, 10} addReq := micro_examples.AddReq{1, 10}
addRsp := rpc_examples.AddRsp{} addRsp := micro_examples.AddRsp{}
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:10000", ts.Service(), "Add", &addReq, &addRsp) err = client.Call(nil, rpc.CodecProtobuf, ts.Service(), ts.Version(), "Add", &addReq, &addRsp)
if err != nil { if err != nil {
log.Error("client.Call(protobuf, TestService::Add) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(protobuf, TestService::Add) = error:%s", jerrors.ErrorStack(err))
return return
} }
log.Info("TestService::Add(protobuf, req:%#v) = res:%#v", addReq, addRsp) log.Info("TestService::Add(protobuf, req:%#v) = res:%#v", addReq, addRsp)
errReq := rpc_examples.ErrReq{1} errReq := micro_examples.ErrReq{1}
errRsp := rpc_examples.ErrRsp{} errRsp := micro_examples.ErrRsp{}
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", ts.Service(), "Err", &errReq, &errRsp) err = client.Call(nil, rpc.CodecProtobuf, ts.Service(), ts.Version(), "Err", &errReq, &errRsp)
if err != nil { if err != nil {
// error test case, this invocation should step into this branch. // error test case, this invocation should step into this branch.
log.Error("client.Call(protobuf, TestService::Err) = error:%s", jerrors.ErrorStack(err)) log.Error("client.Call(protobuf, TestService::Err) = error:%s", jerrors.ErrorStack(err))
...@@ -170,8 +170,8 @@ func testProtobuf() { ...@@ -170,8 +170,8 @@ func testProtobuf() {
} }
func test() { func test() {
for i := 0; i < 5; i++ { for i := 0; i < 1; i++ {
testJSON() // testJSON()
testProtobuf() testProtobuf()
} }
} }
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
package main package main
var ( var (
Version = "0.9.2" Version = "1.0.1"
) )
#!/usr/bin/env bash #!/usr/bin/env bash
# ****************************************************** # ******************************************************
# DESC : getty rpc app devops script # DESC : getty micro app devops script
# AUTHOR : Alex Stocks # AUTHOR : Alex Stocks
# VERSION : 1.0 # VERSION : 1.0
# LICENCE : LGPL V3 # LICENCE : LGPL V3
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# FILE : app.properties # FILE : app.properties
# ****************************************************** # ******************************************************
export TARGET_EXEC_NAME="rpc_client" export TARGET_EXEC_NAME="micro_client"
export BUILD_PACKAGE="app" export BUILD_PACKAGE="app"
export TARGET_CONF_FILE="conf/config.toml" export TARGET_CONF_FILE="conf/config.toml"
......
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-CLIENT" AppName = "MICRO-CLIENT"
# host # host
LocalHost = "127.0.0.1" LocalHost = "127.0.0.1"
...@@ -38,4 +38,14 @@ FailFastTimeout = "3s" ...@@ -38,4 +38,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-client" SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-CLIENT" AppName = "MICRO-CLIENT"
# host # host
LocalHost = "127.0.0.1" LocalHost = "127.0.0.1"
...@@ -38,4 +38,14 @@ FailFastTimeout = "3s" ...@@ -38,4 +38,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-client" SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-CLIENT" AppName = "MICRO-CLIENT"
# host # host
LocalHost = "127.0.0.1" LocalHost = "127.0.0.1"
...@@ -38,4 +38,14 @@ FailFastTimeout = "3s" ...@@ -38,4 +38,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-client" SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// source: service.proto // source: service.proto
/* /*
Package rpc_examples is a generated protocol buffer package. Package micro_examples is a generated protocol buffer package.
It is generated from these files: It is generated from these files:
service.proto service.proto
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
ErrReq ErrReq
ErrRsp ErrRsp
*/ */
package rpc_examples package micro_examples
import proto "github.com/gogo/protobuf/proto" import proto "github.com/gogo/protobuf/proto"
import fmt "fmt" import fmt "fmt"
...@@ -90,12 +90,12 @@ func (*ErrRsp) ProtoMessage() {} ...@@ -90,12 +90,12 @@ func (*ErrRsp) ProtoMessage() {}
func (*ErrRsp) Descriptor() ([]byte, []int) { return fileDescriptorService, []int{5} } func (*ErrRsp) Descriptor() ([]byte, []int) { return fileDescriptorService, []int{5} }
func init() { func init() {
proto.RegisterType((*TestReq)(nil), "rpc_examples.TestReq") proto.RegisterType((*TestReq)(nil), "micro_examples.TestReq")
proto.RegisterType((*TestRsp)(nil), "rpc_examples.TestRsp") proto.RegisterType((*TestRsp)(nil), "micro_examples.TestRsp")
proto.RegisterType((*AddReq)(nil), "rpc_examples.AddReq") proto.RegisterType((*AddReq)(nil), "micro_examples.AddReq")
proto.RegisterType((*AddRsp)(nil), "rpc_examples.AddRsp") proto.RegisterType((*AddRsp)(nil), "micro_examples.AddRsp")
proto.RegisterType((*ErrReq)(nil), "rpc_examples.ErrReq") proto.RegisterType((*ErrReq)(nil), "micro_examples.ErrReq")
proto.RegisterType((*ErrRsp)(nil), "rpc_examples.ErrRsp") proto.RegisterType((*ErrRsp)(nil), "micro_examples.ErrRsp")
} }
func (this *TestReq) VerboseEqual(that interface{}) error { func (this *TestReq) VerboseEqual(that interface{}) error {
if that == nil { if that == nil {
...@@ -480,7 +480,7 @@ func (this *TestReq) GoString() string { ...@@ -480,7 +480,7 @@ func (this *TestReq) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 7) s := make([]string, 0, 7)
s = append(s, "&rpc_examples.TestReq{") s = append(s, "&micro_examples.TestReq{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "B: "+fmt.Sprintf("%#v", this.B)+",\n") s = append(s, "B: "+fmt.Sprintf("%#v", this.B)+",\n")
s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n") s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n")
...@@ -492,7 +492,7 @@ func (this *TestRsp) GoString() string { ...@@ -492,7 +492,7 @@ func (this *TestRsp) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 5) s := make([]string, 0, 5)
s = append(s, "&rpc_examples.TestRsp{") s = append(s, "&micro_examples.TestRsp{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
...@@ -502,7 +502,7 @@ func (this *AddReq) GoString() string { ...@@ -502,7 +502,7 @@ func (this *AddReq) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 6) s := make([]string, 0, 6)
s = append(s, "&rpc_examples.AddReq{") s = append(s, "&micro_examples.AddReq{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "B: "+fmt.Sprintf("%#v", this.B)+",\n") s = append(s, "B: "+fmt.Sprintf("%#v", this.B)+",\n")
s = append(s, "}") s = append(s, "}")
...@@ -513,7 +513,7 @@ func (this *AddRsp) GoString() string { ...@@ -513,7 +513,7 @@ func (this *AddRsp) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 5) s := make([]string, 0, 5)
s = append(s, "&rpc_examples.AddRsp{") s = append(s, "&micro_examples.AddRsp{")
s = append(s, "Sum: "+fmt.Sprintf("%#v", this.Sum)+",\n") s = append(s, "Sum: "+fmt.Sprintf("%#v", this.Sum)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
...@@ -523,7 +523,7 @@ func (this *ErrReq) GoString() string { ...@@ -523,7 +523,7 @@ func (this *ErrReq) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 5) s := make([]string, 0, 5)
s = append(s, "&rpc_examples.ErrReq{") s = append(s, "&micro_examples.ErrReq{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
...@@ -533,7 +533,7 @@ func (this *ErrRsp) GoString() string { ...@@ -533,7 +533,7 @@ func (this *ErrRsp) GoString() string {
return "nil" return "nil"
} }
s := make([]string, 0, 5) s := make([]string, 0, 5)
s = append(s, "&rpc_examples.ErrRsp{") s = append(s, "&micro_examples.ErrRsp{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
......
syntax = "proto2"; syntax = "proto2";
package rpc_examples; package micro_examples;
import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto";
......
package rpc_examples package micro_examples
import ( import (
jerrors "github.com/juju/errors" jerrors "github.com/juju/errors"
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
) )
import ( import (
"github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/getty/rpc" "github.com/AlexStocks/getty/rpc"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors" jerrors "github.com/juju/errors"
...@@ -27,8 +28,13 @@ const ( ...@@ -27,8 +28,13 @@ const (
APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE" APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE"
) )
type microConfig struct {
rpc.ServerConfig
Registry micro.RegistryConfig
}
var ( var (
conf *rpc.ServerConfig conf *microConfig
) )
func initConf() { func initConf() {
...@@ -42,13 +48,18 @@ func initConf() { ...@@ -42,13 +48,18 @@ func initConf() {
panic(fmt.Sprintf("application configure file name{%v} suffix must be .toml", confFile)) panic(fmt.Sprintf("application configure file name{%v} suffix must be .toml", confFile))
return return
} }
conf = &rpc.ServerConfig{} conf = &microConfig{}
config.MustLoadWithPath(confFile, conf) config.MustLoadWithPath(confFile, conf)
if err := conf.CheckValidity(); err != nil { if err := conf.ServerConfig.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err))
return
}
if err := conf.Registry.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err)) panic(jerrors.ErrorStack(err))
return return
} }
// log // log
confFile = os.Getenv(APP_LOG_CONF_FILE) confFile = os.Getenv(APP_LOG_CONF_FILE)
if confFile == "" { if confFile == "" {
......
...@@ -19,8 +19,8 @@ import ( ...@@ -19,8 +19,8 @@ import (
) )
import ( import (
"github.com/AlexStocks/getty-examples/rpc/proto" "github.com/AlexStocks/getty-examples/micro/proto"
"github.com/AlexStocks/getty/rpc" "github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/goext/log" "github.com/AlexStocks/goext/log"
"github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/net"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
...@@ -32,7 +32,7 @@ const ( ...@@ -32,7 +32,7 @@ const (
) )
var ( var (
server *rpc.Server server *micro.Server
) )
func main() { func main() {
...@@ -64,12 +64,12 @@ func initProfiling() { ...@@ -64,12 +64,12 @@ func initProfiling() {
func initServer() { func initServer() {
var err error var err error
server, err = rpc.NewServer(conf) server, err = micro.NewServer(&conf.ServerConfig, &conf.Registry)
if err != nil { if err != nil {
panic(jerrors.ErrorStack(err)) panic(jerrors.ErrorStack(err))
return return
} }
err = server.Register(&rpc_examples.TestService{}) err = server.Register(&micro_examples.TestService{})
if err != nil { if err != nil {
panic(jerrors.ErrorStack(err)) panic(jerrors.ErrorStack(err))
return return
......
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
package main package main
var ( var (
Version = "0.9.2" Version = "1.0.1"
) )
#!/usr/bin/env bash #!/usr/bin/env bash
# ****************************************************** # ******************************************************
# DESC : getty rpc app devops script # DESC : getty micro app devops script
# AUTHOR : Alex Stocks # AUTHOR : Alex Stocks
# VERSION : 1.0 # VERSION : 1.0
# LICENCE : LGPL V3 # LICENCE : LGPL V3
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# FILE : app.properties # FILE : app.properties
# ****************************************************** # ******************************************************
export TARGET_EXEC_NAME="rpc_server" export TARGET_EXEC_NAME="micro_server"
export BUILD_PACKAGE="app" export BUILD_PACKAGE="app"
export TARGET_CONF_FILE="conf/config.toml" export TARGET_CONF_FILE="conf/config.toml"
......
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-SERVER" AppName = "MICRO-SERVER"
Host = "127.0.0.1" Host = "127.0.0.1"
...@@ -30,4 +30,14 @@ FailFastTimeout = "3s" ...@@ -30,4 +30,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-server" 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
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-SERVER" AppName = "MICRO-SERVER"
Host = "127.0.0.1" Host = "127.0.0.1"
...@@ -30,4 +30,14 @@ FailFastTimeout = "3s" ...@@ -30,4 +30,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-server" 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
# toml configure file # toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写 # toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-SERVER" AppName = "MICRO-SERVER"
Host = "127.0.0.1" Host = "127.0.0.1"
...@@ -30,4 +30,14 @@ FailFastTimeout = "3s" ...@@ -30,4 +30,14 @@ FailFastTimeout = "3s"
TcpWriteTimeout = "5s" TcpWriteTimeout = "5s"
WaitTimeout = "1s" WaitTimeout = "1s"
MaxMsgLen = 1024 MaxMsgLen = 1024
SessionName = "getty-rpc-server" 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
#!/usr/bin/env bash
# ******************************************************
# DESC : getty rpc app devops script
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : LGPL V3
# EMAIL : alexstocks@foxmail.com
# MOD : 2018-08-06 13:23
# FILE : load.sh
# ******************************************************
APP_NAME="rpc_server"
APP_ARGS=""
SLEEP_INTERVAL=5
MAX_LIFETIME=4000
PROJECT_HOME=""
OS_NAME=`uname`
if [[ ${OS_NAME} != "Windows" ]]; then
PROJECT_HOME=`pwd`
PROJECT_HOME=${PROJECT_HOME}"/"
else
APP_NAME="rpc_server.exe"
fi
export APP_CONF_FILE=${PROJECT_HOME}"conf/config.toml"
export APP_LOG_CONF_FILE=${PROJECT_HOME}"conf/log.xml"
# export GOTRACEBACK=system
# export GODEBUG=gctrace=1
usage() {
echo "Usage: $0 start"
echo " $0 stop"
echo " $0 term"
echo " $0 restart"
echo " $0 list"
echo " $0 monitor"
echo " $0 crontab"
exit
}
start() {
APP_LOG_PATH=${PROJECT_HOME}"logs/"
mkdir -p ${APP_LOG_PATH}
APP_BIN=${PROJECT_HOME}sbin/${APP_NAME}
chmod u+x ${APP_BIN}
# CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &"
CMD="${APP_BIN}"
eval ${CMD}
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
CUR=`date +%FT%T`
if [ "${PID}" != "" ]; then
for p in ${PID}
do
echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR}
done
fi
}
stop() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [ "${PID}" != "" ];
then
for ps in ${PID}
do
echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")"
kill -2 ${ps}
done
fi
}
term() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [ "${PID}" != "" ];
then
for ps in ${PID}
do
echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")"
kill -9 ${ps}
done
fi
}
list() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'`
fi
if [ "${PID}" != "" ]; then
echo "list ${APP_NAME}"
if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then
echo "index: user, pid, start, duration"
else
echo "index: PID, WINPID, UID, STIME, COMMAND"
fi
idx=0
for ps in ${PID}
do
echo "${idx}: ${ps}"
((idx ++))
done
fi
}
monitor() {
idx=0
while true; do
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [[ "${PID}" == "" ]]; then
start
idx=0
fi
((LIFE=idx*${SLEEP_INTERVAL}))
echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds."
((idx ++))
sleep ${SLEEP_INTERVAL}
done
}
crontab() {
idx=0
while true; do
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [[ "${PID}" == "" ]]; then
start
idx=0
fi
((LIFE=idx*${SLEEP_INTERVAL}))
echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds."
((idx ++))
sleep ${SLEEP_INTERVAL}
if [[ ${LIFE} -gt ${MAX_LIFETIME} ]]; then
kill -9 ${PID}
fi
done
}
opt=$1
case C"$opt" in
Cstart)
start
;;
Cstop)
stop
;;
Cterm)
term
;;
Crestart)
term
start
;;
Clist)
list
;;
Cmonitor)
monitor
;;
Ccrontab)
crontab
;;
C*)
usage
;;
esac
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "RPC-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-rpc-server"
<logging>
<filter enabled="true">
<tag>stdout</tag>
<type>console</type>
<!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
<level>DEBUG</level>
</filter>
<filter enabled="false">
<tag>debug_file</tag>
<type>file</type>
<level>DEBUG</level>
<property name="filename">logs/debug.log</property>
<property name="format">[%D %T] [%L] [%S] %M</property>
<property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
<property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
<property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
<property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
</filter>
<filter enabled="true">
<tag>info_file</tag>
<type>file</type>
<level>INFO</level>
<property name="filename">logs/info.log</property>
<!--
%T - Time (15:04:05 MST)
%t - Time (15:04)
%D - Date (2006/01/02)
%d - Date (01/02/06)
%L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT)
%S - Source
%M - Message
It ignores unknown format strings (and removes them)
Recommended: "[%D %T] [%L] (%S) %M"
-->
<property name="format">[%D %T] [%L] [%S] %M</property>
<property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
<property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
<property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
<property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
</filter>
<filter enabled="true">
<tag>warn_file</tag>
<type>file</type>
<level>WARNING</level>
<property name="filename">logs/warn.log</property>
<property name="format">[%D %T] [%L] [%S] %M</property>
<property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
<property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
<property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
<property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
</filter>
<filter enabled="true">
<tag>error_file</tag>
<type>file</type>
<level>ERROR</level>
<property name="filename">logs/error.log</property>
<property name="format">[%D %T] [%L] [%S] %M</property>
<property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
<property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
<property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
<property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
</filter>
</logging>
This source diff could not be displayed because it is too large. You can view the blob instead.
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