Waiting for RabbitMQ docker container to start with docker-maven-plugin

2k Views Asked by At

How can I tell docker-maven-plugin to wait for the RabbitMQ container to fully start up before running integration tests?

This is the plugin configuration I am using in the pom.xml:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>start-rabbitmq-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
            <configuration>
                <images>
                    <image>
                        <alias>rabbitmq</alias>
                        <name>rabbitmq:3.6.10-management</name>
                        <run>
                            <log>
                                <prefix>RABBITMQ</prefix>
                                <color>cyan</color>
                            </log>
                            <namingStrategy>alias</namingStrategy>
                            <ports>
                                <port>5672:5672</port>
                                <port>15672:15672</port>
                            </ports>
                        </run>
                    </image>
                </images>
            </configuration>
        </execution>
        <execution>
            <id>stop-rabbitmq-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

At the moment the ITs start executing while RabbitMQ it's still initialising and failing as the server is not available.

2

There are 2 best solutions below

0
On BEST ANSWER

I managed to find a more assertive way of checking for the status of RabbitMQ. As I am using the rabbitmq:3.6.10-management docker image, I can check that the management url on localhost:15672 is up:

<wait>
    <http>
        <url>http://localhost:15672</url>
        <method>GET</method>
        <status>200..399</status>
    </http>
    <time>10000</time>
</wait>

The wait configuration will check the return value of getting the management url, for a maximum of 10 seconds until it's within the specified HTTP response status range, but RabbitMQ normally starts up within 2 to 3 seconds.

2
On

"While starting a container is it possible to block the execution until some condition is met"

https://dmp.fabric8.io/#start-wait

You can wait for some log output from RabbitMQ container with log:

Regular expression which is applied against the log output of an container and blocks until the pattern is matched. You can use (?s) in the pattern to switch on multi line matching.