|
| 1 | +package org.testcontainers.activemq; |
| 2 | + |
| 3 | +import org.testcontainers.containers.GenericContainer; |
| 4 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 5 | +import org.testcontainers.utility.DockerImageName; |
| 6 | + |
| 7 | +import java.time.Duration; |
| 8 | + |
| 9 | +/** |
| 10 | + * Testcontainers implementation for Apache ActiveMQ Artemis. |
| 11 | + * <p> |
| 12 | + * Exposed ports: |
| 13 | + * <ul> |
| 14 | + * <li>Console: 8161</li> |
| 15 | + * <li>TCP: 61616</li> |
| 16 | + * <li>HORNETQ: 5445</li> |
| 17 | + * <li>AMQP: 5672</li> |
| 18 | + * <li>STOMP: 61613</li> |
| 19 | + * <li>MQTT: 1883</li> |
| 20 | + * <li>WS: 61614</li> |
| 21 | + * </ul> |
| 22 | + */ |
| 23 | +public class ArtemisContainer extends GenericContainer<ArtemisContainer> { |
| 24 | + |
| 25 | + private static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("apache/activemq-artemis"); |
| 26 | + |
| 27 | + private static final int WEB_CONSOLE_PORT = 8161; |
| 28 | + |
| 29 | + // CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE |
| 30 | + private static final int TCP_PORT = 61616; |
| 31 | + |
| 32 | + private static final int HORNETQ_STOMP_PORT = 5445; |
| 33 | + |
| 34 | + private static final int AMQP_PORT = 5672; |
| 35 | + |
| 36 | + private static final int STOMP_PORT = 61613; |
| 37 | + |
| 38 | + private static final int MQTT_PORT = 1883; |
| 39 | + |
| 40 | + private static final int WS_PORT = 61614; |
| 41 | + |
| 42 | + private String username = "artemis"; |
| 43 | + |
| 44 | + private String password = "artemis"; |
| 45 | + |
| 46 | + public ArtemisContainer(String image) { |
| 47 | + this(DockerImageName.parse(image)); |
| 48 | + } |
| 49 | + |
| 50 | + public ArtemisContainer(DockerImageName dockerImageName) { |
| 51 | + super(dockerImageName); |
| 52 | + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE); |
| 53 | + |
| 54 | + withExposedPorts(WEB_CONSOLE_PORT, TCP_PORT, HORNETQ_STOMP_PORT, AMQP_PORT, STOMP_PORT, MQTT_PORT, WS_PORT); |
| 55 | + waitingFor(Wait.forLogMessage(".*HTTP Server started.*", 1).withStartupTimeout(Duration.ofMinutes(1))); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + protected void configure() { |
| 60 | + withEnv("ARTEMIS_USER", this.username); |
| 61 | + withEnv("ARTEMIS_PASSWORD", this.password); |
| 62 | + } |
| 63 | + |
| 64 | + public ArtemisContainer withUser(String username) { |
| 65 | + this.username = username; |
| 66 | + return this; |
| 67 | + } |
| 68 | + |
| 69 | + public ArtemisContainer withPassword(String password) { |
| 70 | + this.password = password; |
| 71 | + return this; |
| 72 | + } |
| 73 | + |
| 74 | + public String getBrokerUrl() { |
| 75 | + return String.format("tcp://%s:%s", getHost(), getMappedPort(TCP_PORT)); |
| 76 | + } |
| 77 | + |
| 78 | + public String getUser() { |
| 79 | + return getEnvMap().get("ARTEMIS_USER"); |
| 80 | + } |
| 81 | + |
| 82 | + public String getPassword() { |
| 83 | + return getEnvMap().get("ARTEMIS_PASSWORD"); |
| 84 | + } |
| 85 | +} |
0 commit comments