Skip to content

Commit

Permalink
Add support for more version of the Confluent Schema Registry serde
Browse files Browse the repository at this point in the history
Also extract the documentation in a separate version
Fixes #26428
  • Loading branch information
cescoffier committed Jul 18, 2022
1 parent c5adb46 commit 203b46c
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 65 deletions.
146 changes: 82 additions & 64 deletions docs/src/main/asciidoc/kafka-schema-registry-avro.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,70 +53,7 @@ include::{includes}/devtools/create-app.adoc[]
====
If you use Confluent Schema Registry, you don't need the `quarkus-apicurio-registry-avro` extension.
Instead, you need the `quarkus-confluent-registry-avro` extension and a few more dependencies.
Also, you need to add the Confluent Maven repository to your build file:
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependencies>
...
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-confluent-registry-avro</artifactId>
</dependency>
<!-- Confluent registry libraries use JAX-RS client -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>6.1.1</version>
<exclusions>
<exclusion>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
----
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
repositories {
...
maven {
url "https://packages.confluent.io/maven/"
}
}
dependencies {
...
implementation("io.quarkus:quarkus-confluent-registry-avro")
// Confluent registry libraries use JAX-RS client
implementation("io.quarkus:quarkus-rest-client-reactive")
implementation("io.confluent:kafka-avro-serializer:6.1.1") {
exclude group: "jakarta.ws.rs", module: "jakarta.ws.rs-api"
}
}
----
See <<confluent>> for details.
====

== Avro schema
Expand Down Expand Up @@ -673,6 +610,87 @@ public class MovieResourceTest {
}
----

[[confluent]]
== Using the Confluent Schema Registry

If you want to use the Confluent Schema Registry, you need the `quarkus-confluent-registry-avro` extension, instead of the `quarkus-apicurio-registry-avro` extension.
Also, you need to add a few dependencies and a custom Maven repository to your `pom.xml` / `build.gradle` file:

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependencies>
...
<!-- the extension -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-confluent-registry-avro</artifactId>
</dependency>
<!-- Confluent registry libraries use JAX-RS client -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.2.0</version>
<exclusions>
<exclusion>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<!-- io.confluent:kafka-avro-serializer is only available from this repository: -->
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
----

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
repositories {
...
maven {
url "https://packages.confluent.io/maven/"
}
}
dependencies {
...
implementation("io.quarkus:quarkus-confluent-registry-avro")
// Confluent registry libraries use JAX-RS client
implementation("io.quarkus:quarkus-rest-client-reactive")
implementation("io.confluent:kafka-avro-serializer:7.2.0") {
exclude group: "jakarta.ws.rs", module: "jakarta.ws.rs-api"
}
}
----

In JVM mode, any version of `io.confluent:kafka-avro-serializer` can be used.
In native mode, Quarkus only supports the following versions:

* 6.2.x
* 7.0.x
* 7.1.x
* 7.2.x

For any other versions, the native configuration may need to be adjusted.

== Avro code generation details

In this guide we used the Quarkus code generation mechanism to generate Java files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
package io.quarkus.confluent.registry.avro;

import java.util.Collection;
import java.util.Optional;
import java.util.function.Predicate;

import org.jboss.logging.Logger;

import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.maven.dependency.ResolvedDependency;

public class ConfluentRegistryAvroProcessor {

public static final String CONFLUENT_GROUP_ID = "io.confluent";
public static final String CONFLUENT_ARTIFACT_ID = "kafka-avro-serializer";

private static final Logger LOGGER = Logger.getLogger(ConfluentRegistryAvroProcessor.class.getName());
public static final String CONFLUENT_REPO = "https://packages.confluent.io/maven/";
public static final String GUIDE_URL = "https://quarkus.io/guides/kafka-schema-registry-avro";

@BuildStep
FeatureBuildItem feature() {
FeatureBuildItem featureAndCheckDependency(CurateOutcomeBuildItem cp) {
if (findConfluentSerde(cp.getApplicationModel().getDependencies()).isEmpty()) {
LOGGER.warnf("The application uses the `quarkus-confluent-registry-avro` extension, but does not " +
"depend on `%s:%s`. Note that this dependency is only available from the `%s` Maven " +
"repository. Check %s for more details.",
CONFLUENT_GROUP_ID, CONFLUENT_ARTIFACT_ID, CONFLUENT_REPO, GUIDE_URL);
}

return new FeatureBuildItem(Feature.CONFLUENT_REGISTRY_AVRO);
}

Expand All @@ -22,9 +46,31 @@ public void confluentRegistryAvro(BuildProducer<ReflectiveClassBuildItem> reflec
"io.confluent.kafka.serializers.KafkaAvroSerializer"));
}

@BuildStep
public void configureNative(BuildProducer<NativeImageConfigBuildItem> config, CurateOutcomeBuildItem cp) {
Optional<ResolvedDependency> serde = findConfluentSerde(cp.getApplicationModel().getDependencies());
if (serde.isPresent()) {
String version = serde.get().getVersion();
if (version.startsWith("7.1") || version.startsWith("7.2")) {
// Only required for Confluent Serde 7.1.x and 7.2.x
config.produce(NativeImageConfigBuildItem.builder()
.addRuntimeInitializedClass("io.confluent.kafka.schemaregistry.client.rest.utils.UrlList").build());
}
}
}

@BuildStep
ExtensionSslNativeSupportBuildItem enableSslInNative() {
return new ExtensionSslNativeSupportBuildItem(Feature.CONFLUENT_REGISTRY_AVRO);
}

private Optional<ResolvedDependency> findConfluentSerde(Collection<ResolvedDependency> dependencies) {
return dependencies.stream().filter(new Predicate<ResolvedDependency>() {
@Override
public boolean test(ResolvedDependency rd) {
return rd.getGroupId().equalsIgnoreCase(CONFLUENT_GROUP_ID)
&& rd.getArtifactId().equalsIgnoreCase(CONFLUENT_ARTIFACT_ID);
}
}).findAny();
}
}

0 comments on commit 203b46c

Please sign in to comment.