quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Kafka DevService return null when reloading application in quarkus:dev #21342

Closed zhfeng closed 2 years ago

zhfeng commented 2 years ago

Describe the bug

This issue comes across https://github.com/apache/camel-quarkus/issues/3284 It throws the NPE when runing with mvn quarkus:dev

I think it might be an issue in Quarkus DevServicesKafkaProcessor. https://github.com/quarkusio/quarkus/blob/362199e0638e86ab57aa7e0c1fadfa16f4766bd8/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java#L89-L96

It returns null when there is no changes with configuration which means no needs to restart the kafka container. That cause camel-quarkus-kafka KafkaProcessor to throw NPE.

Expected behavior

It needs to return the current broker url with DevServicesKafkaBrokerBuildItem.

Actual behavior

It returns null.

How to Reproduce?

please check https://github.com/tarilabs/quarkus-content-based-routing

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

quarkus-bot[bot] commented 2 years ago

/cc @cescoffier, @ozangunalp

cescoffier commented 2 years ago

Can't the KafkaProcessor handles null? Most dev services are doing this.

stuartwdouglas commented 2 years ago

Can't you just get this info from 'io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem' ? It contains all the resulting dev service properties.

zhfeng commented 2 years ago

Thanks @stuartwdouglas and we use the following codes to consumer DevServicesKafkaBrokerBuildItem

    @BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class)
    public void configureKafkaComponentForDevServices(
            DevServicesKafkaBrokerBuildItem kafkaBrokerBuildItem,
            KafkaBuildTimeConfig kafkaBuildTimeConfig,
            BuildProducer<RunTimeConfigurationDefaultBuildItem> runTimeConfig) {

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

        if (brokers.isEmpty() && kafkaBuildTimeConfig.devservices.enabled.orElse(true)) {
            runTimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(CAMEL_KAFKA_BROKERS,
                    kafkaBrokerBuildItem.getBootstrapServers()));
        }
    }

I'll try to use io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem to see if it works.

zhfeng commented 2 years ago

yeah, it should work and I wil fix it in camel-quarkus-kafka. Thanks all for helping !