客户端实现初步
This commit is contained in:
parent
8c55b99b7e
commit
86eaafa004
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/micro/plugins/v5/registry/consul"
|
"github.com/micro/plugins/v5/registry/consul"
|
||||||
"go-micro.dev/v5/registry"
|
"go-micro.dev/v5/registry"
|
||||||
|
|
@ -21,6 +23,8 @@ func main() {
|
||||||
service := web.NewService(
|
service := web.NewService(
|
||||||
web.Name("hello"),
|
web.Name("hello"),
|
||||||
web.Handler(ginRouter),
|
web.Handler(ginRouter),
|
||||||
|
web.RegisterTTL(time.Second*5),
|
||||||
|
web.RegisterInterval(time.Second),
|
||||||
web.Address(":8080"),
|
web.Address(":8080"),
|
||||||
web.Registry(consulReg),
|
web.Registry(consulReg),
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue