45 lines
866 B
Plaintext
45 lines
866 B
Plaintext
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/micro/plugins/v5/client/http"
|
|
"github.com/micro/plugins/v5/registry/consul"
|
|
"go-micro.dev/v5/client"
|
|
"go-micro.dev/v5/registry"
|
|
"go-micro.dev/v5/selector"
|
|
)
|
|
|
|
func callAPI(s selector.Selector) {
|
|
my := http.NewClient(
|
|
client.Selector(s),
|
|
client.ContentType("application/json"),
|
|
)
|
|
|
|
req := my.NewRequest("hello", `/v1/hello`, map[string]string{})
|
|
var resp map[string]interface{}
|
|
if err := my.Call(context.Background(), req, &resp); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println(resp)
|
|
}
|
|
|
|
func main() {
|
|
consulReg := consul.NewRegistry(
|
|
registry.Addrs("127.0.0.1:8500"),
|
|
)
|
|
|
|
mySelector := selector.NewSelector(
|
|
selector.Registry(consulReg),
|
|
selector.SetStrategy(selector.RoundRobin),
|
|
)
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
callAPI(mySelector)
|
|
time.Sleep(10 * time.Microsecond)
|
|
}
|
|
}
|