generated from telekom/reuse-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: alternative approach on handling graceful shutdown and prestop …
…hook
- Loading branch information
Showing
5 changed files
with
126 additions
and
26 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/de/telekom/horizon/pulsar/ApplicationShutdownListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.telekom.horizon.pulsar; | ||
|
||
import de.telekom.horizon.pulsar.actuator.StopActiveConnectionsEvent; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ApplicationShutdownListener implements ApplicationListener<ContextClosedEvent> { | ||
|
||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
public ApplicationShutdownListener(ApplicationEventPublisher applicationEventPublisher) { | ||
this.applicationEventPublisher = applicationEventPublisher; | ||
} | ||
|
||
/* | ||
Will execute even before any @PreStop invocation | ||
*/ | ||
@Override | ||
public void onApplicationEvent(ContextClosedEvent event) { | ||
var message = "Got PreStop request. Terminating all connections..."; | ||
|
||
applicationEventPublisher.publishEvent(new StopActiveConnectionsEvent(this, message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 18 additions & 18 deletions
36
.../pulsar/actuator/HorizonPreStopEvent.java → .../actuator/StopActiveConnectionsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// Copyright 2024 Deutsche Telekom IT GmbH | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package de.telekom.horizon.pulsar.actuator; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
public class HorizonPreStopEvent extends ApplicationEvent { | ||
private String message; | ||
|
||
public HorizonPreStopEvent(Object source, String message) { | ||
super(source); | ||
this.message = message; | ||
} | ||
public String getMessage() { | ||
return message; | ||
} | ||
// Copyright 2024 Deutsche Telekom IT GmbH | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package de.telekom.horizon.pulsar.actuator; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
public class StopActiveConnectionsEvent extends ApplicationEvent { | ||
private String message; | ||
|
||
public StopActiveConnectionsEvent(Object source, String message) { | ||
super(source); | ||
this.message = message; | ||
} | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/de/telekom/horizon/pulsar/config/PodConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.telekom.horizon.pulsar.config; | ||
|
||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Configuration | ||
public class PodConfig { | ||
|
||
@Value("${pod.ip}") | ||
private String podIp; | ||
|
||
@Value("${pod.namespace}") | ||
private String podNamespace; | ||
|
||
@Value("${pod.service-name}") | ||
private String serviceName; | ||
} |