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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
target/
classes


# Gopkg.lock
# vendor/

logs/
go.sum
go.mod

21 changes: 13 additions & 8 deletions examples/go-client/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"github.com/dubbo/dubbo-go/plugins"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"net/http"
_ "net/http/pprof"
"os"
Expand All @@ -25,7 +27,7 @@ import (

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
8 changes: 5 additions & 3 deletions examples/go-server/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 @@ -38,7 +39,8 @@ type (
// application
Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"`
// Registry_Address string `default:"192.168.35.3:2181"`
Registry_Config registry.RegistryConfig `yaml:"registry_config" json:"registry_config,omitempty"`
Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"`
ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"`
Service_List []registry.ServiceConfig `yaml:"service_list" json:"service_list,omitempty"`
Server_List []registry.ServerConfig `yaml:"server_list" json:"server_list,omitempty"`
}
Expand Down Expand Up @@ -75,9 +77,9 @@ func initServerConf() *ServerConfig {
panic(fmt.Sprintf("time.ParseDuration(NetTimeout:%#v) = error:%s", conf.NetTimeout, err))
return nil
}
if conf.Registry_Config.Timeout, err = time.ParseDuration(conf.Registry_Config.TimeoutStr); err != nil {
if conf.ZkRegistryConfig.Timeout, err = time.ParseDuration(conf.ZkRegistryConfig.TimeoutStr); err != nil {
panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s",
conf.Registry_Config.TimeoutStr, err))
conf.ZkRegistryConfig.TimeoutStr, err))
return nil
}

Expand Down
27 changes: 13 additions & 14 deletions examples/go-server/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package main

import (
"fmt"
"github.com/dubbo/dubbo-go/plugins"
registry2 "github.com/dubbo/dubbo-go/registry"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"strconv"
"syscall"
)

import (
// "github.com/AlexStocks/gocolor"
"github.com/AlexStocks/goext/net"
"github.com/AlexStocks/goext/time"
log "github.com/AlexStocks/log4go"
"github.com/dubbo/dubbo-go/jsonrpc"
"github.com/dubbo/dubbo-go/registry"
jerrors "github.com/juju/errors"
)

Expand Down Expand Up @@ -50,8 +48,6 @@ func main() {

func initServer() *jsonrpc.Server {
var (
err error
serverRegistry *registry.ZkProviderRegistry
srv *jsonrpc.Server
)

Expand All @@ -61,20 +57,23 @@ func initServer() *jsonrpc.Server {
}

// registry
serverRegistry, err = registry.NewZkProviderRegistry(
registry.ApplicationConf(conf.Application_Config),
registry.RegistryConf(conf.Registry_Config),
registry.BalanceMode(registry.SM_RoundRobin),
registry.ServiceTTL(conf.netTimeout),

registry, err := plugins.PluggableRegistries[conf.Registry](
registry2.WithDubboType(registry2.PROVIDER),
registry2.WithApplicationConf(conf.Application_Config),
zookeeper.WithRegistryConf(conf.ZkRegistryConfig),
//zookeeper.WithBalanceMode(registry.SM_RoundRobin),
registry2.WithServiceTTL(conf.netTimeout),
)
if err != nil || serverRegistry == nil {

if err != nil || registry == nil {
panic(fmt.Sprintf("fail to init registry.Registy, err:%s", jerrors.ErrorStack(err)))
return nil
}

// provider
srv = jsonrpc.NewServer(
jsonrpc.Registry(serverRegistry),
jsonrpc.Registry(registry),
jsonrpc.ConfList(conf.Server_List),
jsonrpc.ServiceConfList(conf.Service_List),
)
Expand Down
4 changes: 3 additions & 1 deletion examples/go-server/profiles/dev/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ application_config:
owner : "ZX"
environment : "dev"

registry_config:
registry: "zookeeper"

zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
4 changes: 3 additions & 1 deletion examples/go-server/profiles/release/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ application_config:
owner : "ZX"
environment : "product"

registry_config:
registry: "zookeeper"

zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
4 changes: 3 additions & 1 deletion examples/go-server/profiles/test/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ application_config:
owner : "ZX"
environment : "test"

registry_config:
registry: "zookeeper"

zk_registry_config:
timeout : "3s"
address:
- "127.0.0.1:2181"
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *Server) Options() Options {
func (s *Server) Handle(h Handler) error {
var (
err error
serviceConf registry.ProviderServiceConfig
serviceConf registry.ServiceConfig
)

opts := s.Options()
Expand Down Expand Up @@ -261,7 +261,7 @@ func (s *Server) Handle(h Handler) error {
}

serviceConf.Path = opts.ConfList[j].Address()
err = opts.Registry.Register(serviceConf)
err = opts.Registry.ProviderRegister(s.opts.Registry.NewProviderServiceConfig(serviceConf))
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package plugins

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

var PluggableRegistries = map[string]func(...registry.OptionInf) (registry.Registry,error){
"zookeeper":zookeeper.NewZkRegistry,
}

Loading