簡體   English   中英

等待RabbitMQ docker容器以docker-maven-plugin開頭

[英]Waiting for RabbitMQ docker container to start with docker-maven-plugin

如何在運行集成測試之前告訴docker-maven-plugin等待RabbitMQ容器完全啟動?

這是我在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>

目前,在RabbitMQ期間IT開始執行時,由於服務器不可用,IT仍在初始化和失敗。

“啟動容器時,可以阻止執行直到滿足某些條件”

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

您可以wait RabbitMQ容器中一些帶有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.

我設法找到一種更自信的方式來檢查RabbitMQ的狀態。 當我使用rabbitmq:3.6.10-management鏡像時,我可以檢查localhost:15672上的管理URL localhost:15672已啟動:

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

wait配置將檢查獲取管理URL的返回值,最多10秒鍾,直到它位於指定的HTTP響應狀態范圍內為止,但是RabbitMQ通常在2-3秒鍾內啟動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM