Search in sources :

Example 1 with InitResult

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);
    }
}
Also used : InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) GetAllInstancesRequest(com.tencent.polaris.api.rpc.GetAllInstancesRequest) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) InstancesResponse(com.tencent.polaris.api.rpc.InstancesResponse)

Example 2 with InitResult

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);
    }
}
Also used : ServiceInfo(com.tencent.polaris.api.pojo.ServiceInfo) InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) ServicesResponse(com.tencent.polaris.api.rpc.ServicesResponse) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) GetServicesRequest(com.tencent.polaris.api.rpc.GetServicesRequest)

Example 3 with InitResult

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);
    }
}
Also used : ProviderAPI(com.tencent.polaris.api.core.ProviderAPI) InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) InstanceDeregisterRequest(com.tencent.polaris.api.rpc.InstanceDeregisterRequest)

Example 4 with InitResult

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);
    }
}
Also used : ProviderAPI(com.tencent.polaris.api.core.ProviderAPI) InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) InstanceHeartbeatRequest(com.tencent.polaris.api.rpc.InstanceHeartbeatRequest)

Example 5 with InitResult

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);
    }
}
Also used : ProviderAPI(com.tencent.polaris.api.core.ProviderAPI) InitResult(com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult) InstanceRegisterRequest(com.tencent.polaris.api.rpc.InstanceRegisterRequest) InstanceRegisterResponse(com.tencent.polaris.api.rpc.InstanceRegisterResponse)

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