首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >等待RabbitMQ docker容器以docker-maven-plugin启动

等待RabbitMQ docker容器以docker-maven-plugin启动
EN

Stack Overflow用户
提问于 2017-08-04 20:08:40
回答 2查看 1.7K关注 0票数 0

如何让docker-maven-plugin在运行集成测试之前等待RabbitMQ容器完全启动?

这是我在pom.xml中使用的插件配置

代码语言:javascript
复制
<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时,它仍在初始化并失败,因为服务器不可用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-09 21:09:13

我设法找到了一种更自信的方法来检查RabbitMQ的状态。当我使用rabbitmq:3.6.10-management docker镜像时,我可以检查localhost:15672上的管理url是否在运行:

代码语言:javascript
复制
<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秒内启动。

票数 1
EN

Stack Overflow用户

发布于 2017-08-04 20:24:38

“启动容器时,是否可以阻止执行,直到满足某些条件”

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

您可以使用log从RabbitMQ容器中通过wait获取一些日志输出

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.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45506461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档