or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

index.mddocs/

0

# Sentinel Transport Simple HTTP

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: sentinel-transport-simple-http

7

- **Package Type**: Maven

8

- **Language**: Java

9

- **GroupId**: com.alibaba.csp

10

- **ArtifactId**: sentinel-transport-simple-http

11

- **Installation**: Add dependency to `pom.xml`:

12

13

```xml

14

<dependency>

15

<groupId>com.alibaba.csp</groupId>

16

<artifactId>sentinel-transport-simple-http</artifactId>

17

<version>1.8.8</version>

18

</dependency>

19

```

20

21

## Core Imports

22

23

```java

24

import com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter;

25

import com.alibaba.csp.sentinel.transport.heartbeat.SimpleHttpHeartbeatSender;

26

import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient;

27

import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest;

28

import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpResponse;

29

import com.alibaba.csp.sentinel.transport.endpoint.Endpoint;

30

import com.alibaba.csp.sentinel.transport.endpoint.Protocol;

31

```

32

33

## Basic Usage

34

35

```java

36

import com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter;

37

import com.alibaba.csp.sentinel.transport.heartbeat.SimpleHttpHeartbeatSender;

38

import com.alibaba.csp.sentinel.transport.CommandCenter;

39

import com.alibaba.csp.sentinel.transport.HeartbeatSender;

40

import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient;

41

import com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpRequest;

42

import com.alibaba.csp.sentinel.transport.endpoint.Endpoint;

43

import com.alibaba.csp.sentinel.transport.endpoint.Protocol;

44

45

// Start HTTP command center

46

CommandCenter commandCenter = new SimpleHttpCommandCenter();

47

commandCenter.beforeStart(); // Register command handlers

48

commandCenter.start(); // Start HTTP server

49

50

// Send heartbeat to dashboard

51

HeartbeatSender heartbeatSender = new SimpleHttpHeartbeatSender();

52

boolean success = heartbeatSender.sendHeartbeat();

53

54

// Make HTTP requests

55

SimpleHttpClient client = new SimpleHttpClient();

56

Endpoint endpoint = new Endpoint(Protocol.HTTP, "dashboard.example.com", 8080);

57

SimpleHttpRequest request = new SimpleHttpRequest(endpoint, "/api/heartbeat");

58

request.addParam("app", "my-app");

59

60

SimpleHttpResponse response = client.post(request);

61

System.out.println("Status: " + response.getStatusCode());

62

System.out.println("Body: " + response.getBodyAsString());

63

```

64

65

## Architecture

66

67

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

68

69

- **Command Center**: HTTP server that receives and processes dashboard commands for configuration updates and monitoring

70

- **Heartbeat System**: Client that periodically sends application status to dashboard servers for health monitoring

71

- **HTTP Client**: Lightweight HTTP client for making requests to dashboard endpoints with form-encoded parameters

72

- **Message Processing**: HTTP request/response parsing and command dispatch mechanisms

73

- **Transport Abstractions**: Socket factories and protocol handling for both HTTP and HTTPS connections

74

75

## Capabilities

76

77

### HTTP Command Center

78

79

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

80

81

```java { .api }

82

public class SimpleHttpCommandCenter implements CommandCenter {

83

public void beforeStart() throws Exception;

84

public void start() throws Exception;

85

public void stop() throws Exception;

86

public static Set<String> getCommands();

87

public static CommandHandler getHandler(String commandName);

88

public static void registerCommand(String commandName, CommandHandler handler);

89

public static void registerCommands(Map<String, CommandHandler> handlerMap);

90

}

91

```

92

93

[Command Center](./command-center.md)

94

95

### Heartbeat Communication

96

97

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

98

99

```java { .api }

100

public class SimpleHttpHeartbeatSender implements HeartbeatSender {

101

public SimpleHttpHeartbeatSender();

102

public boolean sendHeartbeat() throws Exception;

103

public long intervalMs();

104

}

105

106

public class HeartbeatMessage {

107

public HeartbeatMessage();

108

public HeartbeatMessage registerInformation(String key, String value);

109

public Map<String, String> generateCurrentMessage();

110

}

111

```

112

113

[Heartbeat System](./heartbeat.md)

114

115

### HTTP Client

116

117

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

118

119

```java { .api }

120

public class SimpleHttpClient {

121

public SimpleHttpResponse get(SimpleHttpRequest request) throws IOException;

122

public SimpleHttpResponse post(SimpleHttpRequest request) throws IOException;

123

}

124

125

public class SimpleHttpRequest {

126

public SimpleHttpRequest(Endpoint endpoint, String requestPath);

127

public SimpleHttpRequest setEndpoint(Endpoint endpoint);

128

public SimpleHttpRequest setRequestPath(String requestPath);

129

public SimpleHttpRequest setSoTimeout(int soTimeout);

130

public SimpleHttpRequest setParams(Map<String, String> params);

131

public SimpleHttpRequest setCharset(Charset charset);

132

public SimpleHttpRequest addParam(String key, String value);

133

}

134

135

public class SimpleHttpResponse {

136

public Integer getStatusCode();

137

public String getStatusLine();

138

public Map<String, String> getHeaders();

139

public String getHeader(String key);

140

public byte[] getBody();

141

public String getBodyAsString();

142

}

143

```

144

145

[HTTP Client](./http-client.md)

146

147

## Common Types

148

149

```java { .api }

150

// From sentinel-transport-common dependency

151

public interface CommandCenter {

152

void beforeStart() throws Exception;

153

void start() throws Exception;

154

void stop() throws Exception;

155

}

156

157

public interface HeartbeatSender {

158

boolean sendHeartbeat() throws Exception;

159

long intervalMs();

160

}

161

162

// Command handling interfaces from sentinel-transport-common

163

public interface CommandHandler<R> {

164

CommandResponse<R> handle(CommandRequest request);

165

}

166

167

public class CommandRequest {

168

// Contains request parameters and metadata

169

}

170

171

public class CommandResponse<R> {

172

// Contains response data and success status

173

}

174

175

// HTTP status codes

176

public enum StatusCode {

177

OK(200, "OK"),

178

BAD_REQUEST(400, "Bad Request"),

179

REQUEST_TIMEOUT(408, "Request Timeout"),

180

LENGTH_REQUIRED(411, "Length Required"),

181

UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),

182

INTERNAL_SERVER_ERROR(500, "Internal Server Error");

183

184

public int getCode();

185

public String getDesc();

186

public String toString(); // Returns "code desc" format (e.g., "200 OK")

187

}

188

189

// Exception for request processing errors

190

public class RequestException extends Exception {

191

public RequestException();

192

public RequestException(StatusCode statusCode, String msg);

193

public StatusCode getStatusCode();

194

}

195

196

// Endpoint and Protocol from sentinel-transport-common

197

public class Endpoint {

198

public Endpoint(Protocol protocol, String host, int port);

199

public Protocol getProtocol();

200

public void setProtocol(Protocol protocol);

201

public String getHost();

202

public void setHost(String host);

203

public int getPort();

204

public void setPort(int port);

205

}

206

207

public enum Protocol {

208

HTTP,

209

HTTPS;

210

211

public String getProtocol();

212

}

213

```