From 9d18e57ec03cd211f051b8eb552eb10f1d48da66 Mon Sep 17 00:00:00 2001 From: Mike Weber Date: Tue, 7 Dec 2021 13:17:08 -0500 Subject: [PATCH] Added health check --- .../health/ConnectionFactoryHealthCheck.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 runtime/src/main/java/org/amqphub/quarkus/qpid/jms/runtime/health/ConnectionFactoryHealthCheck.java diff --git a/runtime/src/main/java/org/amqphub/quarkus/qpid/jms/runtime/health/ConnectionFactoryHealthCheck.java b/runtime/src/main/java/org/amqphub/quarkus/qpid/jms/runtime/health/ConnectionFactoryHealthCheck.java new file mode 100644 index 0000000..328f7a2 --- /dev/null +++ b/runtime/src/main/java/org/amqphub/quarkus/qpid/jms/runtime/health/ConnectionFactoryHealthCheck.java @@ -0,0 +1,45 @@ +/* +* Copyright 2021 the original author or authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.amqphub.quarkus.qpid.jms.runtime.health; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; + +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponseBuilder; +import org.eclipse.microprofile.health.Readiness; + +@Readiness +@ApplicationScoped +public class ConnectionFactoryHealthCheck implements HealthCheck { + + @Inject + ConnectionFactory connectionFactory; + + @Override + public HealthCheckResponse call() { + HealthCheckResponseBuilder builder = HealthCheckResponse.named("Qpid JMS health check"); + try (Connection connection = connectionFactory.createConnection()) { + builder.up(); + } catch (Exception e) { + builder.down(); + } + return builder.build(); + } +} \ No newline at end of file