Reputation: 95
how I can do in order to return 503 server error response code when my api is under maintenance?
Upvotes: 1
Views: 3391
Reputation: 849
Usually microservices tend to have a API gateway where you implement solutions such parsing some header token and inserting new headers , rate limiting , checks like if a user is administrator or not etc
You can use https://spring.io/projects/spring-cloud-gateway which is used build API gateway based on spring stack
I believe you can use this to temporarily shutdown certain routes and also configure different errors
Upvotes: 1
Reputation: 1200
Assuming your Spring Boot web service is down completely for maintenance, then its best not to do it at the Spring Boot level. Perhaps its better to come up with a solution in by which you can swap out the server for something else that returns the 503.
Heres a very simple example:
api.myservice.com
Note: Domains records have a Time To Live so note that the above example is just something to give you an idea. You'll have to take the timing into consideration. An actual solution is hard to recommend when we don't have your environment details or context.
The point I'm trying to make is that perhaps Spring Boot is usually not the place to do this.
Upvotes: 1