Skip to content

Commit 7784027

Browse files
committed
fixes #11 update the kafka-sidecar streams-health to add unregister
1 parent f3f240f commit 7784027

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/concern/kafka-sidecar/streams-health.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
When operating a Kafka sidecar that runs Kafka Streams applications, it is crucial to monitor the health of these streams. The `SidecarHealthHandler` provides a health check endpoint that verifies if all registered Kafka Streams instances are in `RUNNING` or `REBALANCING` state.
44

5-
## Registering Kafka Streams
5+
## Registering and Unregistering Kafka Streams
66

7-
To enable health monitoring for your Kafka Streams application, you must verify that your streams instance is registered with the `KafkaStreamsRegistry`.
7+
To enable health monitoring for your Kafka Streams application, you must verify that your streams instance is registered with the `KafkaStreamsRegistry`. You should also unregister it when the application shuts down.
88

99
### Usage
1010

@@ -24,6 +24,18 @@ KafkaStreamsRegistry.register("my-streams-app", streams);
2424

2525
The `SidecarHealthHandler` will automatically discover all registered streams and include them in the health check. If any registered stream is not in a healthy state, the health check endpoint will return `ERROR` (status 500 equivalent logic, though specifically returning a string).
2626

27+
To prevent the health check from returning an error during a graceful server shutdown, you should unregister the stream instance in your application's shutdown hook or `close()` method:
28+
29+
```java
30+
// ... inside shutdown hook or LightStreams close() loop ...
31+
32+
if (streams != null) {
33+
streams.close();
34+
}
35+
// Unregister the streams instance
36+
KafkaStreamsRegistry.unregister("my-streams-app");
37+
```
38+
2739
### Example
2840

2941
Here is an example from `WordCountStreams`:
@@ -40,6 +52,14 @@ Here is an example from `WordCountStreams`:
4052
KafkaStreamsRegistry.register("WordCountStreams", wordCountStreams);
4153
}
4254

55+
@Override
56+
public void close() {
57+
if (wordCountStreams != null) {
58+
wordCountStreams.close();
59+
}
60+
// Unregistration
61+
KafkaStreamsRegistry.unregister("WordCountStreams");
62+
}
4363
```
4464

4565
## Example Applications
@@ -64,4 +84,5 @@ Both examples show how to:
6484
- Configure the Kafka Streams application using `KafkaStreamsConfig`.
6585
- Start the `KafkaStreams` instance.
6686
- Register the instance with `KafkaStreamsRegistry` to enable health monitoring via `SidecarHealthHandler`.
87+
- Unregister the instance during the application shutdown lifecycle using `KafkaStreamsRegistry.unregister()` to cleanly handle server shutdown.
6788

0 commit comments

Comments
 (0)