0

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

angus
  • 3,210
  • 10
  • 41
  • 71
  • I think your answer is dictated by the on-line service you are using: "_The service accepts only one device each time._" - You'll obviously need to call your method once for each device. My guess is, if this is a commercial service, they will throttle the number of requests you can make. – Randy Casburn Apr 05 '21 at 22:13
  • Thanks Randy, I am not worry about the number of times just want to have better understanding of how to do that. – angus Apr 06 '21 at 12:18

0 Answers0