@Override public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) { RegCheck regCheck = null; try{ /** * Deal with health check script */ String rawScript = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT); if (rawScript != null && !rawScript.trim().isEmpty()) { Long healthCheckScriptIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT_INTERVAL_SECONDS)); String healthCheckScript = rawScript.replaceAll(HEALTH_SCRIPT_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress()) .replaceAll(HEALTH_SCRIPT_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort())); regCheck = Registration.RegCheck.args(Arrays.asList(healthCheckScript.split(" ")), healthCheckScriptIntervalSeconds); } }catch(Exception e){ logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e); } return regCheck; }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, String args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(Collections.singletonList(args), interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, List<String> args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(args, interval); register(port, check, name, id, tags, meta); }