Skip to content

Commit

Permalink
Add websocket broker health indicator (ls1intum#2626)
Browse files Browse the repository at this point in the history
* Add Websocket Broker Health indicator.

* Add ip addresses as additional info for health indicator.

Co-authored-by: Stephan Krusche <[email protected]>
  • Loading branch information
sleiss and Stephan Krusche authored Jan 3, 2021
1 parent f68dc0a commit 0cebedd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
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();
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/app/admin/health/health.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h2>
</td>
</tr>
<tr>
<td>Websocket Connection</td>
<td>Websocket Connection (Client -> Server)</td>
<td class="text-center">
<jhi-connection-status></jhi-connection-status>
</td>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/i18n/de/health.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"continuousIntegrationServer": "Kontinuierlicher Integrationsserver",
"versionControlServer": "Versionskontrollserver",
"userManagement": "Nutzerverwaltung",
"hazelcast": "Hazelcast"
"hazelcast": "Hazelcast",
"websocketBroker": "Websocket Broker (Server -> Broker)"
},
"table": {
"service": "Dienst Name",
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/i18n/en/health.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"continuousIntegrationServer": "Continuous Integration Server",
"versionControlServer": "Version Control Server",
"userManagement": "User Management",
"hazelcast": "Hazelcast"
"hazelcast": "Hazelcast",
"websocketBroker": "Websocket Broker (Server -> Broker)"
},
"table": {
"service": "Service name",
Expand Down

0 comments on commit 0cebedd

Please sign in to comment.