From d1a6357b95783c2979cd89f1f40117dd3da59d1d Mon Sep 17 00:00:00 2001 From: glasses-and-hat Date: Sat, 27 Jun 2026 09:59:57 -0500 Subject: [PATCH] feat(activemq): add execArtemisCommand helper to ArtemisContainer Adds a convenience method that wraps the Artemis CLI binary inside the container, automatically prepending the binary path and appending broker credentials. Users no longer need to hardcode the binary path or pass --user/--password manually when invoking management commands (e.g. creating AMQP queues). Closes #11589 --- docs/modules/activemq.md | 8 +++++++ .../activemq/ArtemisContainer.java | 21 +++++++++++++++++++ .../activemq/ArtemisContainerTest.java | 19 +++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/docs/modules/activemq.md b/docs/modules/activemq.md index 7959c47576a..e21cdeb67ae 100644 --- a/docs/modules/activemq.md +++ b/docs/modules/activemq.md @@ -37,6 +37,14 @@ With anonymous login: [Allow anonymous login](../../modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java) inside_block:enableAnonymousLogin +### Executing Artemis CLI commands + +The Artemis image ships with a built-in CLI that can be used to administer the broker (e.g. create queues for AMQP 1.0 clients). `ArtemisContainer` exposes an `execArtemisCommand` helper that automatically prepends the binary path and appends the broker credentials, so you only need to supply the sub-command and its options: + + +[Executing an Artemis CLI command](../../modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java) inside_block:execArtemisCommand + + ## Adding this module to your project dependencies Add the following dependency to your `pom.xml`/`build.gradle` file: diff --git a/modules/activemq/src/main/java/org/testcontainers/activemq/ArtemisContainer.java b/modules/activemq/src/main/java/org/testcontainers/activemq/ArtemisContainer.java index 82072993b48..d691db2070b 100644 --- a/modules/activemq/src/main/java/org/testcontainers/activemq/ArtemisContainer.java +++ b/modules/activemq/src/main/java/org/testcontainers/activemq/ArtemisContainer.java @@ -4,6 +4,7 @@ import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; +import java.io.IOException; import java.time.Duration; /** @@ -28,6 +29,8 @@ public class ArtemisContainer extends GenericContainer { private static final DockerImageName APACHE_ARTEMIS_IMAGE = DockerImageName.parse("apache/artemis"); + private static final String ARTEMIS_CLI_PATH = "/var/lib/artemis-instance/bin/artemis"; + private static final int WEB_CONSOLE_PORT = 8161; // CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE @@ -86,4 +89,22 @@ public String getUser() { public String getPassword() { return getEnvMap().get("ARTEMIS_PASSWORD"); } + + /** + * Execute an Artemis CLI command inside the container. The broker credentials are + * automatically appended so callers only need to supply the sub-command and its options. + * + * @param commands the sub-command and its arguments, e.g. {@code "queue", "create", "--name=myQueue", ...} + * @return the result of the command execution + */ + public ExecResult execArtemisCommand(String... commands) throws IOException, InterruptedException { + String[] fullCommand = new String[commands.length + 5]; + fullCommand[0] = ARTEMIS_CLI_PATH; + System.arraycopy(commands, 0, fullCommand, 1, commands.length); + fullCommand[commands.length + 1] = "--user"; + fullCommand[commands.length + 2] = getUser(); + fullCommand[commands.length + 3] = "--password"; + fullCommand[commands.length + 4] = getPassword(); + return execInContainer(fullCommand); + } } diff --git a/modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java b/modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java index 74cdfa76da7..0375346f2bf 100644 --- a/modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java +++ b/modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java @@ -71,6 +71,25 @@ void compatibility(String image) { } } + @Test + void execArtemisCommand() throws Exception { + try (ArtemisContainer artemis = new ArtemisContainer("apache/activemq-artemis:2.32.0-alpine")) { + artemis.start(); + + // execArtemisCommand { + var result = artemis.execArtemisCommand( + "queue", + "create", + "--name=test-amqp-queue", + "--auto-create-address", + "--anycast", + "--silent" + ); + // } + assertThat(result.getExitCode()).isEqualTo(0); + } + } + @SneakyThrows private void assertFunctionality(ArtemisContainer artemis, boolean anonymousLogin) { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(artemis.getBrokerUrl());