@PostConstruct @Scheduled(fixedDelayString = "${service.registry.delay:1000}") public synchronized void schedule() { try { if (app.getApplication() != null && apiUrl != null) { app.getApplication() .forEach(moduleEntry -> sendPing(moduleEntry)); } } catch (Exception e) { logger.error("Failed to register services due to exception {}", e.getMessage(), e); } }
@Override public void register(ServerData[] data) { try { final String hostname = Optional.ofNullable(customHostname) .orElse(InetAddress.getLocalHost() .getHostName()); application = new Application( Stream.of(data) .map(next -> new RegisterEntry( next.getPort(), hostname, next.getModule().getContext(), next.getModule().getContext(), null, targetEndpoint, externalPort(next))) .collect(Collectors.toList())); logger.info("Registered application {} ", application); } catch (UnknownHostException e) { throw ExceptionSoftener.throwSoftenedException(e); } }
@Test public void testRegister() { ServerData data1 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); ServerData data2 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); ServerData data3 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); List<ServerData> datas = Arrays.asList(data1, data2, data3); applicationRegister = new ApplicationRegisterImpl(); ServerData[] dataArray = new ServerData[datas.size()]; applicationRegister.register(datas.toArray(dataArray)); applicationRegister.getApplication().forEach(it -> count++); assertThat(count, is(3)); } }
@Override public void register(ServerData[] data) { try { final String hostname = Optional.ofNullable(customHostname) .orElse(InetAddress.getLocalHost() .getHostName()); application = new Application( Stream.of(data) .map(next -> new RegisterEntry( next.getPort(), hostname, next.getModule().getContext(), next.getModule().getContext(), null, targetEndpoint, externalPort(next))) .collect(Collectors.toList())); logger.info("Registered application {} ", application); } catch (UnknownHostException e) { throw ExceptionSoftener.throwSoftenedException(e); } }
@PostConstruct @Scheduled(fixedDelayString = "${service.registry.delay:1000}") public synchronized void schedule() { try { if (app.getApplication() != null && apiUrl != null) { app.getApplication() .forEach(moduleEntry -> sendPing(moduleEntry)); } } catch (Exception e) { logger.error("Failed to register services due to exception {}", e.getMessage(), e); } }