Skip to content

Commit 6c10259

Browse files
committed
Add auto-configuration capability for Quarkus+Kafka
1 parent 7840554 commit 6c10259

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

docs/features/KafkaMessaging.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public class AppContainerConfig implements SharedContainerConfiguration {
3636
}
3737
```
3838

39-
Runtimes such as OpenLiberty and Quarkus will be automatically configured if a `KafkaContainer` is present
40-
in the test environment. For other runtimes, you can link the containers together by using `kafka.withNetworkAlias("kafka")`
39+
Runtimes such as OpenLiberty and Quarkus will be auto-configured together if a `KafkaContainer` is present
40+
in the test environment. For Quarkus, no `ApplicationContainer` or `Network` is needed either.
41+
For other runtimes, you can link the containers together by using `kafka.withNetworkAlias("kafka")`
4142
and `app.withEnv("<runtime-specific kafka bootstrap servers property>", "kafka:9092")`.
4243

4344

modules/quarkus/src/main/java/org/microshed/testing/quarkus/QuarkusConfiguration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public void start() {
9494
// TODO: JWT auto configuration
9595
// autoConfigureJwt();
9696
autoConfigureDatabases();
97-
// TODO: Kafka auto configuration (fix classpath conflicts)
98-
// autoConfigureKafka();
97+
autoConfigureKafka();
9998
autoConfigureMongoDB();
10099
}
101100

@@ -150,7 +149,9 @@ private void autoConfigureDatabases() {
150149
}
151150

152151
private void autoConfigureKafka() {
153-
if (System.getProperty("quarkus.kafka.bootstrap-servers") != null)
152+
final String KAFKA_PROP = "kafka.bootstrap.servers";
153+
//kafka.bootstrap.servers
154+
if (System.getProperty(KAFKA_PROP) != null)
154155
return; // Do not override explicit configuration
155156
try {
156157
Class<?> KafkaContainerClass = Class.forName("org.testcontainers.containers.KafkaContainer");
@@ -160,12 +161,12 @@ private void autoConfigureKafka() {
160161
if (kafkaContainers.size() == 1) {
161162
GenericContainer<?> kafka = kafkaContainers.get(0);
162163
String bootstrapServers = (String) KafkaContainerClass.getMethod("getBootstrapServers").invoke(kafka);
163-
System.setProperty("quarkus.kafka.bootstrap-servers", bootstrapServers);
164+
System.setProperty(KAFKA_PROP, bootstrapServers);
164165
if (LOG.isInfoEnabled())
165-
LOG.info("Set quarkus.kafka.bootstrap-servers=" + bootstrapServers);
166+
LOG.info("Set " + KAFKA_PROP + "=" + bootstrapServers);
166167
} else if (kafkaContainers.size() > 1) {
167168
if (LOG.isInfoEnabled())
168-
LOG.info("Located multiple KafkaContainer instances. Unable to auto configure 'quarkus.kafka.bootstrap-servers' property");
169+
LOG.info("Located multiple KafkaContainer instances. Unable to auto configure '" + KAFKA_PROP + "' property");
169170
} else {
170171
if (LOG.isDebugEnabled())
171172
LOG.debug("No KafkaContainer instances found in configuration");

0 commit comments

Comments
 (0)