com.github.fashionbrot.ribbon.ping.PingUrl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mars-ribbon Show documentation
Show all versions of mars-ribbon Show documentation
mars-ribbon-api 负载均衡工具 https://github.com/fashionbrot/mars-dynamic-config
package com.github.fashionbrot.ribbon.ping;
import com.github.fashionbrot.ribbon.constants.GlobalConstants;
import com.github.fashionbrot.ribbon.enums.SchemeEnum;
import com.github.fashionbrot.ribbon.loadbalancer.Server;
import com.github.fashionbrot.ribbon.util.HttpClientUtil;
import com.github.fashionbrot.ribbon.util.HttpResult;
import lombok.extern.slf4j.Slf4j;
/**
* @author fashionbrot
* @version 0.1.1
* @date 2019/12/8 22:45
*/
@Slf4j
public class PingUrl implements IPing {
@Override
public boolean isAlive(Server server,boolean enableLog) {
String url = server.getServer();
HttpResult httpResult;
try {
httpResult = HttpClientUtil.httpGet(url,null,null, GlobalConstants.ENCODE_UTF8,2000,2000,enableLog);
} catch (Exception e) {
if (enableLog) {
log.error("pingUrl alive error:", e.getMessage());
}
return false;
}
if (log.isDebugEnabled()){
log.debug("isAlive url:{} result:{}",url,httpResult.toString());
}
if (httpResult.isSuccess()){
return true;
}
return false;
}
}