![](/img/trans.png)
[英]Spring Boot 2 app cannot connect to mysql while run inside docker container triggered by 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.