Search in sources :

Example 1 with ServicesResponse

use of com.tencent.polaris.api.rpc.ServicesResponse in project polaris-java by polarismesh.

the class GetServicesTest method testRoundTrip.

@Test
public void testRoundTrip() {
    Configuration configuration = TestUtils.configWithEnvAddress();
    try (ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
        for (int i = 0; i < 5; i++) {
            namingServer.getNamingService().addService(new ServiceKey(NAMESPACE_TEST, "get_services_test_" + i));
        }
        ServicesResponse response = consumerAPI.getServices(GetServicesRequest.builder().namespace(NAMESPACE_TEST).build());
        Assert.assertFalse(CollectionUtils.isEmpty(response.getServices()));
        Assert.assertEquals(5, response.getServices().size());
    }
}
Also used : Configuration(com.tencent.polaris.api.config.Configuration) ServicesResponse(com.tencent.polaris.api.rpc.ServicesResponse) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) Test(org.junit.Test)

Example 2 with ServicesResponse

use of com.tencent.polaris.api.rpc.ServicesResponse 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)

Aggregations

ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)2 ServicesResponse (com.tencent.polaris.api.rpc.ServicesResponse)2 Configuration (com.tencent.polaris.api.config.Configuration)1 ServiceInfo (com.tencent.polaris.api.pojo.ServiceInfo)1 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 GetServicesRequest (com.tencent.polaris.api.rpc.GetServicesRequest)1 InitResult (com.tencent.polaris.discovery.example.utils.ExampleUtils.InitResult)1 Test (org.junit.Test)1