Search in sources :

Example 6 with InitResult

use of com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult in project polaris-java by polarismesh.

the class GetOneInstanceExample 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);
        GetOneInstanceRequest getOneInstanceRequest = new GetOneInstanceRequest();
        getOneInstanceRequest.setNamespace(namespace);
        getOneInstanceRequest.setService(service);
        InstancesResponse oneInstance = consumerAPI.getOneInstance(getOneInstanceRequest);
        Instance[] instances = oneInstance.getInstances();
        System.out.println("instances count is " + instances.length);
        Instance targetInstance = instances[0];
        System.out.printf("target instance is %s:%d%n", targetInstance.getHost(), targetInstance.getPort());
    }
}
Also used : InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) Instance(com.tencent.polaris.api.pojo.Instance) GetOneInstanceRequest(com.tencent.polaris.api.rpc.GetOneInstanceRequest) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) InstancesResponse(com.tencent.polaris.api.rpc.InstancesResponse)

Aggregations

InitResult (com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult)6 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)3 ProviderAPI (com.tencent.polaris.api.core.ProviderAPI)3 InstancesResponse (com.tencent.polaris.api.rpc.InstancesResponse)2 Instance (com.tencent.polaris.api.pojo.Instance)1 ServiceInfo (com.tencent.polaris.api.pojo.ServiceInfo)1 GetAllInstancesRequest (com.tencent.polaris.api.rpc.GetAllInstancesRequest)1 GetOneInstanceRequest (com.tencent.polaris.api.rpc.GetOneInstanceRequest)1 GetServicesRequest (com.tencent.polaris.api.rpc.GetServicesRequest)1 InstanceDeregisterRequest (com.tencent.polaris.api.rpc.InstanceDeregisterRequest)1 InstanceHeartbeatRequest (com.tencent.polaris.api.rpc.InstanceHeartbeatRequest)1 InstanceRegisterRequest (com.tencent.polaris.api.rpc.InstanceRegisterRequest)1 InstanceRegisterResponse (com.tencent.polaris.api.rpc.InstanceRegisterResponse)1 ServicesResponse (com.tencent.polaris.api.rpc.ServicesResponse)1