Skip to content

Commit

Permalink
Use @ConfigMapping in SmallRye Reactive Messaging extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jan 22, 2025
1 parent 1e454df commit b329543
Show file tree
Hide file tree
Showing 34 changed files with 233 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package io.quarkus.smallrye.reactivemessaging.amqp.deployment;

import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(name = "amqp", phase = ConfigPhase.BUILD_TIME)
public class AmqpBuildTimeConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigMapping(prefix = "quarkus.amqp")
public interface AmqpBuildTimeConfig {

/**
* Dev Services.
* <p>
* Dev Services allows Quarkus to automatically start an AMQP broker in dev and test mode.
*/
@ConfigItem
@ConfigDocSection(generated = true)
public AmqpDevServicesBuildTimeConfig devservices;
AmqpDevServicesBuildTimeConfig devservices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

@ConfigGroup
public class AmqpDevServicesBuildTimeConfig {
public interface AmqpDevServicesBuildTimeConfig {

/**
* If Dev Services for AMQP has been explicitly enabled or disabled. Dev Services are generally enabled
* by default, unless there is an existing configuration present. For AMQP, Dev Services starts a broker unless
* {@code amqp-host} or {@code amqp-port} are set or if all the Reactive Messaging AMQP channel are configured with
* {@code host} or {@code port}.
*/
@ConfigItem
public Optional<Boolean> enabled = Optional.empty();
Optional<Boolean> enabled();

/**
* Optional fixed port the dev service will listen to.
* <p>
* If not defined, the port will be chosen randomly.
*/
@ConfigItem
public Optional<Integer> port;
Optional<Integer> port();

/**
* The image to use.
Expand All @@ -36,16 +34,16 @@ public class AmqpDevServicesBuildTimeConfig {
* page</a>
* to find the available versions.
*/
@ConfigItem(defaultValue = "quay.io/artemiscloud/activemq-artemis-broker:1.0.25")
public String imageName;
@WithDefault("quay.io/artemiscloud/activemq-artemis-broker:1.0.25")
String imageName();

/**
* The value of the {@code AMQ_EXTRA_ARGS} environment variable to pass to the container.
* For ActiveMQ Artemis Broker <= 1.0.21, set this property to
* {@code --no-autotune --mapped --no-fsync --relax-jolokia --http-host 0.0.0.0}
*/
@ConfigItem(defaultValue = "--no-autotune --mapped --no-fsync --relax-jolokia")
public String extraArgs;
@WithDefault("--no-autotune --mapped --no-fsync --relax-jolokia")
String extraArgs();

/**
* Indicates if the AMQP broker managed by Quarkus Dev Services is shared.
Expand All @@ -58,8 +56,8 @@ public class AmqpDevServicesBuildTimeConfig {
* <p>
* Container sharing is only used in dev mode.
*/
@ConfigItem(defaultValue = "true")
public boolean shared;
@WithDefault("true")
boolean shared();

/**
* The value of the {@code quarkus-dev-service-aqmp} label attached to the started container.
Expand All @@ -71,14 +69,13 @@ public class AmqpDevServicesBuildTimeConfig {
* <p>
* This property is used when you need multiple shared AMQP brokers.
*/
@ConfigItem(defaultValue = "amqp")
public String serviceName;
@WithDefault("amqp")
String serviceName();

/**
* Environment variables that are passed to the container.
*/
@ConfigItem
@ConfigDocMapKey("environment-variable-name")
public Map<String, String> containerEnv;
Map<String, String> containerEnv();

}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private boolean hasAmqpChannelWithoutHostAndPort() {
}

private AmqpDevServiceCfg getConfiguration(AmqpBuildTimeConfig cfg) {
AmqpDevServicesBuildTimeConfig devServicesConfig = cfg.devservices;
AmqpDevServicesBuildTimeConfig devServicesConfig = cfg.devservices();
return new AmqpDevServiceCfg(devServicesConfig);
}

Expand All @@ -250,13 +250,13 @@ private static final class AmqpDevServiceCfg {
private final Map<String, String> containerEnv;

public AmqpDevServiceCfg(AmqpDevServicesBuildTimeConfig devServicesConfig) {
this.devServicesEnabled = devServicesConfig.enabled.orElse(true);
this.imageName = devServicesConfig.imageName;
this.fixedExposedPort = devServicesConfig.port.orElse(0);
this.extra = devServicesConfig.extraArgs;
this.shared = devServicesConfig.shared;
this.serviceName = devServicesConfig.serviceName;
this.containerEnv = devServicesConfig.containerEnv;
this.devServicesEnabled = devServicesConfig.enabled().orElse(true);
this.imageName = devServicesConfig.imageName();
this.fixedExposedPort = devServicesConfig.port().orElse(0);
this.extra = devServicesConfig.extraArgs();
this.shared = devServicesConfig.shared();
this.serviceName = devServicesConfig.serviceName();
this.containerEnv = devServicesConfig.containerEnv();
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions extensions/smallrye-reactive-messaging-amqp/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package io.quarkus.smallrye.reactivemessaging.kafka.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

@ConfigRoot(name = "messaging.kafka", phase = ConfigPhase.BUILD_TIME)
public class ReactiveMessagingKafkaBuildTimeConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigMapping(prefix = "quarkus.messaging.kafka")
public interface ReactiveMessagingKafkaBuildTimeConfig {
/**
* Whether or not Kafka serializer/deserializer auto-detection is enabled.
*/
@ConfigItem(name = "serializer-autodetection.enabled", defaultValue = "true")
public boolean serializerAutodetectionEnabled;
@WithName("serializer-autodetection.enabled")
@WithDefault("true")
boolean serializerAutodetectionEnabled();

/**
* Whether Kafka serializer/deserializer generation is enabled.
* When no serializer/deserializer are found and not set, Quarkus generates a Jackson-based serde.
*/
@ConfigItem(name = "serializer-generation.enabled", defaultValue = "true")
public boolean serializerGenerationEnabled;
@WithName("serializer-generation.enabled")
@WithDefault("true")
boolean serializerGenerationEnabled();

/**
* Enables the graceful shutdown in dev and test modes.
* The graceful shutdown waits until the inflight records have been processed and the offset committed to Kafka.
* While this setting is highly recommended in production, in dev and test modes, it's disabled by default.
* This setting allows to re-enable it.
*/
@WithDefault("false")
boolean enableGracefulShutdownInDevAndTestMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import io.quarkus.smallrye.reactivemessaging.kafka.HibernateOrmStateStore;
import io.quarkus.smallrye.reactivemessaging.kafka.HibernateReactiveStateStore;
import io.quarkus.smallrye.reactivemessaging.kafka.KafkaConfigCustomizer;
import io.quarkus.smallrye.reactivemessaging.kafka.ReactiveMessagingKafkaConfig;
import io.quarkus.smallrye.reactivemessaging.kafka.RedisStateStore;
import io.smallrye.mutiny.tuples.Functions.TriConsumer;
import io.smallrye.reactive.messaging.kafka.KafkaConnector;
Expand Down Expand Up @@ -181,21 +180,20 @@ public void additionalJpaModel(BuildProducer<AdditionalJpaModelBuildItem> additi
public void defaultChannelConfiguration(
LaunchModeBuildItem launchMode,
ReactiveMessagingKafkaBuildTimeConfig buildTimeConfig,
ReactiveMessagingKafkaConfig runtimeConfig,
CombinedIndexBuildItem combinedIndex,
List<ConnectorManagedChannelBuildItem> channelsManagedByConnectors,
BuildProducer<RunTimeConfigurationDefaultBuildItem> defaultConfigProducer,
BuildProducer<GeneratedClassBuildItem> generatedClass,
BuildProducer<ReflectiveClassBuildItem> reflection) {

DefaultSerdeDiscoveryState discoveryState = new DefaultSerdeDiscoveryState(combinedIndex.getIndex());
if (buildTimeConfig.serializerAutodetectionEnabled) {
if (buildTimeConfig.serializerAutodetectionEnabled()) {
discoverDefaultSerdeConfig(discoveryState, channelsManagedByConnectors, defaultConfigProducer,
buildTimeConfig.serializerGenerationEnabled ? generatedClass : null, reflection);
buildTimeConfig.serializerGenerationEnabled() ? generatedClass : null, reflection);
}

if (launchMode.getLaunchMode().isDevOrTest()) {
if (!runtimeConfig.enableGracefulShutdownInDevAndTestMode) {
if (!buildTimeConfig.enableGracefulShutdownInDevAndTestMode()) {
List<AnnotationInstance> incomings = discoveryState.findRepeatableAnnotationsOnMethods(DotNames.INCOMING);
List<AnnotationInstance> outgoings = discoveryState.findRepeatableAnnotationsOnMethods(DotNames.OUTGOING);
List<AnnotationInstance> channels = discoveryState.findAnnotationsOnInjectionPoints(DotNames.CHANNEL);
Expand Down
3 changes: 0 additions & 3 deletions extensions/smallrye-reactive-messaging-kafka/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.quarkus.smallrye.reactivemessaging.mqtt.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(name = "mqtt", phase = ConfigPhase.BUILD_TIME)
public class MqttBuildTimeConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigMapping(prefix = "quarkus.mqtt")
public interface MqttBuildTimeConfig {

/**
* Configuration for DevServices. DevServices allows Quarkus to automatically start a MQTT broker in dev and test mode.
*/
@ConfigItem
public MqttDevServicesBuildTimeConfig devservices;
MqttDevServicesBuildTimeConfig devservices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

@ConfigGroup
public class MqttDevServicesBuildTimeConfig {
public interface MqttDevServicesBuildTimeConfig {

/**
* If Dev Services for MQTT has been explicitly enabled or disabled. Dev Services are generally enabled
Expand All @@ -19,22 +19,20 @@ public class MqttDevServicesBuildTimeConfig {
* with
* {@code host} or {@code port}.
*/
@ConfigItem
public Optional<Boolean> enabled = Optional.empty();
Optional<Boolean> enabled();

/**
* Optional fixed port the dev service will listen to.
* <p>
* If not defined, the port will be chosen randomly.
*/
@ConfigItem
public OptionalInt port;
OptionalInt port();

/**
* The image to use.
*/
@ConfigItem(defaultValue = "eclipse-mosquitto:2.0.15")
public String imageName;
@WithDefault("eclipse-mosquitto:2.0.15")
String imageName();

/**
* Indicates if the MQTT broker managed by Quarkus Dev Services is shared.
Expand All @@ -47,8 +45,8 @@ public class MqttDevServicesBuildTimeConfig {
* <p>
* Container sharing is only used in dev mode.
*/
@ConfigItem(defaultValue = "true")
public boolean shared;
@WithDefault("true")
boolean shared();

/**
* The value of the {@code quarkus-dev-service-mqtt} label attached to the started container.
Expand All @@ -60,13 +58,12 @@ public class MqttDevServicesBuildTimeConfig {
* <p>
* This property is used when you need multiple shared MQTT brokers.
*/
@ConfigItem(defaultValue = "mqtt")
public String serviceName;
@WithDefault("mqtt")
String serviceName();

/**
* Environment variables that are passed to the container.
*/
@ConfigItem
@ConfigDocMapKey("environment-variable-name")
public Map<String, String> containerEnv;
Map<String, String> containerEnv();
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private boolean hasMqttChannelWithoutHostAndPort() {
}

private MqttDevServiceCfg getConfiguration(MqttBuildTimeConfig cfg) {
MqttDevServicesBuildTimeConfig devServicesConfig = cfg.devservices;
MqttDevServicesBuildTimeConfig devServicesConfig = cfg.devservices();
return new MqttDevServiceCfg(devServicesConfig);
}

Expand All @@ -232,12 +232,12 @@ private static final class MqttDevServiceCfg {
private final Map<String, String> containerEnv;

public MqttDevServiceCfg(MqttDevServicesBuildTimeConfig devServicesConfig) {
this.devServicesEnabled = devServicesConfig.enabled.orElse(true);
this.imageName = devServicesConfig.imageName;
this.fixedExposedPort = devServicesConfig.port.orElse(0);
this.shared = devServicesConfig.shared;
this.serviceName = devServicesConfig.serviceName;
this.containerEnv = devServicesConfig.containerEnv;
this.devServicesEnabled = devServicesConfig.enabled().orElse(true);
this.imageName = devServicesConfig.imageName();
this.fixedExposedPort = devServicesConfig.port().orElse(0);
this.shared = devServicesConfig.shared();
this.serviceName = devServicesConfig.serviceName();
this.containerEnv = devServicesConfig.containerEnv();
}

@Override
Expand Down
Loading

0 comments on commit b329543

Please sign in to comment.