- int interval = 5;
- while (null == microServiceFullInfo && retry < 20) {
- log.info("Holmes Service Registration. Retry: " + retry++);
-
- Response response = target.queryParam("createOrUpdate", true)
- .request(MediaType.APPLICATION_JSON)
- .post(Entity.entity(msinfo, MediaType.APPLICATION_JSON));
-
- if (response != null) {
- String ret = response.readEntity(String.class);
- int statusCode = response.getStatus();
- log.info(String.format("=========MSB REG=========\nStatus Code: %d\nInformation: %s", statusCode, ret));
- if (HttpStatus.isSuccess(statusCode)) {
- microServiceFullInfo = GsonUtil.jsonToBean(ret, MicroServiceFullInfo.class);
+ while (null == microServiceFullInfo && retry < totalRetryTimes) {
+ try {
+ log.info("Holmes Service Registration. Times: " + ++retry);
+ int time = interval * retry;
+ microServiceFullInfo = client
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .queryParam("createOrUpdate", true)
+ .post(String.format("%s://%s:%s/api/microservices/v1/services",
+ isHttpsEnabled ? PROTOCOL_HTTPS : PROTOCOL_HTTP, msbAddrInfo[0], msbAddrInfo[1]),
+ Entity.entity(msinfo, MediaType.APPLICATION_JSON),
+ MicroServiceFullInfo.class);
+
+ if (null == microServiceFullInfo) {
+ log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", time));
+ threadSleep(TimeUnit.SECONDS.toSeconds(time));
+ } else {
+ log.info("Registration succeeded!");
+ break;