rebue.wheel.vertx.guice.VertxGuiceModule Maven / Gradle / Ivy
The newest version!
package rebue.wheel.vertx.guice;
import com.github.f4b6a3.ulid.UlidCreator;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.json.JsonObject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class VertxGuiceModule extends AbstractModule {
protected Vertx vertx;
private final JsonObject config;
public VertxGuiceModule(final Vertx vertx, final JsonObject config) {
log.info("new VertxGuiceModule");
this.vertx = vertx;
this.config = config;
}
@Provides
@Singleton
Vertx getVertx() {
log.info("VertxGuiceModule.getVertx");
return this.vertx;
}
@Provides
@Singleton
EventBus getEventBus() {
log.info("VertxGuiceModule.getEventBus");
return this.vertx.eventBus();
}
@Provides
@Singleton
@Named("config")
JsonObject getConfig() {
log.info("VertxGuiceModule.getConfig");
return this.config;
}
@Provides
@Singleton
@Named("deliveryOptions")
JsonObject getDeliveryOptions(@Named("config") final JsonObject config) {
log.info("VertxGuiceModule.getDeliveryOptions");
final JsonObject deliveryConfig = config.getJsonObject("delivery");
return deliveryConfig == null ? new JsonObject() : deliveryConfig;
}
@Provides
@Singleton
@Named("mainId")
String getMainId() {
log.info("VertxGuiceModule.getMainId");
String mainId = UlidCreator.getUlid().toLowerCase();
log.info("生成MainId: {}", mainId);
return mainId;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy