liveBook · Manning

Availability change event

As explained in Spring in Action, Sixth Edition

An availability change event is an application event that records a change in an application's liveness or readiness state.

An availability change event records a change in an application's liveness or readiness state. Spring, a dependency, or application code can publish it through the application context. section 18.3.3

Publish different states for different operational conditions:

  • Use ReadinessState.REFUSING_TRAFFIC while initialization is incomplete, then publish ReadinessState.ACCEPTING_TRAFFIC. section 18.3.3
  • Use LivenessState.BROKEN after an unrecoverable fatal error, allowing Kubernetes to restart the application; publish LivenessState.CORRECT for a healthy state. section 18.3.3

Delay readiness during startup

An ApplicationRunner can receive the Spring application context and call AvailabilityChangeEvent.publish(context, ReadinessState.REFUSING_TRAFFIC) before initialization finishes. Afterward, publish ReadinessState.ACCEPTING_TRAFFIC so the application can accept traffic. section 18.3.3

@Bean
public ApplicationRunner disableLiveness(ApplicationContext context) {
  return args -> {
    AvailabilityChangeEvent.publish(context, ReadinessState.REFUSING_TRAFFIC);
  };
}

Shows the Spring bean and publish call used to change readiness during application startup. section 18.3.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains publication through the application context and distinguishes readiness from liveness states, without detailing event internals.
Examples
Uses startup initialization, traffic refusal or acceptance, and unrecoverable failure triggering Kubernetes restart.
What it assumes
Assumes familiarity with Spring application beans and context injection; introduces the event's operational states through examples.
What you can do after
Apply it via Spring's AvailabilityChangeEvent.publish method to control readiness and liveness states.
How it connects
Connects Spring application context, ApplicationRunner, liveness, readiness, and Kubernetes health probes.

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.