-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
In case you have clustered admin servers, you can now specify multiple urls for the client to register at. So that in the case the first server is down it will register at the next one specified in the list. This allows you to do cluster- ing without the need for a load-balanced host.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,31 +69,33 @@ private static HttpHeaders createHttpHeaders() { | |
* @return true if successful | ||
*/ | ||
public boolean register() { | ||
Application self = null; | ||
try { | ||
self = createApplication(); | ||
|
||
@SuppressWarnings("rawtypes") | ||
ResponseEntity<Map> response = template.postForEntity(admin.getAdminUrl(), | ||
new HttpEntity<Application>(self, HTTP_HEADERS), Map.class); | ||
|
||
if (response.getStatusCode().equals(HttpStatus.CREATED)) { | ||
if (registeredId.get() == null) { | ||
if (registeredId.compareAndSet(null, response.getBody().get("id").toString())) { | ||
LOGGER.info("Application registered itself as {}", response.getBody()); | ||
return true; | ||
Application self = createApplication(); | ||
|
||
for (String adminUrl : admin.getAdminUrl()) { | ||
try { | ||
@SuppressWarnings("rawtypes") | ||
ResponseEntity<Map> response = template.postForEntity(adminUrl, | ||
new HttpEntity<Application>(self, HTTP_HEADERS), Map.class); | ||
|
||
if (response.getStatusCode().equals(HttpStatus.CREATED)) { | ||
if (registeredId.get() == null) { | ||
if (registeredId.compareAndSet(null, | ||
response.getBody().get("id").toString())) { | ||
LOGGER.info("Application registered itself as {}", response.getBody()); | ||
return true; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mikexliu
|
||
} | ||
} | ||
} | ||
|
||
LOGGER.debug("Application refreshed itself as {}", response.getBody()); | ||
return true; | ||
} else { | ||
LOGGER.warn("Application failed to registered itself as {}. Response: {}", self, | ||
response.toString()); | ||
LOGGER.debug("Application refreshed itself as {}", response.getBody()); | ||
return true; | ||
} else { | ||
LOGGER.warn("Application failed to registered itself as {}. Response: {}", self, | ||
response.toString()); | ||
} | ||
} catch (Exception ex) { | ||
LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", | ||
self, admin.getAdminUrl(), ex.getMessage()); | ||
} | ||
} catch (Exception ex) { | ||
LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", self, | ||
admin.getAdminUrl(), ex.getMessage()); | ||
} | ||
|
||
return false; | ||
|
@@ -102,13 +104,16 @@ public boolean register() { | |
public void deregister() { | ||
String id = registeredId.get(); | ||
if (id != null) { | ||
try { | ||
template.delete(admin.getAdminUrl() + "/" + id); | ||
registeredId.set(null); | ||
} catch (Exception ex) { | ||
LOGGER.warn( | ||
"Failed to deregister application (id={}) at spring-boot-admin ({}): {}", | ||
id, admin.getAdminUrl(), ex.getMessage()); | ||
for (String adminUrl : admin.getAdminUrl()) { | ||
try { | ||
template.delete(adminUrl + "/" + id); | ||
registeredId.set(null); | ||
return; | ||
} catch (Exception ex) { | ||
LOGGER.warn( | ||
"Failed to deregister application (id={}) at spring-boot-admin ({}): {}", | ||
id, adminUrl, ex.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
|
@joshiste
Is there any reason it can only register to only one server?