registry

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2020 License: Apache-2.0 Imports: 2 Imported by: 11

README

gRPC服务发现

使用google.golang.org/grpc/resolver实现服务发现

使用

默认mock未实现,需要import _ github.com/hb-go/grpc-contrib/registry/micro_ github.com/hb-go/grpc-contrib/registry/istio

go-micro默认使用mdns

// 服务注册与注销
registry.Register(&_ExampleService_serviceDesc, opts...)
registry.Deregister(&_ExampleService_serviceDesc, opts...)
registry.Deregister(nil)

// 服务发现
target := registry.NewTarget(&_ExampleService_serviceDesc, opts...)
conn, err := grpc.Dial(target, grpc.WithInsecure(), grpc.WithBalancerName(roundrobin.Name), grpc.WithBlock())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRegistry = NewRegistry()
)

Functions

func Deregister

func Deregister(sd *grpc.ServiceDesc, opts ...Option)

func NewTarget

func NewTarget(sd *grpc.ServiceDesc, opts ...Option) string

func Register

func Register(sd *grpc.ServiceDesc, opts ...Option) error

Types

type Option

type Option func(options *Options)

func WithAddr

func WithAddr(addr string) Option

func WithVersion

func WithVersion(version string) Option

type Options

type Options struct {
	Version string
	Addr    string
}

type Registry

type Registry interface {
	// 生成grpc.Dial target
	NewTarget(sd *grpc.ServiceDesc, opts ...Option) string

	// 注册服务
	Register(sd *grpc.ServiceDesc, opts ...Option) error
	// 注销服务
	// sd=nil,注销全部服务
	Deregister(sd *grpc.ServiceDesc, opts ...Option)
}

func NewRegistry

func NewRegistry() Registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL