Skip to content

Commit 321efed

Browse files
committed
Move logic of resolving PulsarBrokerUrl and HttpServiceUrl into PulsarContainer
1 parent 6f99bbc commit 321efed

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarContainer.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.quarkus.smallrye.reactivemessaging.pulsar.deployment;
22

3+
import static io.quarkus.smallrye.reactivemessaging.pulsar.deployment.PulsarDevServicesProcessor.DEV_SERVICE_PULSAR;
4+
35
import java.nio.charset.StandardCharsets;
46
import java.time.Duration;
57
import java.util.Collections;
@@ -11,6 +13,8 @@
1113

1214
import com.github.dockerjava.api.command.InspectContainerResponse;
1315

16+
import io.quarkus.devservices.common.ConfigureUtil;
17+
1418
public class PulsarContainer extends GenericContainer<PulsarContainer> {
1519

1620
public static final DockerImageName PULSAR_IMAGE = DockerImageName.parse("apachepulsar/pulsar:3.2.4");
@@ -20,6 +24,9 @@ public class PulsarContainer extends GenericContainer<PulsarContainer> {
2024
public static final int BROKER_PORT = 6650;
2125
public static final int BROKER_HTTP_PORT = 8080;
2226

27+
private boolean useSharedNetwork;
28+
private String hostName;
29+
2330
public PulsarContainer() {
2431
this(PULSAR_IMAGE);
2532
}
@@ -51,6 +58,13 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
5158
STARTER_SCRIPT);
5259
}
5360

61+
public PulsarContainer withSharedNetwork() {
62+
useSharedNetwork = true;
63+
hostName = ConfigureUtil.configureSharedNetwork(this, DEV_SERVICE_PULSAR);
64+
65+
return self();
66+
}
67+
5468
public PulsarContainer withPort(final int fixedPort) {
5569
if (fixedPort <= 0) {
5670
throw new IllegalArgumentException("The fixed port must be greater than 0");
@@ -60,10 +74,24 @@ public PulsarContainer withPort(final int fixedPort) {
6074
}
6175

6276
public String getPulsarBrokerUrl() {
63-
return String.format("pulsar://%s:%s", this.getHost(), this.getMappedPort(BROKER_PORT));
77+
if (useSharedNetwork) {
78+
return getServiceUrl(this.hostName, PulsarContainer.BROKER_PORT);
79+
}
80+
return getServiceUrl(this.getHost(), this.getMappedPort(BROKER_PORT));
81+
}
82+
83+
private String getServiceUrl(String host, int port) {
84+
return String.format("pulsar://%s:%d", host, port);
6485
}
6586

6687
public String getHttpServiceUrl() {
67-
return String.format("http://%s:%s", this.getHost(), this.getMappedPort(BROKER_HTTP_PORT));
88+
if (useSharedNetwork) {
89+
return getHttpServiceUrl(this.hostName, PulsarContainer.BROKER_HTTP_PORT);
90+
}
91+
return getHttpServiceUrl(this.getHost(), this.getMappedPort(BROKER_HTTP_PORT));
92+
}
93+
94+
private String getHttpServiceUrl(String host, int port) {
95+
return String.format("http://%s:%d", host, port);
6896
}
6997
}

extensions/smallrye-reactive-messaging-pulsar/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/pulsar/deployment/PulsarDevServicesProcessor.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import io.quarkus.deployment.console.StartupLogCompressor;
3030
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
3131
import io.quarkus.deployment.logging.LoggingSetupBuildItem;
32-
import io.quarkus.devservices.common.ConfigureUtil;
3332
import io.quarkus.devservices.common.ContainerLocator;
3433
import io.quarkus.runtime.LaunchMode;
3534
import io.quarkus.runtime.configuration.ConfigUtils;
@@ -51,9 +50,9 @@ public class PulsarDevServicesProcessor {
5150

5251
private static final ContainerLocator pulsarContainerLocator = new ContainerLocator(DEV_SERVICE_LABEL,
5352
PulsarContainer.BROKER_PORT);
54-
private static final String DEV_SERVICE_PULSAR = "pulsar";
5553
private static final String PULSAR_CLIENT_SERVICE_URL = "pulsar.client.serviceUrl";
5654
private static final String PULSAR_ADMIN_SERVICE_URL = "pulsar.admin.serviceUrl";
55+
static final String DEV_SERVICE_PULSAR = "pulsar";
5756
static volatile RunningDevService devService;
5857
static volatile PulsarDevServiceCfg cfg;
5958
static volatile boolean first = true;
@@ -183,21 +182,13 @@ private RunningDevService startPulsarContainer(DockerStatusBuildItem dockerStatu
183182
container.withPort(config.fixedExposedPort);
184183
}
185184
timeout.ifPresent(container::withStartupTimeout);
186-
String hostName = null;
187185
if (useSharedNetwork) {
188-
hostName = ConfigureUtil.configureSharedNetwork(container, DEV_SERVICE_PULSAR);
186+
container.withSharedNetwork();
189187
}
190188
container.start();
191189

192-
var pulsarBrokerUrl = container.getPulsarBrokerUrl();
193-
var httpHostServiceUrl = container.getHttpServiceUrl();
194-
if (useSharedNetwork) {
195-
pulsarBrokerUrl = getServiceUrl(hostName, PulsarContainer.BROKER_PORT);
196-
httpHostServiceUrl = getHttpServiceUrl(hostName, PulsarContainer.BROKER_HTTP_PORT);
197-
}
198-
199-
return getRunningService(container.getContainerId(), container::close, pulsarBrokerUrl,
200-
httpHostServiceUrl);
190+
return getRunningService(container.getContainerId(), container::close, container.getPulsarBrokerUrl(),
191+
container.getHttpServiceUrl());
201192
};
202193

203194
return pulsarContainerLocator.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode())

0 commit comments

Comments
 (0)