Giter Site home page Giter Site logo

maintenance-mode's Introduction

Java CI with Maven

API Maintenance Mode with Spring Boot

This project illustrates how to easily manage a maintenance mode on Spring boot based APIs

Requirements

This demo has been developed with the following piece of software:

  • OpenJDK 11.0.10
  • Spring Boot 2.5.0
  • Maven 3.8.1

How to run it

Build your application using this command:

mvn clean install

Then, run this command

java -jar ./target/maintenance-mode-0.0.1-SNAPSHOT.jar

Check that is ready:

curl -s http://localhost:8080/actuator/health/readiness 

We can see 2 live probes:

  • one relative to the database connection automatically provided by Spring
  • an other one related to an application specific maintenance flag.

By default the maintenance flag is set to false. That means that the service is ready.

There is an endpoint enabling to read and set that flag.

Let's put the service in maintenance:

curl -X 'PUT' \
  'http://localhost:8080/api/maintenance' \
  -w "\n" \
  -H 'Content-Type: text/plain' \
  -d 'true' -v

We get an HTTP 204 answer (no-content).

We can check now that our API is no longer ready:

curl -s http://localhost:8080/q/health/ready

Let's inspect the code of MaintenanceController.retreiveInMaintenance() to see how the HealthCheck probe is developed.

Let's try to read a random url:

curl -s \
  -w "\n" \
  'localhost:8080/api/random' 

We get an answer from our API:

{
  "reason": "Service currently in maintenance"
}

Let's browse the code of CheckMaintenanceFilter.java and see how this answer is provided using a good old servlet filter.

curl -X 'PUT' \
  'http://localhost:8080/api/maintenance' \
  -w "\n" \
  -H 'Content-Type: text/plain' \
  -d 'false' -v

We can now check now that our API is ready again:

curl -s http://localhost:8080/actuator/health/readiness

maintenance-mode's People

Contributors

alexandre-touret avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

rpselvamtnj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.