io.quarkus.vertx.runtime.VertxRecorder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-vertx Show documentation
Show all versions of quarkus-vertx Show documentation
Write reactive applications with the Vert.x API
package io.quarkus.vertx.runtime;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
import java.util.function.Supplier;
import org.jboss.logging.Logger;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.ConsumeEvent;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import io.vertx.core.eventbus.MessageCodec;
import io.vertx.core.eventbus.MessageConsumer;
@Recorder
public class VertxRecorder {
private static final Logger LOGGER = Logger.getLogger(VertxRecorder.class.getName());
static volatile Vertx vertx;
static volatile List> messageConsumers;
public void configureVertx(Supplier vertx, Map messageConsumerConfigurations,
LaunchMode launchMode, ShutdownContext shutdown, Map, Class>> codecByClass) {
VertxRecorder.vertx = vertx.get();
VertxRecorder.messageConsumers = new ArrayList<>();
registerMessageConsumers(messageConsumerConfigurations);
registerCodecs(codecByClass);
if (launchMode == LaunchMode.DEVELOPMENT) {
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
unregisterMessageConsumers();
}
});
} else {
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
destroy();
}
});
}
}
public static Vertx getVertx() {
return vertx;
}
void destroy() {
messageConsumers = null;
}
void registerMessageConsumers(Map messageConsumerConfigurations) {
if (!messageConsumerConfigurations.isEmpty()) {
EventBus eventBus = vertx.eventBus();
CountDownLatch latch = new CountDownLatch(messageConsumerConfigurations.size());
for (Entry entry : messageConsumerConfigurations.entrySet()) {
EventConsumerInvoker invoker = createInvoker(entry.getKey());
String address = entry.getValue().value();
MessageConsumer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy