使用SDK
准备Polaris服务端
需要预先安装好Polaris服务端,安装方式可参考:单机版安装 (opens new window)或者集群版安装 (opens new window)
Polaris SDK会提供拉取全量服务实例的接口,用户可以通过服务名来进行服务发现。
拉取全量服务实例
Polaris SDK提供GetAllInstances
接口,供用户进行单个服务下全量服务实例拉取。
- Java语言
GetAllInstancesRequest allInstancesRequest = new GetAllInstancesRequest();
allInstancesRequest.setNamespace("Test");
allInstancesRequest.setService("FooService");
InstancesResponse instancesResponse = consumer.getAllInstance(allInstancesRequest);
详细使用逻辑可以参考polaris-java服务发现 (opens new window)
- Go语言
getAllRequest := &api.GetAllInstancesRequest{}
getAllRequest.Namespace = "Test"
getAllRequest.Service = "FooService"
allInstResp, err := consumer.GetAllInstances(getAllRequest)
详细使用逻辑可以参考polaris-go服务发现 (opens new window)
- C++语言
polaris::ServiceKey service_key = {"Test", "FooService"};
polaris::GetInstancesRequest request(service_key);
polaris::InstancesResponse* response = NULL;
polaris::ReturnCode ret = consumer->GetAllInstances(request, response);
详细使用逻辑可以参考polaris-cpp服务发现 (opens new window)