zookeeper

package module
v2.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 12 Imported by: 0

README

GoFrame Etcd Registry

Use zookeeper as service registration and discovery management.

Installation

go get -u -v github.com/wangyougui/gf/contrib/registry/zookeeper/v2

suggested using go.mod:

require github.com/wangyougui/gf/contrib/registry/zookeeper/v2 latest
package main

import (
	"github.com/wangyougui/gf/contrib/registry/zookeeper/v2"
	"github.com/wangyougui/gf/v2/frame/g"
	"github.com/wangyougui/gf/v2/net/ghttp"
	"github.com/wangyougui/gf/v2/net/gsvc"
)

func main() {
	gsvc.SetRegistry(zookeeper.New(
		[]string{"127.0.0.1:2181"}, zookeeper.WithRootPath("/gogf"),
    ))
	
	s := g.Server(`hello.svc`)
	s.BindHandler("/", func(r *ghttp.Request) {
		g.Log().Info(r.Context(), `request received`)
		r.Response.Write(`Hello world`)
	})
	s.Run()
}
package main

import (
	"fmt"
	"time"

	"github.com/wangyougui/gf/contrib/registry/zookeeper/v2"
	"github.com/wangyougui/gf/v2/frame/g"
	"github.com/wangyougui/gf/v2/net/gsel"
	"github.com/wangyougui/gf/v2/net/gsvc"
	"github.com/wangyougui/gf/v2/os/gctx"
)

func main() {
	gsvc.SetRegistry(zookeeper.New(
		[]string{"127.0.0.1:2181"}, zookeeper.WithRootPath("/gogf"),
	))
	gsel.SetBuilder(gsel.NewBuilderRoundRobin())

	client := g.Client()
	for i := 0; i < 100; i++ {
		res, err := client.Get(gctx.New(), `http://hello.svc/`)
		if err != nil {
			panic(err)
		}
		fmt.Println(res.ReadAllString())
		res.Close()
		time.Sleep(time.Second)
	}
}

License

GoFrame zookeeper is licensed under the MIT License, 100% free and open-source, forever.

Documentation

Overview

Package zookeeper implements service Registry and Discovery using zookeeper.

Index

Constants

This section is empty.

Variables

View Source
var ErrWatcherStopped = errors.New("watcher stopped")

ErrWatcherStopped is the certain error for watcher closed.

Functions

This section is empty.

Types

type Content

type Content struct {
	Key   string
	Value string
}

Content for custom service Marshal/Unmarshal.

type Option

type Option func(o *options)

Option is etcd registry option.

func WithDigestACL

func WithDigestACL(user string, password string) Option

WithDigestACL with registry password.

func WithRootPath

func WithRootPath(path string) Option

WithRootPath with registry root path.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is consul registry

func New

func New(address []string, opts ...Option) *Registry

func (*Registry) Deregister

func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error

Deregister off-lines and removes `service` from the Registry.

func (*Registry) Register

func (r *Registry) Register(_ context.Context, service gsvc.Service) (gsvc.Service, error)

Register registers `service` to Registry. Note that it returns a new Service if it changes the input Service with custom one.

func (*Registry) Search

func (r *Registry) Search(_ context.Context, in gsvc.SearchInput) ([]gsvc.Service, error)

Search searches and returns services with specified condition.

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, key string) (gsvc.Watcher, error)

Watch watches specified condition changes. The `key` is the prefix of service key.

Jump to

Keyboard shortcuts

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