forked from ls1intum/Artemis
-
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.
Add websocket broker health indicator (ls1intum#2626)
* Add Websocket Broker Health indicator. * Add ip addresses as additional info for health indicator. Co-authored-by: Stephan Krusche <[email protected]>
- Loading branch information
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/de/tum/in/www1/artemis/config/websocket/WebsocketBrokerHealthIndicator.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,37 @@ | ||
package de.tum.in.www1.artemis.config.websocket; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.messaging.simp.broker.BrokerAvailabilityEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
import de.tum.in.www1.artemis.service.connectors.ConnectorHealth; | ||
|
||
@Component | ||
public class WebsocketBrokerHealthIndicator implements HealthIndicator, ApplicationListener<BrokerAvailabilityEvent> { | ||
|
||
private boolean isBrokerAvailable = false; // Will be updated to true by event listener once connection is established | ||
|
||
// Split the addresses by comma | ||
@Value("#{'${spring.websocket.broker.addresses}'.split(',')}") | ||
private List<String> brokerAddresses; | ||
|
||
@Override | ||
public Health health() { | ||
Map<String, Object> additionalInformation = new HashMap<>(); | ||
additionalInformation.put("ipAddresses", brokerAddresses); | ||
return new ConnectorHealth(isBrokerAvailable, additionalInformation).asActuatorHealth(); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(BrokerAvailabilityEvent event) { | ||
// The event is fired if the broker gets (un-)available | ||
this.isBrokerAvailable = event.isBrokerAvailable(); | ||
} | ||
} |
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
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
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