使用SDK
准备Polaris服务端
需要预先安装好Polaris服务端,安装方式可参考:单机版安装 (opens new window)或者集群版安装 (opens new window)
Polaris SDK只提供服务实例注册以及反注册的接口,注册实例时,服务端会自动创建不存在的服务。
注册服务实例
Polaris SDK提供Register
接口,供用户进行服务实例注册。
- Java语言
InstanceRegisterRequest registerRequest = new InstanceRegisterRequest();
registerRequest.setNamespace("Test");
registerRequest.setService("FooService");
registerRequest.setHost("127.0.0.1");
registerRequest.setPort(8888);
InstanceRegisterResponse registerResp = provider.register(registerRequest);
详细使用逻辑可以参考polaris-java快速入门 (opens new window)
- Go语言
registerRequest := &api.InstanceRegisterRequest{}
registerRequest.Service = "FooService"
registerRequest.Namespace = "Test"
registerRequest.Host = "127.0.0.1"
registerRequest.Port = 8888
resp, err := provider.Register(registerRequest)
详细使用逻辑可以参考polaris-go快速入门 (opens new window)
- C++语言
polaris::InstanceRegisterRequest register_req("Test", "FooService", service_token, "127.0.0.1", 8888);
std::string instance_id;
ret = provider->Register(register_req, instance_id);
详细使用逻辑可以参考polaris-cpp快速入门 (opens new window)
反注册服务实例
Polaris SDK提供Deregister
接口,供用户进行服务实例反注册。
- Java语言
InstanceDeregisterRequest deregisterRequest = new InstanceDeregisterRequest();
deregisterRequest.setNamespace("Test");
deregisterRequest.setService("FooService");
deregisterRequest.setHost("127.0.0.1");
deregisterRequest.setPort(8888);
providerAPI.deRegister(deregisterRequest);
详细使用逻辑可以参考polaris-java快速入门 (opens new window)
- Go语言
deregisterRequest := &api.InstanceDeRegisterRequest{}
deregisterRequest.Service = "FooService"
deregisterRequest.Namespace = "Test"
deregisterRequest.Host = "127.0.0.1"
deregisterRequest.Port = 8888
err = provider.Deregister(deregisterRequest)
详细使用逻辑可以参考polaris-go快速入门 (opens new window)
- C++语言
polaris::InstanceDeregisterRequest deregister_req(service_token, instance_id);
ret = provider->Deregister(deregister_req);
详细使用逻辑可以参考polaris-cpp快速入门 (opens new window)