use of org.apache.ignite.client.ClientAddressFinder in project ignite by apache.
the class ThinClientPartitionAwarenessDiscoveryTest method getClientConfigurationWithDiscovery.
/**
* Provide ClientConfiguration with addrResolver that find all alive nodes.
*/
private ClientConfiguration getClientConfigurationWithDiscovery(int... excludeIdx) {
Set<Integer> exclude = Arrays.stream(excludeIdx).boxed().collect(Collectors.toSet());
ClientAddressFinder addrFinder = () -> IgnitionEx.allGrids().stream().map(node -> {
int port = (Integer) node.cluster().localNode().attributes().get(CLIENT_LISTENER_PORT);
if (exclude.contains(port - DFLT_PORT))
return null;
return "127.0.0.1:" + port;
}).filter(Objects::nonNull).toArray(String[]::new);
return new ClientConfiguration().setAddressesFinder(addrFinder).setPartitionAwarenessEnabled(true);
}
use of org.apache.ignite.client.ClientAddressFinder in project ignite by apache.
the class JavaThinClient method clientAddressFinder.
void clientAddressFinder() throws Exception {
// tag::client-address-finder[]
ClientAddressFinder finder = () -> {
String[] dynamicServerAddresses = fetchServerAddresses();
return dynamicServerAddresses;
};
ClientConfiguration cfg = new ClientConfiguration().setAddressesFinder(finder).setPartitionAwarenessEnabled(true);
try (IgniteClient client = Ignition.startClient(cfg)) {
ClientCache<Integer, String> cache = client.cache("myCache");
// Put, get, or remove data from the cache...
} catch (ClientException e) {
System.err.println(e.getMessage());
}
// end::client-address-finder[]
}
Aggregations