All Projects → jihor → hiatus-spring-boot

jihor / hiatus-spring-boot

Licence: GPL-3.0 license
No description or website provided.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to hiatus-spring-boot

node-graceful-shutdown
Gracefully shutdown your modular NodeJS application.
Stars: ✭ 20 (-13.04%)
Mutual labels:  shutdown, graceful-shutdown
neo4j-java-driver-spring-boot-starter
Automatic configuration of Neo4j's Java Driver for Spring Boot applications
Stars: ✭ 33 (+43.48%)
Mutual labels:  spring-boot-starter
Qubes-scripts
Scripts that help with administration and usage of Qubes OS
Stars: ✭ 33 (+43.48%)
Mutual labels:  shutdown
honeymon-spring-boot-starter
Simple Spring Boot Starter and Summary
Stars: ✭ 20 (-13.04%)
Mutual labels:  spring-boot-starter
localstack-spring-boot-starter
SpringBoot Starter for Localstack
Stars: ✭ 38 (+65.22%)
Mutual labels:  spring-boot-starter
infinispan-spring-boot
Infinispan Spring Boot starter. Use this starter in your Spring Boot applications to help you use Infinispan+Spring integration in embedded and client/server mode
Stars: ✭ 61 (+165.22%)
Mutual labels:  spring-boot-starter
busy
Busy is a mouse movement simulator. It stops your system from going to sleep / idling and makes sure that you keep getting those notifications while you take that well deserved break.
Stars: ✭ 15 (-34.78%)
Mutual labels:  shutdown
Raspberry-Pi-Dashboard
Web-based dashboard interface to inspect Raspberry Pi hardware and software with no extra software required.
Stars: ✭ 131 (+469.57%)
Mutual labels:  shutdown
cxf-spring-boot-starter
Enterprise & production ready SOAP webservices powered by Spring Boot & Apache CXF
Stars: ✭ 129 (+460.87%)
Mutual labels:  spring-boot-starter
memcached-spring-boot
Library that provides support for auto-configuration of Memcached cache in a Spring Boot application.
Stars: ✭ 68 (+195.65%)
Mutual labels:  spring-boot-starter
shiro-pac4j-spring-boot-starter
pac4j + shiro
Stars: ✭ 14 (-39.13%)
Mutual labels:  spring-boot-starter
ControlBlockService2
This is the driver for the ControlBlock re.v 2.X, a power switch and input/output/gameapd gadget for the Raspberry Pi
Stars: ✭ 18 (-21.74%)
Mutual labels:  shutdown
python-graceful-shutdown
Example of a Python code that implements graceful shutdown while using asyncio, threading and multiprocessing
Stars: ✭ 109 (+373.91%)
Mutual labels:  graceful-shutdown
weixin-sdk
www.docs4dev.com/
Stars: ✭ 19 (-17.39%)
Mutual labels:  spring-boot-starter
kms
🔪 Is a library that aids in graceful shutdown of a process/application
Stars: ✭ 44 (+91.3%)
Mutual labels:  graceful-shutdown
fine
🧹 Gracefully shutdown Node.js application: help you handle exit signals and cleanup
Stars: ✭ 20 (-13.04%)
Mutual labels:  shutdown
faucet-pipeline-spring-boot-starter
faucet-pipeline for Spring Boot
Stars: ✭ 17 (-26.09%)
Mutual labels:  spring-boot-starter
xbox360-controller-manager
Turn OFF your wireless xbox 360 controller on PC and see the battery status of the connected controllers.
Stars: ✭ 38 (+65.22%)
Mutual labels:  shutdown
qynat-spring-boot-starter
A springboot-starter that can achieve Intranet penetration. 一款可以实现内网穿透的springboot-starter。
Stars: ✭ 65 (+182.61%)
Mutual labels:  spring-boot-starter
waitabit
😴 A tiny library for handling system interrupts
Stars: ✭ 38 (+65.22%)
Mutual labels:  shutdown

Hiatus for Spring Boot

A Spring Boot 2 starter for graceful work interruption or shutdown.

Download CircleCI
Current version is written for Spring Boot 2. Older versions of this starter (0.x and 1.0) are written for Spring Boot 1.x and have different paths, see previous readme versions.

What is Hiatus for Spring Boot?

