Search in sources :

Example 1 with WatchServiceRequest

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();
    }
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) WatchServiceResponse(com.tencent.polaris.api.rpc.WatchServiceResponse) ExampleUtils(com.tencent.polaris.discovery.example.utils.ExampleUtils) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) CountDownLatch(java.util.concurrent.CountDownLatch) WatchServiceRequest(com.tencent.polaris.api.rpc.WatchServiceRequest)

Example 2 with WatchServiceRequest

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();
}
Also used : UnWatchServiceRequest(com.tencent.polaris.api.rpc.UnWatchServiceRequest) WatchServiceRequest(com.tencent.polaris.api.rpc.WatchServiceRequest)

Aggregations

WatchServiceRequest (com.tencent.polaris.api.rpc.WatchServiceRequest)2 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)1 Instance (com.tencent.polaris.api.pojo.Instance)1 UnWatchServiceRequest (com.tencent.polaris.api.rpc.UnWatchServiceRequest)1 WatchServiceResponse (com.tencent.polaris.api.rpc.WatchServiceResponse)1 ExampleUtils (com.tencent.polaris.discovery.example.utils.ExampleUtils)1 CountDownLatch (java.util.concurrent.CountDownLatch)1