gf/contrib/registry/zookeeper
2023-03-08 14:12:51 +08:00
..
go.mod feature/v2.3.0 (#2296) 2023-01-09 14:43:10 +08:00
go.sum feature/v2.3.0 (#2296) 2023-01-09 14:43:10 +08:00
README.MD version v2.3.0 (#2392) 2023-01-11 19:19:41 +08:00
zookeeper_discovery.go add package contrib/rpc/grpcx (#2169) 2023-03-08 14:12:51 +08:00
zookeeper_func.go add zookeeper registry support (#2284) 2022-11-18 14:07:17 +08:00
zookeeper_registrar.go add zookeeper registry support (#2284) 2022-11-18 14:07:17 +08:00
zookeeper_watcher.go add package contrib/rpc/grpcx (#2169) 2023-03-08 14:12:51 +08:00
zookeeper_z_test.go add zookeeper registry support (#2284) 2022-11-18 14:07:17 +08:00
zookeeper.go add package contrib/rpc/grpcx (#2169) 2023-03-08 14:12:51 +08:00

GoFrame Etcd Registry

Use zookeeper as service registration and discovery management.

Installation

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

suggested using go.mod:

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

import (
	"github.com/gogf/gf/contrib/registry/zookeeper/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/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/gogf/gf/contrib/registry/zookeeper/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/gsel"
	"github.com/gogf/gf/v2/net/gsvc"
	"github.com/gogf/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.