or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

command-center.mdheartbeat.mdhttp-client.mdindex.md
tile.json

tessl/maven-com-alibaba-csp--sentinel-transport-simple-http

Simple HTTP transport module for Sentinel providing basic HTTP communication capabilities for heartbeat and command transport

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.alibaba.csp/sentinel-transport-simple-http@1.8.x

To install, run

npx @tessl/cli install tessl/maven-com-alibaba-csp--sentinel-transport-simple-http@1.8.0

index.mddocs/

Sentinel Transport Simple HTTP

Sentinel Transport Simple HTTP provides basic HTTP transport capabilities for the Alibaba Sentinel resilience framework. It enables Sentinel instances to communicate with dashboard servers through HTTP-based command centers and heartbeat mechanisms, supporting cluster coordination, monitoring, and management operations.

Package Information

  • Package Name: sentinel-transport-simple-http
  • Package Type: Maven
  • Language: Java
  • GroupId: com.alibaba.csp
  • ArtifactId: sentinel-transport-simple-http
  • Installation: Add dependency to pom.xml:
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-transport-simple-http</artifactId>
    <version>1.8.8</version>
</dependency>

Core Imports

import com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter;
import com.alibaba.csp.sentinel.transport.heartbeat.SimpleHttpHeartbeatSender;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse;
import com.alibaba.csp.sentinel.transport.endpoint.Endpoint;
import com.alibaba.csp.sentinel.transport.endpoint.Protocol;

Basic Usage

import com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter;
import com.alibaba.csp.sentinel.transport.heartbeat.SimpleHttpHeartbeatSender;
import com.alibaba.csp.sentinel.transport.CommandCenter;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient;
import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest;
import com.alibaba.csp.sentinel.transport.endpoint.Endpoint;
import com.alibaba.csp.sentinel.transport.endpoint.Protocol;

// Start HTTP command center
CommandCenter commandCenter = new SimpleHttpCommandCenter();
commandCenter.beforeStart(); // Register command handlers
commandCenter.start();       // Start HTTP server

// Send heartbeat to dashboard
HeartbeatSender heartbeatSender = new SimpleHttpHeartbeatSender();
boolean success = heartbeatSender.sendHeartbeat();

// Make HTTP requests
SimpleHttpClient client = new SimpleHttpClient();
Endpoint endpoint = new Endpoint(Protocol.HTTP, "dashboard.example.com", 8080);
SimpleHttpRequest request = new SimpleHttpRequest(endpoint, "/api/heartbeat");
request.addParam("app", "my-app");

SimpleHttpResponse response = client.post(request);
System.out.println("Status: " + response.getStatusCode());
System.out.println("Body: " + response.getBodyAsString());

Architecture

The simple HTTP transport module is organized around several key components:

  • Command Center: HTTP server that receives and processes dashboard commands for configuration updates and monitoring
  • Heartbeat System: Client that periodically sends application status to dashboard servers for health monitoring
  • HTTP Client: Lightweight HTTP client for making requests to dashboard endpoints with form-encoded parameters
  • Message Processing: HTTP request/response parsing and command dispatch mechanisms
  • Transport Abstractions: Socket factories and protocol handling for both HTTP and HTTPS connections

Capabilities

HTTP Command Center

Command center that provides HTTP-based communication between Sentinel applications and dashboard servers. Handles incoming commands for configuration updates, monitoring queries, and control operations.

public class SimpleHttpCommandCenter implements CommandCenter {
    public void beforeStart() throws Exception;
    public void start() throws Exception;
    public void stop() throws Exception;
    public static Set<String> getCommands();
    public static CommandHandler getHandler(String commandName);
    public static void registerCommand(String commandName, CommandHandler handler);
    public static void registerCommands(Map<String, CommandHandler> handlerMap);
}

Command Center

Heartbeat Communication

System for sending periodic heartbeat messages to dashboard servers to maintain connectivity and report application status. Includes automatic failover between multiple dashboard addresses.

public class SimpleHttpHeartbeatSender implements HeartbeatSender {
    public SimpleHttpHeartbeatSender();
    public boolean sendHeartbeat() throws Exception;
    public long intervalMs();
}

public class HeartbeatMessage {
    public HeartbeatMessage();
    public HeartbeatMessage registerInformation(String key, String value);
    public Map<String, String> generateCurrentMessage();
}

Heartbeat System

HTTP Client

Lightweight, blocking HTTP client that supports GET and POST requests with form-encoded parameters. Designed for simple dashboard communication without external dependencies.

public class SimpleHttpClient {
    public SimpleHttpResponse get(SimpleHttpRequest request) throws IOException;
    public SimpleHttpResponse post(SimpleHttpRequest request) throws IOException;
}

public class SimpleHttpRequest {
    public SimpleHttpRequest(Endpoint endpoint, String requestPath);
    public SimpleHttpRequest setEndpoint(Endpoint endpoint);
    public SimpleHttpRequest setRequestPath(String requestPath);
    public SimpleHttpRequest setSoTimeout(int soTimeout);
    public SimpleHttpRequest setParams(Map<String, String> params);
    public SimpleHttpRequest setCharset(Charset charset);
    public SimpleHttpRequest addParam(String key, String value);
}

public class SimpleHttpResponse {
    public Integer getStatusCode();
    public String getStatusLine();
    public Map<String, String> getHeaders();
    public String getHeader(String key);
    public byte[] getBody();
    public String getBodyAsString();
}

HTTP Client

Common Types

// From sentinel-transport-common dependency
public interface CommandCenter {
    void beforeStart() throws Exception;
    void start() throws Exception;
    void stop() throws Exception;
}

public interface HeartbeatSender {
    boolean sendHeartbeat() throws Exception;
    long intervalMs();
}

// Command handling interfaces from sentinel-transport-common
public interface CommandHandler<R> {
    CommandResponse<R> handle(CommandRequest request);
}

public class CommandRequest {
    // Contains request parameters and metadata
}

public class CommandResponse<R> {
    // Contains response data and success status
}

// HTTP status codes
public enum StatusCode {
    OK(200, "OK"),
    BAD_REQUEST(400, "Bad Request"),
    REQUEST_TIMEOUT(408, "Request Timeout"),
    LENGTH_REQUIRED(411, "Length Required"),
    UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
    INTERNAL_SERVER_ERROR(500, "Internal Server Error");
    
    public int getCode();
    public String getDesc();
    public String toString(); // Returns "code desc" format (e.g., "200 OK")
}

// Exception for request processing errors
public class RequestException extends Exception {
    public RequestException();
    public RequestException(StatusCode statusCode, String msg);
    public StatusCode getStatusCode();
}

// Endpoint and Protocol from sentinel-transport-common
public class Endpoint {
    public Endpoint(Protocol protocol, String host, int port);
    public Protocol getProtocol();
    public void setProtocol(Protocol protocol);
    public String getHost();
    public void setHost(String host);
    public int getPort();
    public void setPort(int port);
}

public enum Protocol {
    HTTP,
    HTTPS;
    
    public String getProtocol();
}