I have a list of 5000 network devices that I need to retrieve data from an online service. The service accepts only one device each time.
I have created the following API to handle one device but I am not sure what will be the right way the fetch 5000 devices.
public Mono<String> getDeviceData(String macAddress) {
return webClient.post()
.uri("....")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(request), String.class).attributes(ServerOAuth2AuthorizedClientExchangeFilterFunction.clientRegistrationId("xxxx")).retrieve()
.bodyToMono(String.class).doOnError(e -> logger.error(e.getMessage()));
}
@Override
public void run(String... args) throws Exception {
getDeviceData("xxxx").subscribe(response -> {
try {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = mapper.readValue(response, new TypeReference<Map<String, Object>>() {
});
NetDevice device = new Device();
device.setIp(map.get("ip").toString());
} catch (JsonMappingException e) {
logger.error(e.getMessage());
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
}
});
}
Should I slice the list of devices or maybe there are other and better alternatives?
Thank you