Files
mtusi2026lab5/src/main/java/com/example/mtusi_messenger/controller/HealthController.java
T
2026-11-18 20:33:27 +03:00

33 lines
1.2 KiB
Java

package com.example.mtusi_messenger.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.mtusi_messenger.dto.HealthResponse;
import com.example.mtusi_messenger.exception.ApiExceptions;
import com.example.mtusi_messenger.service.ReadinessService;
@RestController
public class HealthController {
private final ReadinessService readiness;
public HealthController(ReadinessService readiness) {
this.readiness = readiness;
}
@GetMapping("/health/live")
public ResponseEntity<HealthResponse> live() {
return ResponseEntity.ok(new HealthResponse("ok"));
}
@GetMapping("/health/ready")
public ResponseEntity<HealthResponse> ready() {
// Always probe dependencies, even after a failure, so a restored schema
// can move this process back to ACCEPTING_TRAFFIC without a restart.
if (!readiness.probeDependencies() || !readiness.acceptsBusinessTraffic()) {
throw ApiExceptions.unavailable("Application is not accepting traffic");
}
return ResponseEntity.ok(new HealthResponse("ok"));
}
}