use of com.tencent.polaris.api.rpc.WatchServiceRequest in project polaris-java by polarismesh.
the class WatchServiceExample method main.
public static void main(String[] args) throws Exception {
ExampleUtils.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);
WatchServiceRequest request = WatchServiceRequest.builder().namespace(namespace).service(service).listeners(Collections.singletonList(new ServiceWatcher())).build();
request.setNamespace(namespace);
WatchServiceResponse response = consumerAPI.watchService(request);
List<Instance> instances = response.getResponse().toServiceInstances().getInstances();
System.out.println("instance count is " + instances.size());
System.out.println("print all instance " + instances);
new CountDownLatch(1).await();
}
}
use of com.tencent.polaris.api.rpc.WatchServiceRequest in project polaris-java-agent by polarismesh.
the class PolarisOperator method watchService.
public boolean watchService(String service, ServiceListener listener) {
WatchServiceRequest watchServiceRequest = new WatchServiceRequest();
watchServiceRequest.setNamespace(polarisConfig.getNamespace());
watchServiceRequest.setService(service);
watchServiceRequest.setListeners(Collections.singletonList(listener));
return consumerAPI.watchService(watchServiceRequest).isSuccess();
}
Aggregations