or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

base-sse-servlet.mdconfiguration-streaming.mdindex.mdlegacy-metrics-polling.mdmetrics-streaming.mdrequest-events-streaming.mdutilization-streaming.md

request-events-streaming.mddocs/

0

# Request Events Streaming

1

2

Servlet that streams individual Hystrix request events as they occur, providing detailed information about each request execution including events, latencies, and collapser information.

3

4

## Capabilities

5

6

### HystrixRequestEventsSseServlet

7

8

Servlet that writes SSE JSON data every time a Hystrix request is made, providing detailed execution information.

9

10

```java { .api }

11

/**

12

* Servlet that writes SSE JSON every time a request is made

13

* Provides detailed request execution information including events and latencies

14

*/

15

public class HystrixRequestEventsSseServlet extends HystrixSampleSseServlet {

16

17

/**

18

* Default constructor using HystrixRequestEventsStream and default delay

19

*/

20

public HystrixRequestEventsSseServlet();

21

22

/**

23

* Package-private constructor for testing with custom stream and delay

24

* @param sampleStream Observable stream of request events

25

* @param pausePollerThreadDelayInMs Delay between polling cycles in milliseconds

26

*/

27

HystrixRequestEventsSseServlet(Observable<HystrixRequestEvents> sampleStream, int pausePollerThreadDelayInMs);

28

29

/**

30

* Returns maximum number of concurrent connections allowed

31

* @return Maximum concurrent connections (default: 5)

32

*/

33

protected int getMaxNumberConcurrentConnectionsAllowed();

34

35

/**

36

* Returns current number of active connections

37

* @return Current connection count

38

*/

39

protected int getNumberCurrentConnections();

40

41

/**

42

* Atomically increments and returns current concurrent connection count

43

* @return New connection count after increment

44

*/

45

protected int incrementAndGetCurrentConcurrentConnections();

46

47

/**

48

* Atomically decrements current concurrent connection count

49

*/

50

protected void decrementCurrentConcurrentConnections();

51

}

52

```

53

54

### HystrixRequestEventsJsonStream (Deprecated)

55

56

Legacy JSON stream utility for converting request events to JSON format.

57

58

```java { .api }

59

/**

60

* Stream that converts HystrixRequestEvents into JSON

61

* @deprecated Since 1.5.4 - prefer mapping serialization on HystrixRequestEventsStream.observe()

62

*/

63

@Deprecated

64

public class HystrixRequestEventsJsonStream {

65

66

/**

67

* Get the underlying request events stream

68

* @return Observable stream of request events

69

*/

70

public Observable<HystrixRequestEvents> getStream();

71

72

/**

73

* Convert collection of request events to JSON string

74

* @param requests Collection of request events to convert

75

* @return JSON string representation

76

* @throws IOException if JSON generation fails

77

*/

78

public static String convertRequestsToJson(Collection<HystrixRequestEvents> requests) throws IOException;

79

80

/**

81

* Convert single request event to JSON string

82

* @param request Request event to convert

83

* @return JSON string representation

84

* @throws IOException if JSON generation fails

85

*/

86

public static String convertRequestToJson(HystrixRequestEvents request) throws IOException;

87

88

/**

89

* Write request as JSON to a JsonGenerator

90

* @param json JsonGenerator to write to

91

* @param request Request event to write

92

* @throws IOException if JSON writing fails

93

*/

94

private static void writeRequestAsJson(JsonGenerator json, HystrixRequestEvents request) throws IOException;

95

96

/**

97

* Convert execution signature to JSON

98

* @param json JsonGenerator to write to

99

* @param executionSignature Execution signature containing command details

100

* @param latencies List of execution latencies in milliseconds

101

* @throws IOException if JSON writing fails

102

*/

103

private static void convertExecutionToJson(JsonGenerator json, HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies) throws IOException;

104

}

105

106

/**

107

* Request events types for detailed request information

108

*/

109

public interface HystrixRequestEvents.ExecutionSignature {

110

String getCommandName();

111

ExecutionResult.EventCounts getEventCounts();

112

int getCachedCount();

113

HystrixCollapserKey getCollapserKey();

114

int getCollapserBatchSize();

115

}

116

```

117

118

**Web.xml Configuration:**

119

120

