-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathRabbitMQContainer.java
More file actions
55 lines (47 loc) · 1.7 KB
/
RabbitMQContainer.java
File metadata and controls
55 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright The OpenZipkin Authors
* SPDX-License-Identifier: Apache-2.0
*/
package zipkin2.reporter.amqp;
import java.time.Duration;
import org.opentest4j.TestAbortedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import static org.testcontainers.utility.DockerImageName.parse;
import static zipkin2.reporter.Call.propagateIfFatal;
final class RabbitMQContainer extends GenericContainer<RabbitMQContainer> {
static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQContainer.class);
static final int RABBIT_PORT = 5672;
RabbitMQContainer() {
super(parse("ghcr.io/openzipkin/zipkin-rabbitmq:3.6.0"));
withExposedPorts(RABBIT_PORT);
waitStrategy = Wait.forLogMessage(".*Server startup complete.*", 1);
withStartupTimeout(Duration.ofSeconds(60));
withLogConsumer(new Slf4jLogConsumer(LOGGER));
}
RabbitMQSender.Builder newSenderBuilder(String queue) {
declareQueue(queue);
return RabbitMQSender.newBuilder().queue(queue).addresses(host() + ":" + port());
}
void declareQueue(String queue) {
ExecResult result;
try {
result = execInContainer("amqp-declare-queue", "-q", queue);
} catch (Throwable e) {
propagateIfFatal(e);
throw new TestAbortedException("Couldn't declare queue " + queue + ": " + e.getMessage(), e);
}
if (result.getExitCode() != 0) {
throw new TestAbortedException("Couldn't declare queue " + queue + ": " + result);
}
}
String host() {
return getHost();
}
int port() {
return getMappedPort(RABBIT_PORT);
}
}