diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/DotNames.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/DotNames.java index 1a0fe28f8..9a5144d31 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/DotNames.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/DotNames.java @@ -10,6 +10,7 @@ import io.smallrye.reactive.messaging.annotations.Channel; import io.smallrye.reactive.messaging.annotations.Emitter; import io.smallrye.reactive.messaging.annotations.Merge; import io.smallrye.reactive.messaging.annotations.OnOverflow; +import io.smallrye.reactive.messaging.metrics.MetricDecorator; public final class DotNames { @@ -27,6 +28,8 @@ public final class DotNames { static final DotName MERGE = DotName.createSimple(Merge.class.getName()); static final DotName BROADCAST = DotName.createSimple(Broadcast.class.getName()); + static final DotName METRIC_DECORATOR = DotName.createSimple(MetricDecorator.class.getName()); + private DotNames() { } diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java index 766c12771..64507eac7 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/SmallRyeReactiveMessagingProcessor.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Optional; import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Vetoed; import javax.enterprise.inject.spi.DeploymentException; import org.eclipse.microprofile.config.Config; @@ -61,7 +62,6 @@ import io.quarkus.smallrye.reactivemessaging.runtime.ReactiveMessagingConfigurat import io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle; import io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingRecorder; import io.smallrye.reactive.messaging.Invoker; -import io.smallrye.reactive.messaging.metrics.MetricDecorator; /** * @author Martin Kouba @@ -236,10 +236,27 @@ public class SmallRyeReactiveMessagingProcessor { } @BuildStep - public void enableMetrics(Capabilities capabilities, ReactiveMessagingConfiguration configuration, - BuildProducer beans) { - if (capabilities.isCapabilityPresent(Capabilities.METRICS) && configuration.metricsEnabled) { - beans.produce(new AdditionalBeanBuildItem(MetricDecorator.class.getName())); + public void enableMetrics(BuildProducer transformers, + Capabilities capabilities, ReactiveMessagingConfiguration configuration) { + boolean isMetricEnabled = capabilities.isCapabilityPresent(Capabilities.METRICS) && configuration.metricsEnabled; + if (!isMetricEnabled) { + LOGGER.info("Metric is disabled - vetoing the MetricDecorator"); + // We veto the Metric Decorator + AnnotationsTransformerBuildItem veto = new AnnotationsTransformerBuildItem(new AnnotationsTransformer() { + @Override + public boolean appliesTo(AnnotationTarget.Kind kind) { + return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS; + } + + @Override + public void transform(AnnotationsTransformer.TransformationContext ctx) { + if (ctx.isClass() && ctx.getTarget().asClass().name().equals( + io.quarkus.smallrye.reactivemessaging.deployment.DotNames.METRIC_DECORATOR)) { + ctx.transform().add(Vetoed.class).done(); + } + } + }); + transformers.produce(veto); } } diff --git a/tcks/microprofile-reactive-messaging/pom.xml b/tcks/microprofile-reactive-messaging/pom.xml index ecbeac072..e44f8f81b 100644 --- a/tcks/microprofile-reactive-messaging/pom.xml +++ b/tcks/microprofile-reactive-messaging/pom.xml @@ -51,9 +51,5 @@ microprofile-reactive-messaging-tck ${microprofile-reactive-messaging-api.version} - - io.quarkus - quarkus-smallrye-metrics -