Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ target/
classes


# Gopkg.lock
# vendor/

logs/
go.sum
go.mod

175 changes: 175 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/AlexStocks/goext"
version = "0.3.2"

[[constraint]]
name = "github.com/AlexStocks/log4go"
version = "1.0.1"

[[constraint]]
branch = "master"
name = "github.com/juju/errors"

[[constraint]]
branch = "master"
name = "github.com/samuel/go-zookeeper"

[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.2"

[prune]
go-tests = true
unused-packages = true
21 changes: 13 additions & 8 deletions examples/go-client/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import (
)

import (
"github.com/dubbo/dubbo-go/plugins"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"github.com/dubbo/dubbo-go/public"
"github.com/dubbo/dubbo-go/registry"
)

var (
survivalTimeout int = 10e9
clientRegistry *registry.ZkConsumerRegistry
clientRegistry registry.Registry
)

func main() {
Expand Down Expand Up @@ -54,7 +56,7 @@ func main() {

func initClient() {
var (
err error
err error
codecType public.CodecType
)

Expand All @@ -64,18 +66,20 @@ func initClient() {
}

// registry
clientRegistry, err = registry.NewZkConsumerRegistry(
registry.ApplicationConf(clientConfig.Application_Config),
registry.RegistryConf(clientConfig.Registry_Config),
registry.BalanceMode(registry.SM_RoundRobin),
registry.ServiceTTL(300e9),
clientRegistry,err = plugins.PluggableRegistries[clientConfig.Registry](
registry.WithDubboType(registry.CONSUMER),
registry.WithApplicationConf(clientConfig.Application_Config),
zookeeper.WithRegistryConf(clientConfig.ZkRegistryConfig),
registry.WithBalanceMode(registry.SM_RoundRobin),
registry.WithServiceTTL(300e9),

)
if err != nil {
panic(fmt.Sprintf("fail to init registry.Registy, err:%s", jerrors.ErrorStack(err)))
return
}
for _, service := range clientConfig.Service_List {
err = clientRegistry.Register(service)
err = clientRegistry.ConsumerRegister(service)
if err != nil {
panic(fmt.Sprintf("registry.Register(service{%#v}) = error{%v}", service, jerrors.ErrorStack(err)))
return
Expand All @@ -102,6 +106,7 @@ func initClient() {
panic(fmt.Sprintf("unknown protocol %s", clientConfig.Service_List[idx].Protocol))
}
}

}

func uninitClient() {
Expand Down
7 changes: 4 additions & 3 deletions examples/go-client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -48,7 +49,7 @@ type (
Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"`
// application
Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"`
Registry_Config registry.RegistryConfig `yaml:"registry_config" json:"registry_config,omitempty"`
ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"`
// 一个客户端只允许使用一个service的其中一个group和其中一个version
Service_List []registry.ServiceConfig `yaml:"service_list" json:"service_list,omitempty"`
}
Expand Down Expand Up @@ -81,8 +82,8 @@ func initClientConfig() error {
panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err)))
return nil
}
if clientConfig.Registry_Config.Timeout, err = time.ParseDuration(clientConfig.Registry_Config.TimeoutStr); err != nil {
panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", clientConfig.Registry_Config.TimeoutStr, err))
if clientConfig.ZkRegistryConfig.Timeout, err = time.ParseDuration(clientConfig.ZkRegistryConfig.TimeoutStr); err != nil {
panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", clientConfig.ZkRegistryConfig.TimeoutStr, err))
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions examples/go-client/app/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/dubbo/dubbo-go/registry/zookeeper"
_ "net/http/pprof"
)

Expand Down Expand Up @@ -63,6 +64,7 @@ func testJsonrpc(userKey string) {
// Attention the last parameter : []UserKey{userKey}
req = clt.NewRequest(conf, method, []string{userKey})

clientRegistry = clientRegistry.(*zookeeper.ZkRegistry)
serviceURL, err = clientRegistry.Filter(req.ServiceConfig(), 1)
if err != nil {
log.Error("registry.Filter(conf:%#v) = error:%s", req.ServiceConfig(), jerrors.ErrorStack(err))
Expand Down
2 changes: 1 addition & 1 deletion examples/go-client/profiles/dev/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ application_config:
owner : "ZX"
environment : "dev"

registry_config:
zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
2 changes: 1 addition & 1 deletion examples/go-client/profiles/release/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ application_config:
owner : "ZX"
environment : "product"

registry_config:
zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
2 changes: 1 addition & 1 deletion examples/go-client/profiles/test/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ application_config:
owner : "ZX"
environment : "test"

registry_config:
zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
Loading