All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hengboy.job.schedule.runnable.MicroJobRegistryScheduleHeartRunnable Maven / Gradle / Ivy

The newest version!
/*
 *    Copyright [2019] [恒宇少年 - 于起宇]
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.github.hengboy.job.schedule.runnable;

import com.alibaba.fastjson.JSON;
import com.github.hengboy.job.core.http.MicroJobRestTemplate;
import com.github.hengboy.job.core.http.RestUrlConstants;
import com.github.hengboy.job.core.http.RestUrlTools;
import com.github.hengboy.job.core.http.model.request.InstanceInfo;
import com.github.hengboy.job.schedule.resource.MicroJobScheduleResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;

/**
 * 调度器与注册中心的心跳通讯
 *
 * @author:恒宇少年 - 于起宇
 * 

* DateTime:2019-01-30 11:09 * Blog:http://blog.yuqiyu.com * WebSite:http://www.jianshu.com/u/092df3f77bca * Gitee:https://gitee.com/hengboy * GitHub:https://github.com/hengyuboy */ public class MicroJobRegistryScheduleHeartRunnable implements Runnable { /** * logger instance */ static Logger logger = LoggerFactory.getLogger(MicroJobRegistryScheduleHeartRunnable.class); @Override public void run() { try { // 实例对象 InstanceInfo scheduleInstance = InstanceInfo.builder().instanceType(InstanceInfo.InstanceType.SCHEDULE).ipAddress(MicroJobScheduleResource.getIpAddress()).httpPort(MicroJobScheduleResource.getPort()).instanceStatus(InstanceInfo.InstanceStatus.UP).loadBalanceWeight(MicroJobScheduleResource.getScheduleLbWeight()).build(); MicroJobRestTemplate restTemplate = MicroJobScheduleResource.getRestTemplate(); // 格式化心跳检查http路径 String sendHeartUrl = RestUrlTools.formatter(MicroJobScheduleResource.getRegistryIpAddress(), MicroJobScheduleResource.getRegistryPort(), RestUrlConstants.REGISTRY_HEART_BEAT_FULL_URL); // 发送心跳检查请求 restTemplate.postJsonEntity(sendHeartUrl, JSON.toJSONString(scheduleInstance), HttpHeaders.EMPTY, Void.class); } catch (Exception e) { logger.error("Mission registry heart rate check failed", e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy