From 1f301980342492955e16beed36feec7845312367 Mon Sep 17 00:00:00 2001 From: Zheng Feng Date: Mon, 4 Jul 2022 21:59:10 +0800 Subject: [PATCH] Improve Artemis DevService --- .../ArtemisDevServicesBuildTimeConfig.java | 8 ++- .../DevServicesArtemisProcessor.java | 52 +++++++++++++++---- .../ROOT/pages/includes/attributes.adoc | 2 +- .../pages/includes/quarkus-artemis-core.adoc | 8 +-- .../it/artemis/DevServiceArtemisEnabled.java | 2 +- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisDevServicesBuildTimeConfig.java b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisDevServicesBuildTimeConfig.java index 1c8c52cb..5c4b7606 100644 --- a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisDevServicesBuildTimeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisDevServicesBuildTimeConfig.java @@ -1,7 +1,5 @@ package io.quarkus.artemis.core.deployment; -import java.util.Collections; -import java.util.List; import java.util.Optional; import io.quarkus.runtime.annotations.ConfigGroup; @@ -71,8 +69,8 @@ public class ArtemisDevServicesBuildTimeConfig { public String password; /** - * Queues to create on starting + * The value of the {@code AMQ_EXTRA_ARGS} environment variable to pass to the container. */ - @ConfigItem(defaultValue = "[]") - public List queues = Collections.emptyList(); + @ConfigItem(defaultValue = "--no-autotune --mapped --no-fsync") + public String extraArgs; } diff --git a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java index e15fb7db..43ff3805 100644 --- a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/DevServicesArtemisProcessor.java @@ -8,7 +8,9 @@ import org.jboss.logging.Logger; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildStep; @@ -153,12 +155,12 @@ private RunningDevService startArtemis(DockerStatusBuildItem dockerStatusBuildIt // Starting the broker final Supplier defaultArtemisBrokerSupplier = () -> { - GenericContainer container = new GenericContainer<>(config.imageName) - .withExposedPorts(ARTEMIS_PORT) - .withEnv("AMQ_USER", config.user) - .withEnv("AMQ_PASSWORD", config.password) - .withEnv("AMQ_EXTRA_ARGS", "--queues " + String.join(", ", config.queues)) - .waitingFor(Wait.forLogMessage(".* Apache ActiveMQ Artemis Message Broker .*", 1)); + ArtemisContainer container = new ArtemisContainer( + DockerImageName.parse(config.imageName), + config.fixedExposedPort, + config.user, + config.password, + config.extraArgs); ConfigureUtil.configureSharedNetwork(container, "artemis"); @@ -173,7 +175,7 @@ private RunningDevService startArtemis(DockerStatusBuildItem dockerStatusBuildIt container.getContainerId(), container::close, QUARKUS_ARTEMIS_URL, - String.format("tcp://%s:%d", container.getHost(), container.getMappedPort(ARTEMIS_PORT))); + String.format("tcp://%s:%d", container.getHost(), container.getPort())); }; return maybeContainerAddress @@ -197,7 +199,7 @@ private static final class ArtemisDevServiceCfg { private final String serviceName; private final String user; private final String password; - private final List queues; + private final String extraArgs; public ArtemisDevServiceCfg(ArtemisDevServicesBuildTimeConfig config) { this.devServicesEnabled = config.enabled.orElse(true); @@ -207,7 +209,7 @@ public ArtemisDevServiceCfg(ArtemisDevServicesBuildTimeConfig config) { this.serviceName = config.serviceName; this.user = config.user; this.password = config.password; - this.queues = config.queues; + this.extraArgs = config.extraArgs; } @Override @@ -228,4 +230,36 @@ public int hashCode() { return Objects.hash(devServicesEnabled, imageName, fixedExposedPort); } } + + /** + * Container configuring and starting the Artemis broker. + */ + private static final class ArtemisContainer extends GenericContainer { + + private final int port; + + private ArtemisContainer(DockerImageName dockerImageName, int fixedExposedPort, String user, String password, + String extra) { + super(dockerImageName); + this.port = fixedExposedPort; + withNetwork(Network.SHARED); + withExposedPorts(ARTEMIS_PORT); + withEnv("AMQ_USER", user); + withEnv("AMQ_PASSWORD", password); + withEnv("AMQ_EXTRA_ARGS", extra); + waitingFor(Wait.forLogMessage(".*AMQ241004.*", 1)); // Artemis console available. + } + + @Override + protected void configure() { + super.configure(); + if (port > 0) { + addFixedExposedPort(port, ARTEMIS_PORT); + } + } + + public int getPort() { + return getMappedPort(ARTEMIS_PORT); + } + } } diff --git a/docs/modules/ROOT/pages/includes/attributes.adoc b/docs/modules/ROOT/pages/includes/attributes.adoc index 6c78bb29..9544d84c 100644 --- a/docs/modules/ROOT/pages/includes/attributes.adoc +++ b/docs/modules/ROOT/pages/includes/attributes.adoc @@ -1,4 +1,4 @@ -:quarkus-version: 2.10.0.Final +:quarkus-version: 2.10.1.Final :quarkus-artemis-version: 1.2.0 :quarkus-org-url: https://github.com/quarkusio diff --git a/docs/modules/ROOT/pages/includes/quarkus-artemis-core.adoc b/docs/modules/ROOT/pages/includes/quarkus-artemis-core.adoc index 71905f35..d37ad8a7 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-artemis-core.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-artemis-core.adoc @@ -93,13 +93,13 @@ Password to start artemis broker |`admin` -a|icon:lock[title=Fixed at build time] [[quarkus-artemis-core_quarkus.artemis.devservices.queues]]`link:#quarkus-artemis-core_quarkus.artemis.devservices.queues[quarkus.artemis.devservices.queues]` +a|icon:lock[title=Fixed at build time] [[quarkus-artemis-core_quarkus.artemis.devservices.extra-args]]`link:#quarkus-artemis-core_quarkus.artemis.devservices.extra-args[quarkus.artemis.devservices.extra-args]` [.description] -- -Queues to create on starting ---|list of string -|`[]` +The value of the `AMQ_EXTRA_ARGS` environment variable to pass to the container. +--|string +|`--no-autotune --mapped --no-fsync` a| [[quarkus-artemis-core_quarkus.artemis.url]]`link:#quarkus-artemis-core_quarkus.artemis.url[quarkus.artemis.url]` diff --git a/integration-tests/core/src/test/java/io/quarkus/it/artemis/DevServiceArtemisEnabled.java b/integration-tests/core/src/test/java/io/quarkus/it/artemis/DevServiceArtemisEnabled.java index a807459b..ddc945ac 100644 --- a/integration-tests/core/src/test/java/io/quarkus/it/artemis/DevServiceArtemisEnabled.java +++ b/integration-tests/core/src/test/java/io/quarkus/it/artemis/DevServiceArtemisEnabled.java @@ -13,7 +13,7 @@ public DevServiceArtemisEnabled() { public Map getConfigOverrides() { Map props = new HashMap<>(); props.put("quarkus.artemis.devservices.enabled", "true"); - props.put("quarkus.artemis.devservices.queues", "test-core"); + props.put("quarkus.artemis.devservices.extra-args", "--no-autotune --queues test-core"); return props; }