diff --git a/README.md b/README.md index 184deb8..b411d83 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,83 @@ -# odin - -## directory - -``` -├── app -│   ├── common -│   │   ├── Const.go -│   │   ├── util.go -│   │   └── var.go -│   ├── entity -│   │   └── user.go -│   ├── repository -│   │   ├── memoryDao -│   │   │   └── user.go -│   │   ├── pikaDao -│   │   │   └── user.go -│   │   ├── redisDao -│   │   │   └── user.go -│   │   └── repository.go -│   ├── service -│   │   ├── serviceBridge.go -│   │   └── service.go -│   ├── serviceImpl -│   │   ├── HelloService.go -│   │   └── UserService.go -│   ├── serviceInit.go -│   └── serviceInterface -│   └── interface.go -├── bin -│   └── odin -├── cmd -│   └── odin -│   └── main.go -├── conf -│   ├── conf_dev.ini -│   ├── conf.ini -│   ├── conf_release.ini -│   └── conf_online.ini -├── examples -│   └── main.go -├── go.mod -├── Makefile -├── README.md -└── version - └── version.go +# Odin + +## Introduction + +Odin是基于go语言的rpc框架,框架除了致力于提供高性能的服务间调用能力外,也提供完善的服务治理功能、支持多种服务注册发现机制。为了业务方使用框架更加便捷,框架还具有配套管理工具自动生成代码,提高开发效率。 + +## Features + +### 高性能 +首先,框架底层基于rpcx框架,其是一个纯Go语言的rpc框架,与主流rpc框架进行性能对比,优势明显。其性能仅弱于Go原生rpc调用。 + +### 服务治理 +odin框架可提供统一的服务注册管理,仅通过配置地址方式即可方便使用以及切换服务注册中心。在支持原生容错和负载均衡机制基 +础上,开发插件系统,包括限流、断路器、打点统计、耗时报警等。 + +### 开发便捷 +Odin结合配套的辅助工具rigger,可以直接生成框架模板,业务使用方只需定义对外提供接口,可自动生成服务代码,开发只需编写 +业务逻辑。提供给其他服务的client代码,同样可命令生成,方便调用。 + +### 自定义支持 +Odin框架目前已支持日志Trace跨服务传递,记录一次完整请求的所有记录,根据同一TraceID,查看全部链路。其他包括动态插件都 +可自定义开发,只需最终在main注入即可。 + +## Quick Start + +### Install +``` +//进入开发目录$GOPATH/src +$ cd $GOPATH/src/ + +//Clone项目到开发目录 +$ git clone git@github.com:tal-tech/odin.git +``` + +### Build ``` +//Makefile可依需求自定义 +make +``` + +### Run +``` +//启动 +bin/odin +``` + +## Config +``` +//conf/conf.ini +//listen port +[Server] +network=tcp +port=11900 + +//Register Addr +[Registry] +//注册中心启用开关 +status=off +//Registry Address +addrs=127.0.0.1:2181 +basePath=/odin_demo +``` + +## Example +``` +go run -tags 'zookeeper' examples/main.go -c $GOPATH/src/odin/conf/conf.ini +//Output +SayHello: i'm hello service,recv greeting:hello, i'm odin client +AddUser: &{Id:3} +UserInfo: &{学而思 %!s(int=10) beijing} +UpdateUser: &{} +UserInfo: &{网校 %!s(int=20) beijing} +``` + +## 框架共建 +我们的目标是将Odin打造成一个高性能、高可靠、易用的微服务框架,欢迎大家共同参与,做更多的创新以及贡献,包括但不限于 +以下内容: +* 支持更多的调用方式; +* 扩展中间件功能; +* 提供更灵活、更便捷的服务治理功能; +## 联系我们 +issue: [https://github.com/tal-tech/odin/issues](https://github.com/tal-tech/odin/issues) diff --git a/examples/main.go b/examples/main.go index e29cab2..9df5eb5 100644 --- a/examples/main.go +++ b/examples/main.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - p "git.100tal.com/wangxiao_go_lib/microCommon/micro/proto" + p "odin/proto" "github.com/tal-tech/xtools/addrutil" "github.com/tal-tech/xtools/confutil" @@ -25,8 +25,61 @@ func main() { if confutil.GetConf("Registry", "status") == "on" { - d = rpcxutil.GetClientDiscovery(rpcxutil.GetServiceBasePath(), "Odin") - + //d = rpcxutil.GetClientDiscovery(rpcxutil.GetServiceBasePath(), "Odin") + wrapClient := rpcxutil.NewWrapClient(rpcxutil.GetServiceBasePath(), "Odin", client.Failtry, client.RandomSelect, option) + + //helloservice + req := &p.SayHelloRequest{ + Greeting: "hello, i'm odin client", + } + resp := &p.SayHelloResponse{} + err := wrapClient.WrapCall(context.Background(), "SayHello", req, resp) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call SayHello: %v\n", err) + } + fmt.Fprintf(os.Stdout, "SayHello: %s\n", resp.Reply) + + //userservice + reqAdd := &p.AddUserRequest{ + Name: "学而思", + Age: 10, + City: "beijing", + } + respAdd := &p.AddUserResponse{} + err = wrapClient.WrapCall(context.Background(), "AddUser", reqAdd, respAdd) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call AddUser: %v\n", err) + } + fmt.Fprintf(os.Stdout, "AddUser: %+v\n", respAdd) + + reqInfo := &p.UserInfoRequest{ + Id: respAdd.Id, + } + respInfo := &p.UserInfoResponse{} + err = wrapClient.WrapCall(context.Background(), "UserInfo", reqInfo, respInfo) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) + + reqUpdate := &p.UpdateUserRequest{ + Id: respAdd.Id, + Name: "网校", + Age: 20, + City: "beijing", + } + respUpdate := &p.UpdateUserResponse{} + err = wrapClient.WrapCall(context.Background(), "UpdateUser", reqUpdate, respUpdate) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UpdateUser: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UpdateUser: %s\n", respUpdate) + + err = wrapClient.WrapCall(context.Background(), "UserInfo", reqInfo, respInfo) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) } else { addr, _ := addrutil.Extract("") @@ -34,62 +87,61 @@ func main() { serviceAddr := confutil.GetConf("Server", "network") + "@" + addr + ":" + confutil.GetConf("Server", "port") d = client.NewPeer2PeerDiscovery(serviceAddr, "") - } - - xclient := client.NewXClient("Odin", client.Failtry, client.RandomSelect, d, option) - - defer xclient.Close() - - //helloservice - req := &p.SayHelloRequest{ - Greeting: "hello, i'm odin client", - } - resp := &p.SayHelloResponse{} - err := xclient.Call(context.Background(), "SayHello", req, resp) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to call SayHello: %v\n", err) - } - fmt.Fprintf(os.Stdout, "SayHello: %s\n", resp.Reply) - - //userservice - reqAdd := &p.AddUserRequest{ - Name: "学而思", - Age: 10, - City: "beijing", - } - respAdd := &p.AddUserResponse{} - err = xclient.Call(context.Background(), "AddUser", reqAdd, respAdd) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to call AddUser: %v\n", err) - } - fmt.Fprintf(os.Stdout, "AddUser: %+v\n", respAdd) - - reqInfo := &p.UserInfoRequest{ - Id: respAdd.Id, - } - respInfo := &p.UserInfoResponse{} - err = xclient.Call(context.Background(), "UserInfo", reqInfo, respInfo) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) - } - fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) - - reqUpdate := &p.UpdateUserRequest{ - Id: respAdd.Id, - Name: "网校", - Age: 20, - City: "beijing", - } - respUpdate := &p.UpdateUserResponse{} - err = xclient.Call(context.Background(), "UpdateUser", reqUpdate, respUpdate) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to call UpdateUser: %v\n", err) - } - fmt.Fprintf(os.Stdout, "UpdateUser: %s\n", respUpdate) - err = xclient.Call(context.Background(), "UserInfo", reqInfo, respInfo) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) + xclient := client.NewXClient("Odin", client.Failtry, client.RandomSelect, d, option) + defer xclient.Close() + + //helloservice + req := &p.SayHelloRequest{ + Greeting: "hello, i'm odin client", + } + resp := &p.SayHelloResponse{} + err := xclient.Call(context.Background(), "SayHello", req, resp) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call SayHello: %v\n", err) + } + fmt.Fprintf(os.Stdout, "SayHello: %s\n", resp.Reply) + + //userservice + reqAdd := &p.AddUserRequest{ + Name: "学而思", + Age: 10, + City: "beijing", + } + respAdd := &p.AddUserResponse{} + err = xclient.Call(context.Background(), "AddUser", reqAdd, respAdd) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call AddUser: %v\n", err) + } + fmt.Fprintf(os.Stdout, "AddUser: %+v\n", respAdd) + + reqInfo := &p.UserInfoRequest{ + Id: respAdd.Id, + } + respInfo := &p.UserInfoResponse{} + err = xclient.Call(context.Background(), "UserInfo", reqInfo, respInfo) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) + + reqUpdate := &p.UpdateUserRequest{ + Id: respAdd.Id, + Name: "网校", + Age: 20, + City: "beijing", + } + respUpdate := &p.UpdateUserResponse{} + err = xclient.Call(context.Background(), "UpdateUser", reqUpdate, respUpdate) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UpdateUser: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UpdateUser: %s\n", respUpdate) + + err = xclient.Call(context.Background(), "UserInfo", reqInfo, respInfo) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to call UserInfo: %v\n", err) + } + fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) } - fmt.Fprintf(os.Stdout, "UserInfo: %s\n", respInfo) } diff --git a/go.mod b/go.mod index 0855832..7b68e4e 100644 --- a/go.mod +++ b/go.mod @@ -2,39 +2,43 @@ module odin go 1.12 -replace github.com/smallnest/rpcx v0.0.0 => github.com/sixiaobai/rpcxmirror v1.0.0 +replace github.com/smallnest/rpcx v0.0.0 => github.com/smallnest/rpcx v0.0.0-20200214051052-c65a6415f3d1 require ( + git.100tal.com/wangxiao_go_lib/microCommon v1.0.8 // indirect + github.com/abronan/valkeyrie v0.0.0-20200127174252-ef4277a138cd // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.69 // indirect + github.com/anacrolix/envpprof v1.1.0 // indirect + github.com/anacrolix/sync v0.2.0 // indirect github.com/apache/thrift v0.13.0 // indirect - github.com/docker/libkv v0.2.1 // indirect - github.com/fatih/color v1.9.0 // indirect + github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect + github.com/buger/jsonparser v0.0.0-20191204142016-1a29609e0929 // indirect + github.com/edwingeng/doublejump v0.0.0-20200219153503-7cfc0ed6e836 // indirect github.com/gin-gonic/gin v1.6.3 // indirect github.com/go-redis/redis v6.15.9+incompatible // indirect - github.com/golang/mock v1.4.0 // indirect - github.com/google/btree v1.0.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/grandcat/zeroconf v1.0.0 // indirect + github.com/hashicorp/consul/api v1.4.0 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/henrylee2cn/goutil v0.0.0-20200801052108-cbf313aea969 // indirect github.com/henrylee2cn/teleport v5.0.0+incompatible // indirect github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3 // indirect - github.com/juju/ratelimit v1.0.1 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect github.com/kavu/go_reuseport v1.5.0 // indirect - github.com/kr/pretty v0.2.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect - github.com/onsi/ginkgo v1.11.0 // indirect - github.com/onsi/gomega v1.8.1 // indirect + github.com/klauspost/cpuid v1.2.3 // indirect + github.com/klauspost/reedsolomon v1.9.3 // indirect + github.com/lucas-clemente/quic-go v0.15.5 // indirect + github.com/nacos-group/nacos-sdk-go v0.0.0-20191128082542-fe1b325b125c // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openzipkin/zipkin-go v0.2.2 // indirect + github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/pierrec/lz4 v2.0.5+incompatible // indirect github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect - github.com/rs/cors v1.7.0 // indirect github.com/samuel/go-zookeeper v0.0.0-20200724154423-2164a8ac840e // indirect - github.com/satori/go.uuid v1.2.0 // indirect github.com/sirupsen/logrus v1.5.0 // indirect + github.com/smallnest/libkv-etcdv3-store v1.1.6 // indirect github.com/smallnest/rpcx v0.0.0 - github.com/soheilhy/cmux v0.1.4 // indirect + github.com/smallnest/valkeyrie v0.0.0-20191030065038-13edeca3d026 // indirect github.com/spf13/cast v1.3.1 github.com/streadway/handy v0.0.0-20200128134331-0f66f006fb2e // indirect github.com/tal-tech/connPool v0.0.0-20200806112113-738c408fe6ae // indirect @@ -44,16 +48,16 @@ require ( github.com/tal-tech/routinePool v0.0.0-20200806121001-477db7bdba8a // indirect github.com/tal-tech/torm v0.0.0-20200806135310-06840940369a github.com/tal-tech/xredis v0.0.0-20200806132427-7807ee6297d9 - github.com/tal-tech/xtools v0.0.0-20200807105038-f5e7d6202665 + github.com/tal-tech/xtools v0.0.0-20200827070525-4842d161be6a + github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect + github.com/tjfoc/gmsm v1.3.0 // indirect github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07 // indirect github.com/toolkits/nux v0.0.0-20191107142017-8ddcb501004c // indirect github.com/toolkits/slice v0.0.0-20141116085117-e44a80af2484 // indirect github.com/toolkits/sys v0.0.0-20170615103026-1f33b217ffaf // indirect - github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect + github.com/xtaci/kcp-go v5.4.20+incompatible // indirect + github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect go.opencensus.io v0.22.3 // indirect - golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect - golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect )