use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.
the class GetAllInstancesExample method main.
public static void main(String[] args) throws Exception {
InitResult initResult = ExampleUtils.initConsumerConfiguration(args, false);
String namespace = initResult.getNamespace();
String service = initResult.getService();
try (ConsumerAPI consumerAPI = ExampleUtils.createConsumerAPI(initResult.getConfig())) {
System.out.println("namespace " + namespace + ", service " + service);
GetAllInstancesRequest allInstancesRequest = new GetAllInstancesRequest();
allInstancesRequest.setNamespace(namespace);
allInstancesRequest.setService(service);
InstancesResponse instancesResponse = consumerAPI.getAllInstance(allInstancesRequest);
System.out.println("instances count is " + instancesResponse.getInstances().length);
}
}
use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.
the class GetServicesExample method main.
public static void main(String[] args) throws Exception {
InitResult initResult = ExampleUtils.initConsumerConfiguration(args, true);
String namespace = initResult.getNamespace();
try (ConsumerAPI consumerAPI = ExampleUtils.createConsumerAPI(initResult.getConfig())) {
System.out.println("namespace " + namespace);
GetServicesRequest request = new GetServicesRequest();
request.setNamespace(namespace);
ServicesResponse response = consumerAPI.getServices(request);
List<ServiceInfo> services = response.getServices();
System.out.println("services count is " + services.size());
System.out.println("print all service " + services);
request = new GetServicesRequest();
request.setNamespace(namespace);
response = consumerAPI.getServices(request);
services = response.getServices();
System.out.println("services count is " + services.size());
System.out.println("print all service " + services);
}
}
use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.
the class DeregisterExample method main.
public static void main(String[] args) throws Exception {
InitResult initResult = ExampleUtils.initProviderConfiguration(args);
String namespace = initResult.getNamespace();
String service = initResult.getService();
String host = initResult.getHost();
int port = initResult.getPort();
String token = initResult.getToken();
try (ProviderAPI providerAPI = ExampleUtils.createProviderAPI(initResult.getConfig())) {
InstanceDeregisterRequest instanceDeregisterRequest = new InstanceDeregisterRequest();
instanceDeregisterRequest.setNamespace(namespace);
instanceDeregisterRequest.setService(service);
instanceDeregisterRequest.setHost(host);
instanceDeregisterRequest.setPort(port);
instanceDeregisterRequest.setToken(token);
providerAPI.deRegister(instanceDeregisterRequest);
System.out.println("deregister for service successfully: " + service);
}
}
use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.
the class HeartbeatExample method main.
public static void main(String[] args) throws Exception {
InitResult initResult = ExampleUtils.initProviderConfiguration(args);
String namespace = initResult.getNamespace();
String service = initResult.getService();
String host = initResult.getHost();
int port = initResult.getPort();
String token = initResult.getToken();
try (ProviderAPI providerAPI = ExampleUtils.createProviderAPI(initResult.getConfig())) {
InstanceHeartbeatRequest instanceHeartbeatRequest = new InstanceHeartbeatRequest();
instanceHeartbeatRequest.setNamespace(namespace);
instanceHeartbeatRequest.setService(service);
instanceHeartbeatRequest.setHost(host);
instanceHeartbeatRequest.setPort(port);
instanceHeartbeatRequest.setToken(token);
providerAPI.heartbeat(instanceHeartbeatRequest);
System.out.println("heartbeat for service successfully: " + service);
}
}
use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.
the class RegisterExample method main.
public static void main(String[] args) throws Exception {
InitResult initResult = ExampleUtils.initProviderConfiguration(args);
String namespace = initResult.getNamespace();
String service = initResult.getService();
String host = initResult.getHost();
int port = initResult.getPort();
String token = initResult.getToken();
try (ProviderAPI providerAPI = ExampleUtils.createProviderAPI(initResult.getConfig())) {
InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest();
instanceRegisterRequest.setNamespace(namespace);
instanceRegisterRequest.setService(service);
instanceRegisterRequest.setHost(host);
instanceRegisterRequest.setPort(port);
instanceRegisterRequest.setToken(token);
if (initResult.getTtl() > 0) {
instanceRegisterRequest.setTtl(initResult.getTtl());
}
InstanceRegisterResponse instanceRegisterResponse = providerAPI.register(instanceRegisterRequest);
System.out.println("response after register is " + instanceRegisterResponse);
}
}
Aggregations