Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 1.08 KB

service_instruction.md

File metadata and controls

58 lines (43 loc) · 1.08 KB

Use service discovery

registry service

import(
	...
	
	"github.com/huajiao-tv/gokeeper/client/discovery"
)

...

instance := discovery.NewInstance(discovery.GenRandomId(), "demo.test.com", map[string]string{discoverry.SchemaHttp: "127.0.0.1:17000"})
instance.Id = "test_id_1"

client := discovery.New(
  //gokeeper server address(grpc address)
  "127.0.0.1:7001",
  //registry service
  discovery.WithRegistry(instance),
  discovery.WithRegistryTTL(60*time.Second),
	//schedule strategy,default:random
  discovery.WithScheduler(map[string]schedule.Scheduler{
    "demo.test.com": schedule.NewRoundRobinScheduler(),
  }),
)

discovery service

import(
	...
	
	"github.com/huajiao-tv/gokeeper/client/discovery"
)

...


//start gokeeper client
client := discoverry.New(
  //gokeeper server address(grpc address)
  "127.0.0.1:7001",
  //subscribe a group of service
	discovery.WithDiscovery("example_client1", []string{"demo.test.com"}),
)

...

//get service address
addr, err := client.GetServiceAddr("demo.test.com", discovery.SchemaHttp)
if err != nil{
  ...
}