```xml

121

<servlet>

122

<servlet-name>HystrixRequestEventsSseServlet</servlet-name>

123

<servlet-class>com.netflix.hystrix.contrib.requests.stream.HystrixRequestEventsSseServlet</servlet-class>

124

</servlet>

125

<servlet-mapping>

126

<servlet-name>HystrixRequestEventsSseServlet</servlet-name>

127

<url-pattern>/hystrix/requests.stream</url-pattern>

128

</servlet-mapping>

129

```

130

131

**Usage Examples:**

132

133

```java

134

// Deploy servlet via web.xml configuration

135

// Access stream endpoint

136

curl http://localhost:8080/app/hystrix/requests.stream

137

138

// Custom request events processing (using deprecated API)

139

HystrixRequestEventsJsonStream stream = new HystrixRequestEventsJsonStream();

140

stream.getStream().subscribe(requestEvents -> {

141

String json = HystrixRequestEventsJsonStream.convertRequestToJson(requestEvents);

142

System.out.println("Request event: " + json);

143

});

144

```

145

146

## Data Format

147

148

The servlet outputs detailed request execution information:

149

150

### Request Events Structure

151

152

```json

153

data: [

154

{

155

"name": "GetUser",

156

"events": [

157

"SUCCESS"

158

],

159

"latencies": [45],

160

"cached": 0

161

},

162

{

163

"name": "GetUserPreferences",

164

"events": [

165

"TIMEOUT",

166

"FALLBACK_SUCCESS"

167

],

168

"latencies": [800],

169

"cached": 0

170

},

171

{

172

"name": "GetUserProfile",

173

"events": [

174

{

175

"name": "FAILURE",

176

"count": 3

177

},

178

"FALLBACK_SUCCESS"

179

],

180

"latencies": [23, 45, 67],

181

"cached": 2,

182

"collapsed": {

183

"name": "UserDataCollapser",

184

"count": 5

185

}

186

}

187

]

188

```

189

190

### Event Types

191

192

Common Hystrix event types that appear in request events:

193

194

- `SUCCESS` - Command executed successfully

195

- `FAILURE` - Command execution failed

196

- `TIMEOUT` - Command execution timed out

197

- `SHORT_CIRCUITED` - Circuit breaker short-circuited the request

198

- `THREAD_POOL_REJECTED` - Thread pool rejected the request

199

- `SEMAPHORE_REJECTED` - Semaphore rejected the request

200

- `FALLBACK_SUCCESS` - Fallback executed successfully

201

- `FALLBACK_FAILURE` - Fallback execution failed

202

- `FALLBACK_REJECTION` - Fallback was rejected

203

- `FALLBACK_MISSING` - No fallback was implemented

204

- `EXCEPTION_THROWN` - Exception was thrown during execution

205

- `RESPONSE_FROM_CACHE` - Response served from cache

206

- `COLLAPSED` - Request was collapsed (batched)

207

- `EMIT` - Observable emitted a value

208

- `BAD_REQUEST` - Request was considered bad/invalid

209

210

### Field Descriptions

211

212

- `name` - Command name that was executed

213

- `events` - Array of events that occurred during execution (strings or objects with count)

214

- `latencies` - Array of execution latencies in milliseconds

215

- `cached` - Number of cached responses (if > 0)

216

- `collapsed` - Information about request collapsing/batching (if present)

217

- `name` - Name of the collapser that batched the request

218

- `count` - Size of the batch this request was part of

219

220

## Connection Management

221

222

Uses the same connection management pattern as other SSE servlets:

223

224

```java { .api }

225

// Configuration property for max concurrent connections

226

public static final String MAX_CONCURRENT_CONNECTIONS_PROPERTY = "hystrix.config.stream.maxConcurrentConnections";

227

public static final int DEFAULT_MAX_CONCURRENT_CONNECTIONS = 5;

228

```

229

230

## Migration from Deprecated API

231

232

```java

233

// Old approach (deprecated)

234

HystrixRequestEventsJsonStream jsonStream = new HystrixRequestEventsJsonStream();

235

jsonStream.getStream().subscribe(events -> {

236

String json = HystrixRequestEventsJsonStream.convertRequestToJson(events);

237

// process json

238

});

239

240

// New approach (recommended)

241

HystrixRequestEventsStream.getInstance()

242

.observe()

243

.map(SerialHystrixRequestEvents::toJsonString)

244

.subscribe(json -> {

245

// process json

246

});

247

```