Миграции балансировка запросов идемпотентность graceful shutdown readines
This commit is contained in:
@@ -1,4 +1,25 @@
|
||||
package org.example.config;
|
||||
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class GracefulShutdownListener {
|
||||
|
||||
private final ReadinessState state;
|
||||
|
||||
public GracefulShutdownListener(ReadinessState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@EventListener(ContextClosedEvent.class)
|
||||
public void onClose(){
|
||||
state.setReady(false);
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
package org.example.model;
|
||||
package org.example.config;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Component
|
||||
public class ReadinessState {
|
||||
private final AtomicBoolean ready = new AtomicBoolean(true);
|
||||
public boolean isReady() {
|
||||
return ready.get();
|
||||
}
|
||||
public void setReady(boolean v) {
|
||||
ready.set(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user