Skip to content

Commit

Permalink
[Issue-2771] [Enhancement] Tries to inject Vertx instance from CDI us…
Browse files Browse the repository at this point in the history
…ing a qualifier
  • Loading branch information
gaol committed Oct 9, 2024
1 parent 4d869e4 commit 9b4efed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import jakarta.enterprise.context.BeforeDestroyed;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.event.Reception;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

import org.eclipse.microprofile.config.Config;

import io.smallrye.common.annotation.Identifier;
import io.vertx.mutiny.core.Vertx;

/**
Expand All @@ -19,6 +24,8 @@
@ApplicationScoped
public class ExecutionHolder {

private static final String REACTIVE_MESSAGING_VERTX_CDI_QUALIFIER = "mp.messaging.connector.vertx.cdi.qualifier";

private boolean internalVertxInstance = false;
final Vertx vertx;

Expand All @@ -40,13 +47,25 @@ public ExecutionHolder(Vertx vertx) {
}

@Inject
public ExecutionHolder(Instance<Vertx> instanceOfVertx) {
if (instanceOfVertx == null || instanceOfVertx.isUnsatisfied()) {
public ExecutionHolder(@Any Instance<Vertx> instanceOfVertx, Instance<Config> config) {
String cdiQualifier = null;
if (config != null && !config.isUnsatisfied()) {
final Config theConfig = config.get();
cdiQualifier = theConfig.getConfigValue(REACTIVE_MESSAGING_VERTX_CDI_QUALIFIER).getValue();
}
final Instance<Vertx> vertxInstance;
if (cdiQualifier != null && !cdiQualifier.isEmpty()) {
log.vertxFromCDIQualifier(cdiQualifier);
vertxInstance = instanceOfVertx.select(Identifier.Literal.of(cdiQualifier));
} else {
vertxInstance = instanceOfVertx.select(Default.Literal.INSTANCE);
}
if (vertxInstance == null || vertxInstance.isUnsatisfied()) {
internalVertxInstance = true;
this.vertx = Vertx.vertx();
log.vertXInstanceCreated();
} else {
this.vertx = instanceOfVertx.get();
this.vertx = vertxInstance.get();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ public interface ProviderLogging extends BasicLogger {
@LogMessage(level = Logger.Level.WARN)
@Message(id = 243, value = "Processing method '%s' annotated with @Acknowledgement(POST_PROCESSING), but may not be compatible with post-processing acknowledgement management. You may experience duplicate (negative-)acknowledgement of messages.")
void postProcessingNotFullySupported(String methodAsString);

@LogMessage(level = Logger.Level.INFO)
@Message(id = 244, value = "Trying to get Vertx instance using Identifier qualifier: %s.")
void vertxFromCDIQualifier(String cdiQualifier);
}

0 comments on commit 9b4efed

Please sign in to comment.