gf/contrib/registry/nacos
2023-12-21 21:12:51 +08:00
..
go.mod version v2.6.1 (#3222) 2023-12-21 21:12:51 +08:00
go.sum Upgrade nacos sdk to latest version (#3166) 2023-11-20 20:47:00 +08:00
nacos_discovery.go add service registry implements using nacos (#2995) 2023-10-12 21:06:37 +08:00
nacos_register.go add service registry implements using nacos (#2995) 2023-10-12 21:06:37 +08:00
nacos_service.go add service registry implements using nacos (#2995) 2023-10-12 21:06:37 +08:00
nacos_watcher.go fix issue #3100 (#3106) 2023-10-30 20:27:48 +08:00
nacos_z_test.go fix issue #3100 (#3106) 2023-10-30 20:27:48 +08:00
nacos.go add service registry implements using nacos (#2995) 2023-10-12 21:06:37 +08:00
README.MD add README and example cases for nacos registry (#3075) 2023-10-23 20:04:39 +08:00

GoFrame Nacos Registry

Use nacos as service registration and discovery management.

Installation

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

suggested using go.mod:

require github.com/gogf/gf/contrib/registry/nacos/v2 latest

Example

Reference example

server

package main

import (
	"github.com/gogf/gf/contrib/registry/nacos/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(nacos.New(`127.0.0.1:8848`).
        SetClusterName("DEFAULT").
        SetGroupName("DEFAULT_GROUP"))

	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()
}

client

package main

import (
	"fmt"
	"time"

	"github.com/gogf/gf/contrib/registry/nacos/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(nacos.New(`127.0.0.1:8848`))
	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 Nacos is licensed under the MIT License, 100% free and open-source, forever.