register

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

README

Quick Start

Prerequisites:

Download the module:

go get -u github.com/hewenyu/zero-contrib/zrpc/registry/nacos

fix config

Addr: nacos-cs.ops.svc.cluster.local
Port: 8848
Group: DEFAULT_GROUP
DataID: demo-api
ExtDataIDs:
  - mysql
  - auth
NamespaceID: demo

For example:

Service

  • main.go
import _ "github.com/hewenyu/zero-contrib/zrpc/registry/nacos"

func main() {
flag.Parse()

var c config.Config
conf.MustLoad(*configFile, &c)

server := zrpc.MustNewServer(c.RpcServerConf, func (grpcServer *grpc.Server) {

})
// register service to nacos
sc := []constant.ServerConfig{
*constant.NewServerConfig("192.168.100.15", 8848),
}

cc := &constant.ClientConfig{
NamespaceId:         "public",
TimeoutMs:           5000,
NotLoadCacheAtStart: true,
LogDir:              "/tmp/nacos/log",
CacheDir:            "/tmp/nacos/cache",
RotateTime:          "1h",
MaxAge:              3,
LogLevel:            "debug",
}

opts := nacos.NewNacosConfig("nacos.rpc", c.ListenOn, sc, cc)
_ = nacos.RegisterService(opts)
server.Start()
}

Client

  • main.go
import _ "github.com/hewenyu/zero-contrib/zrpc/registry/nacos"
  • etc/*.yaml
# nacos://[user:passwd]@host/service?param=value'
Target: nacos://192.168.100.15:8848/nacos.rpc?namespaceid=public&timeout=5000s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatcher

func NewWatcher(ctx context.Context, cancel context.CancelFunc, out chan<- []string) *watcher

func PopulateEndpoints

func PopulateEndpoints(ctx context.Context, clientConn resolver.ClientConn, input <-chan []string)

func RegisterService

func RegisterService(opts *Options) error

RegisterService register service to nacos

func UpdateState

func UpdateState(clientConn resolver.ClientConn, addresses []string)

Types

type ByAddressString

type ByAddressString []resolver.Address

ByAddressString sorts resolver.Address by Address Field sorting in increasing order.

func (ByAddressString) Len

func (p ByAddressString) Len() int

func (ByAddressString) Less

func (p ByAddressString) Less(i, j int) bool

func (ByAddressString) Swap

func (p ByAddressString) Swap(i, j int)

type Option

type Option func(*Options)

func WithCluster

func WithCluster(cluster string) Option

func WithGroup

func WithGroup(group string) Option

func WithMetadata

func WithMetadata(metadata map[string]string) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithWeight

func WithWeight(weight float64) Option

type Options

type Options struct {
	ListenOn    string
	ServiceName string
	Prefix      string
	Weight      float64
	Cluster     string
	Group       string
	Metadata    map[string]string

	ServerConfig []constant.ServerConfig
	ClientConfig *constant.ClientConfig
}

options

func NewNacosConfig

func NewNacosConfig(serviceName, listenOn string, sc []constant.ServerConfig, cc *constant.ClientConfig, opts ...Option) *Options

Jump to

Keyboard shortcuts

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