use of com.tencent.polaris.api.rpc.GetAllInstancesRequest 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);
}
}
use of com.tencent.polaris.api.rpc.GetAllInstancesRequest in project sofa-rpc by sofastack.
the class PolarisWatcher method watchService.
private void watchService() {
try {
GetAllInstancesRequest getAllInstancesRequest = new GetAllInstancesRequest();
getAllInstancesRequest.setNamespace(nameSpace);
getAllInstancesRequest.setService(serviceName);
Map<String, String> parameters = new HashMap<>();
parameters.put("protocol", protocol);
getAllInstancesRequest.setMetadata(parameters);
InstancesResponse response = consumerAPI.getAllInstance(getAllInstancesRequest);
this.currentData = response;
ProviderGroup providerGroup = new ProviderGroup(currentProviders());
listeners.stream().filter(Objects::nonNull).forEach(l -> l.updateProviders(providerGroup));
} catch (Exception e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_WATCH_HEALTH, "Polaris"), e);
}
}
use of com.tencent.polaris.api.rpc.GetAllInstancesRequest in project sofa-rpc by sofastack.
the class PolarisRegistryTest method testRegister.
@Test
public void testRegister() {
polaris.getNamingService().addService(new ServiceKey(NAMESPACE, SERVICE));
// register
ProviderConfig<?> providerConfig = providerConfig("polaris-test-1", 12200, 12201, 12202);
registry.register(providerConfig);
// check register
ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPI();
GetAllInstancesRequest getAllInstancesRequest = new GetAllInstancesRequest();
getAllInstancesRequest.setNamespace(APPNAME);
getAllInstancesRequest.setService(SERVICE);
InstancesResponse allInstance = consumerAPI.getAllInstance(getAllInstancesRequest);
Assert.assertEquals(3, allInstance.getInstances().length);
// unregister
registry.unRegister(providerConfig);
// check unregister ,sleep to wait remove catch
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// if no service will throw a exception
try {
consumerAPI.getAllInstance(getAllInstancesRequest);
} catch (PolarisException e) {
Assert.assertEquals(SERVER_USER_ERROR, e.getCode());
}
}
use of com.tencent.polaris.api.rpc.GetAllInstancesRequest in project polaris-java-agent by polarismesh.
the class PolarisDiscoveryHandler method getInstances.
/**
* Return all instances for the given service.
*
* @param service serviceName
* @return 服务实例列表
*/
public InstancesResponse getInstances(String service) {
LogUtils.logInvoke(this, "getInstances");
PolarisAgentProperties polarisAgentProperties = PolarisAgentPropertiesFactory.getPolarisAgentProperties();
String namespace = polarisAgentProperties.getNamespace();
GetAllInstancesRequest request = new GetAllInstancesRequest();
request.setNamespace(namespace);
request.setService(service);
return consumerAPI.getAllInstance(request);
}
use of com.tencent.polaris.api.rpc.GetAllInstancesRequest in project spring-cloud-tencent by Tencent.
the class PolarisDiscoveryHandler method getInstances.
/**
* Return all instances for the given service.
* @param service serviceName
* @return list of instances
*/
public InstancesResponse getInstances(String service) {
String namespace = polarisDiscoveryProperties.getNamespace();
GetAllInstancesRequest request = new GetAllInstancesRequest();
request.setNamespace(namespace);
request.setService(service);
return polarisConsumer.getAllInstance(request);
}
Aggregations