diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml b/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml
index a7cebf7f0b622..066d3fa37b847 100644
--- a/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml
+++ b/extensions/smallrye-reactive-messaging-amqp/deployment/pom.xml
@@ -97,6 +97,10 @@
awaitility
test
+
+ io.quarkus
+ quarkus-devservices-common
+
diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java
index 8d6ce22434623..db05fab1475bc 100644
--- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java
+++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java
@@ -1,21 +1,16 @@
package io.quarkus.smallrye.reactivemessaging.amqp.deployment;
import java.io.Closeable;
-import java.util.List;
import java.util.Objects;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
-import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
-import com.github.dockerjava.api.model.Container;
-import com.github.dockerjava.api.model.ContainerPort;
-
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.IsDockerWorking;
import io.quarkus.deployment.IsNormal;
@@ -25,6 +20,7 @@
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
+import io.quarkus.devservices.common.ContainerLocator;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
@@ -44,6 +40,8 @@ public class DevServicesAmqpProcessor {
private static final String DEV_SERVICE_LABEL = "quarkus-dev-service-amqp";
private static final int AMQP_PORT = 5672;
+
+ private static final ContainerLocator amqpContainerLocator = new ContainerLocator(DEV_SERVICE_LABEL, AMQP_PORT);
private static final String AMQP_HOST_PROP = "amqp-host";
private static final String AMQP_PORT_PROP = "amqp-port";
private static final String AMQP_USER_PROP = "amqp-user";
@@ -154,28 +152,6 @@ private void shutdownBroker() {
}
}
- private static Container lookup(String expectedLabelValue) {
- List containers = DockerClientFactory.lazyClient().listContainersCmd().exec();
- for (Container container : containers) {
- String s = container.getLabels().get(DEV_SERVICE_LABEL);
- if (expectedLabelValue.equalsIgnoreCase(s)) {
- return container;
- }
- }
- return null;
- }
-
- private static ContainerPort getMappedPort(Container container, int port) {
- for (ContainerPort p : container.getPorts()) {
- Integer mapped = p.getPrivatePort();
- Integer publicPort = p.getPublicPort();
- if (mapped != null && mapped == port && publicPort != null) {
- return p;
- }
- }
- return null;
- }
-
private AmqpBroker startAmqpBroker(AmqpDevServiceCfg config, LaunchModeBuildItem launchMode) {
if (!config.devServicesEnabled) {
// explicitly disabled
@@ -202,19 +178,11 @@ private AmqpBroker startAmqpBroker(AmqpDevServiceCfg config, LaunchModeBuildItem
if (config.shared && launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) {
// Detect if there is a broker already started using container labels.
- Container container = lookup(config.serviceName);
- if (container != null) {
- ContainerPort port = getMappedPort(container, AMQP_PORT);
- if (port != null) {
- Integer p = port.getPublicPort();
- String url = port.getIp() + ":" + p;
- log.infof("Dev Services for AMQP container found: %s (%s). "
- + "Connecting to: %s.",
- container.getId(),
- container.getImage(), url);
- return new AmqpBroker(port.getIp(), p, "admin", "admin", null);
- }
- }
+
+ final String url = amqpContainerLocator.locateContainer(config.serviceName);
+
+ // FIXME: url -> host, port, username, password
+ return new AmqpBroker(url, 0, "admin", "admin", null);
}
// Starting the broker
@@ -304,7 +272,6 @@ public AmqpDevServiceCfg(AmqpDevServicesBuildTimeConfig devServicesConfig) {
this.extra = devServicesConfig.extraArgs;
this.shared = devServicesConfig.shared;
this.serviceName = devServicesConfig.serviceName;
- ;
}
@Override