diff --git a/kafka-spring-boot/boot-kafka-sample/README.md b/kafka-spring-boot/boot-kafka-sample/README.md index 34482ee7..3aa6a2da 100644 --- a/kafka-spring-boot/boot-kafka-sample/README.md +++ b/kafka-spring-boot/boot-kafka-sample/README.md @@ -4,4 +4,63 @@ This sample demonstrates sending message to topic (test_1), after listening to i test_2 topic is configured for validation and if it fails then it will be retried for 3 times and moved to deadletter queue using non blocking way +## Kafka Listener Management Endpoint + Exposed endpoint to start and stop kafka listener on demand + +### Endpoint URL +`/listeners` + +### HTTP Methods +- `GET`: Retrieve the current state of all Kafka listeners +- `POST`: Update the state (start/stop) of a specific Kafka listener + +### Request/Response Formats + +#### GET +Response Format (application/json): +```json +{ + "org.springframework.kafka.KafkaListenerEndpointContainer#0": true, + "org.springframework.kafka.KafkaListenerEndpointContainer#1": true, + "org.springframework.kafka.KafkaListenerEndpointContainer#1-retry": true, + "org.springframework.kafka.KafkaListenerEndpointContainer#1-dlt": true +} +``` +#### POST +Request Format (application/json): + +```json +{ + "containerId": "org.springframework.kafka.KafkaListenerEndpointContainer#1", + "operation": "STOP" // Allowed values: START, STOP +} +``` + +Response Format: Same as GET response + +### Example Usage + +#### Get Listeners State + +```shell +curl -X GET http://localhost:8080/listeners +``` + +#### Stop a Listener +```shell +curl -X POST http://localhost:8080/listeners \ +-H "Content-Type: application/json" \ +-d '{"containerId":"org.springframework.kafka.KafkaListenerEndpointContainer#1","operation":"STOP"}' +``` + +#### Start a Listener +```shell +curl -X POST http://localhost:8080/listeners \ +-H "Content-Type: application/json" \ +-d '{"containerId":"org.springframework.kafka.KafkaListenerEndpointContainer#1","operation":"START"}' +``` + +### Error Responses +* `400 Bad Request`: Invalid operation value or malformed request +* `404 Not Found`: Specified listener container ID not found diff --git a/kafka-spring-boot/boot-kafka-sample/src/test/java/com/example/springbootkafkasample/KafkaSampleIntegrationTest.java b/kafka-spring-boot/boot-kafka-sample/src/test/java/com/example/springbootkafkasample/KafkaSampleIntegrationTest.java index 1021f722..6ce5745c 100644 --- a/kafka-spring-boot/boot-kafka-sample/src/test/java/com/example/springbootkafkasample/KafkaSampleIntegrationTest.java +++ b/kafka-spring-boot/boot-kafka-sample/src/test/java/com/example/springbootkafkasample/KafkaSampleIntegrationTest.java @@ -162,7 +162,6 @@ void stopAndStartContainers() throws Exception { .assertThat() .hasStatusOk() .hasContentType(MediaType.APPLICATION_JSON) - .hasContentType(MediaType.APPLICATION_JSON) .bodyJson() .isEqualTo(expectedJson.formatted(false)); this.mockMvcTester @@ -174,7 +173,6 @@ void stopAndStartContainers() throws Exception { .assertThat() .hasStatusOk() .hasContentType(MediaType.APPLICATION_JSON) - .hasContentType(MediaType.APPLICATION_JSON) .bodyJson() .isEqualTo(expectedJson.formatted(true)); }