客户端实现初步

This commit is contained in:
suguo.yao 2024-08-24 21:02:16 +08:00
parent 8c55b99b7e
commit 86eaafa004
3 changed files with 36 additions and 0 deletions

32
webClient.go Normal file
View File

@ -0,0 +1,32 @@
package main
import (
"fmt"
"log"
"time"
"github.com/micro/plugins/v5/registry/consul"
"go-micro.dev/v5/registry"
"go-micro.dev/v5/selector"
)
func main() {
consulReg := consul.NewRegistry(
registry.Addrs("127.0.0.1:8500"),
)
srv, err := consulReg.GetService("hello")
if err != nil {
log.Fatal(err)
}
for i := 0; i < 100000; i++ {
next := selector.Random(srv)
node, err := next()
if err != nil {
log.Fatal(err)
}
fmt.Println(node.Id, node.Address)
time.Sleep(time.Second)
}
}

BIN
webService Executable file

Binary file not shown.

View File

@ -1,6 +1,8 @@
package main
import (
"time"
"github.com/gin-gonic/gin"
"github.com/micro/plugins/v5/registry/consul"
"go-micro.dev/v5/registry"
@ -21,6 +23,8 @@ func main() {
service := web.NewService(
web.Name("hello"),
web.Handler(ginRouter),
web.RegisterTTL(time.Second*5),
web.RegisterInterval(time.Second),
web.Address(":8080"),
web.Registry(consulReg),
)