Skip to content
Permalink
Browse files
Fix #3157 to make sure the brokers option is configured in native mode (
#3198)

* Fix #3157 to make sure the brokers option is configured in native mode

* override the camel.component.kafka.brokers in KafkaDevServicesDisabledTest
  • Loading branch information
zhfeng committed Oct 20, 2021
1 parent f3973b6 commit 0caa4c491a9711e21490bfa3f5c091411aaafcd3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
@@ -24,21 +24,18 @@
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.kafka.client.deployment.DevServicesKafkaBrokerBuildItem;
import io.quarkus.kafka.client.deployment.KafkaBuildTimeConfig;
import org.apache.camel.component.kafka.KafkaComponent;
import org.apache.camel.quarkus.component.kafka.CamelKafkaRecorder;
import org.apache.camel.quarkus.component.kafka.KafkaClientFactoryProducer;
import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

class KafkaProcessor {
private static final String FEATURE = "camel-kafka";
private static final String CAMEL_KAFKA_BROKERS = "camel.component.kafka.brokers";

@BuildStep
FeatureBuildItem feature() {
@@ -54,21 +51,18 @@ void createKafkaClientFactoryProducerBean(
}
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class)
public void configureKafkaComponentForDevServices(
DevServicesKafkaBrokerBuildItem kafkaBrokerBuildItem,
KafkaBuildTimeConfig kafkaBuildTimeConfig,
BuildProducer<CamelBeanBuildItem> camelBean,
CamelKafkaRecorder recorder) {
BuildProducer<DevServicesConfigResultBuildItem> devServiceConfig) {

Config config = ConfigProvider.getConfig();
Optional<String> brokers = config.getOptionalValue("camel.component.kafka.brokers", String.class);
Optional<String> brokers = config.getOptionalValue(CAMEL_KAFKA_BROKERS, String.class);

if (brokers.isEmpty() && kafkaBuildTimeConfig.devservices.enabled.orElse(true)) {
camelBean.produce(new CamelBeanBuildItem(
"kafka",
KafkaComponent.class.getName(),
recorder.createKafkaComponentForDevServices(kafkaBrokerBuildItem.getBootstrapServers())));
devServiceConfig.produce(new DevServicesConfigResultBuildItem(CAMEL_KAFKA_BROKERS,
kafkaBrokerBuildItem.getBootstrapServers()));
}
}
}
@@ -34,7 +34,8 @@ public class KafkaDevServicesDisabledTest {
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
.withConfigurationResource("application-configuration-devservices-disabled.properties")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
.overrideConfigKey("camel.component.kafka.brokers", "");

@Inject
CamelContext context;

This file was deleted.

0 comments on commit 0caa4c4

Please sign in to comment.