Hiatus for Spring Boot is a starter that allows a Spring Boot application to... go on hiatus :) i.e. return an 'OUT OF SERVICE' result in respond to a health check, while allowing in-flight requests to complete, and also provides a way to keep score of these requests. The basic use cases are as follows:

A. Graceful shutdown

  1. Tell the service instance to go on hiatus (invoke /actuator/hiatus-on). If you are behind HAProxy / Nginx / any other decent load balancer or discovery server that checks your /actuator/health endpoint, this means the load balancer will cease sending new requests to this service (or the discovery server will mark this instance as "down". Anyway, the instance will be taken out of load balancing).
  2. Wait until the count of in-flight requests reaches zero.
  3. Now the instance can be restarted with no requests in danger.

B. Hiatus

  1. Same as in (A)
  2. When it's time to put the service back to work, invoke /actuator/hiatus-off. Service will then be taken back to load balancing

Spring Boot already has /actuator/shutdown, why not use it?

/actuator/shutdown destroys the whole Spring context, leading to failed requests. The goal of this starter is to allow such operations without interfering with the application context, relying on load balancing only.

Download

Gradle
repositories {
    jcenter()
}

dependencies {
    compile group: 'ru.jihor.hiatus-spring-boot', name: 'hiatus-spring-boot-starter', version: '<version>'
    // or
    // compile 'ru.jihor.hiatus-spring-boot:hiatus-spring-boot-starter:<version>'
}
Maven
<dependency>
    <groupId>ru.jihor.hiatus-spring-boot</groupId>
    <artifactId>hiatus-spring-boot-starter</artifactId>
    <version>(version)</version>
    <type>pom</type>
</dependency>

API Description

REST API

The following REST API is available when using hiatus-spring-boot-starter:

  • /actuator/hiatus-on, method = POST - go on hiatus

    Returns:

    • true if the service is gone on hiatus as result of this request, false if it's already on hiatus
  • /actuator/hiatus-off, method = POST - go back to work

    Returns:

    • true if the service is resuming work as result of this request, false if it's already working normally
  • /actuator/hiatus, method = GET - the health indicator which provides the information on the service state and the count of requests in processing

    Returns:

    • json like { "paused": true, "count": 0 } which provides the info on whether the system is paused and the count of requests in processing. Returns HTTP status 200 if working normally, 503 if on hiatus.

Java API

UnitOfWork annotation

If this method-level annotation is present on a method, the counter of requests in processing will be incremented before the method invocation and decremented after exit.

Example:

@RestController
public class DemoController {
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @UnitOfWork
    public String doWork() throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        return "Done";
    }
}

Demo project

  1. Clone the repo and start DemoApplication.
  2. curl the /actuator/health endpoint
$ curl -i http://127.0.0.1:8080/actuator/health
HTTP/1.1 200                                              
...
{"status":"UP","diskSpace":{"status":"UP","total":999,"free":997,"threshold":1},"hiatus":{"status":"UP","paused":false,"count":0}}
  1. curl the /actuator/hiatus endpoint
$ curl -i http://127.0.0.1:8080/actuator/hiatus
HTTP/1.1 200 
...
{"paused":false,"count":0}
  1. curl the /test endpoint a couple times without waiting for them to return
$ curl -i http://127.0.0.1:8080/test > /dev/null 2>&1 &
[4] 21112
$ curl -i http://127.0.0.1:8080/test > /dev/null 2>&1 &
[5] 21114
$ curl -i http://127.0.0.1:8080/test > /dev/null 2>&1 &
[6] 21116
  1. curl the /actuator/hiatus endpoint again and see in-flight requests:
$ curl -i http://127.0.0.1:8080/actuator/hiatus
HTTP/1.1 200 
...
{"paused":false,"count":3}
  1. curl the /actuator/hiatus-on endpoint with a POST:
$ curl -X POST http://127.0.0.1:8080/actuator/hiatus-on
true
  1. curl the /actuator/health endpoint again. Now it returns code 503:
$ curl -i http://127.0.0.1:8080/actuator/health
HTTP/1.1 503                                              
...
{"status":"OUT_OF_SERVICE","diskSpace":{"status":"UP","total":999,"free":997,"threshold":1},"hiatus":{"status":"OUT_OF_SERVICE","paused":true,"count":3}}
  1. curl the /actuator/hiatus endpoint again. Now it also returns code 503:
$ curl -i http://127.0.0.1:8080/actuator/hiatus
HTTP/1.1 503 
...
{"paused":true,"count":3}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].