Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/modules/activemq.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ With anonymous login:
[Allow anonymous login](../../modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java) inside_block:enableAnonymousLogin
<!--/codeinclude-->

### 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:

<!--codeinclude-->
[Executing an Artemis CLI command](../../modules/activemq/src/test/java/org/testcontainers/activemq/ArtemisContainerTest.java) inside_block:execArtemisCommand
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.time.Duration;

/**
Expand All @@ -28,6 +29,8 @@ public class ArtemisContainer extends GenericContainer<ArtemisContainer> {

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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down