Search in sources :

Example 1 with SimpleHttpResponse

use of com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse in project Sentinel by alibaba.

the class SimpleHttpHeartbeatSender method sendHeartbeat.

@Override
public boolean sendHeartbeat() throws Exception {
    if (TransportConfig.getRuntimePort() <= 0) {
        RecordLog.info("[SimpleHttpHeartbeatSender] Command server port not initialized, won't send heartbeat");
        return false;
    }
    Endpoint addrInfo = getAvailableAddress();
    if (addrInfo == null) {
        return false;
    }
    SimpleHttpRequest request = new SimpleHttpRequest(addrInfo, TransportConfig.getHeartbeatApiPath());
    request.setParams(heartBeat.generateCurrentMessage());
    try {
        SimpleHttpResponse response = httpClient.post(request);
        if (response.getStatusCode() == OK_STATUS) {
            return true;
        } else if (clientErrorCode(response.getStatusCode()) || serverErrorCode(response.getStatusCode())) {
            RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addrInfo + ", http status code: " + response.getStatusCode());
        }
    } catch (Exception e) {
        RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addrInfo, e);
    }
    return false;
}
Also used : Endpoint(com.alibaba.csp.sentinel.transport.endpoint.Endpoint) SimpleHttpRequest(com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest) SimpleHttpResponse(com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse)

Aggregations

Endpoint (com.alibaba.csp.sentinel.transport.endpoint.Endpoint)1 SimpleHttpRequest (com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest)1 SimpleHttpResponse (com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse)1