This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit d933b06084e5f8f92ea3b591f4c43b119e39a8bf Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jun 9 11:22:30 2020 +0200 microprofile-health extensions should create health registry and initialize it at built time. Requires Camel 3.4.0 --- .../src/main/resources/application.properties | 3 ++ .../deployment/MicroProfileHealthProcessor.java | 15 ++++++++++ .../runtime/CamelMicroProfileHealthRecorder.java | 34 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/examples/http-log/src/main/resources/application.properties b/examples/http-log/src/main/resources/application.properties index 7831c12..cde03f7 100644 --- a/examples/http-log/src/main/resources/application.properties +++ b/examples/http-log/src/main/resources/application.properties @@ -23,6 +23,9 @@ quarkus.banner.enabled = false # Quarkus - Camel # +# to turn on or off health check +quarkus.camel.health.enabled = true + # disable build time route discovery as the only # route defined in this project is based on CDI. # diff --git a/extensions/microprofile-health/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/health/deployment/MicroProfileHealthProcessor.java b/extensions/microprofile-health/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/health/deployment/MicroProfileHealthProcessor.java index 5845a3c..520f2c6 100644 --- a/extensions/microprofile-health/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/health/deployment/MicroProfileHealthProcessor.java +++ b/extensions/microprofile-health/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/health/deployment/MicroProfileHealthProcessor.java @@ -25,13 +25,17 @@ import javax.enterprise.inject.Vetoed; import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.ExecutionTime; +import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckRegistry; import org.apache.camel.health.HealthCheckRepository; import org.apache.camel.impl.health.DefaultHealthCheckRegistry; import org.apache.camel.microprofile.health.AbstractCamelMicroProfileHealthCheck; import org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig; +import org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthRecorder; import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem; import org.apache.camel.quarkus.core.deployment.util.CamelSupport; import org.eclipse.microprofile.health.Liveness; @@ -45,6 +49,8 @@ import org.jboss.jandex.IndexView; class MicroProfileHealthProcessor { + private static final DotName CAMEL_HEALTH_CHECK_REGISTRY_DOTNAME = DotName + .createSimple(HealthCheckRegistry.class.getName()); private static final DotName CAMEL_HEALTH_CHECK_DOTNAME = DotName.createSimple(HealthCheck.class.getName()); private static final DotName CAMEL_HEALTH_CHECK_REPOSITORY_DOTNAME = DotName .createSimple(HealthCheckRepository.class.getName()); @@ -58,6 +64,15 @@ class MicroProfileHealthProcessor { return new FeatureBuildItem(FEATURE); } + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + CamelBeanBuildItem metricRegistry(CamelMicroProfileHealthRecorder recorder, CamelMicroProfileHealthConfig config) { + return new CamelBeanBuildItem( + "HealthCheckRegistry", + HealthCheckRegistry.class.getName(), + recorder.createHealthCheckRegistry(config)); + } + @BuildStep List<CamelBeanBuildItem> camelHealthDiscovery( CombinedIndexBuildItem combinedIndex, diff --git a/extensions/microprofile-health/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/health/runtime/CamelMicroProfileHealthRecorder.java b/extensions/microprofile-health/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/health/runtime/CamelMicroProfileHealthRecorder.java new file mode 100644 index 0000000..01d546f --- /dev/null +++ b/extensions/microprofile-health/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/health/runtime/CamelMicroProfileHealthRecorder.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.microprofile.health.runtime; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.impl.health.DefaultHealthCheckRegistry; + +@Recorder +public class CamelMicroProfileHealthRecorder { + + public RuntimeValue<HealthCheckRegistry> createHealthCheckRegistry(CamelMicroProfileHealthConfig config) { + HealthCheckRegistry answer = new DefaultHealthCheckRegistry(); + answer.setId("camel-microprofile-health"); + answer.setEnabled(config.enabled); + return new RuntimeValue<>(answer); + } + +}