Embed native image config#25883
Open
david-streamlio wants to merge 2 commits into
Open
Conversation
Add META-INF/native-image configuration files (reflect-config.json, resource-config.json, native-image.properties) so that GraalVM's native-image tool can build applications using the Pulsar client without framework-specific configuration. Includes a test (NativeImageConfigTest) that validates all referenced classes exist on the classpath and all Authentication implementations are registered, so the config does not drift silently as the codebase evolves. This eliminates the need for downstream frameworks (Quarkus, Micronaut, Spring Native) to independently maintain reflection and class initialization metadata for Pulsar client internals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Main Issue: quarkusio/quarkus#48776
Motivation
Applications using
pulsar-client-originalin GraalVM native-image builds currently fail unless the consuming framework (Quarkus, Micronaut, Spring Native, etc.) provides its own reflection and class initialization metadata for Pulsar client internals. This forces every framework to independently reverse-engineer and maintain configuration that tracks Pulsar's internal class layout — and when it drifts, native builds break silently.A concrete example: Quarkus's Pulsar extension registered
org.apache.pulsar.client.util.WithSNISslEngineFactoryfor runtime initialization, but that class was removed in Pulsar 4.x. Because the configuration lived downstream instead of in the client itself, the breakage went unnoticed for a year (quarkusio/quarkus#48776).Embedding the configuration directly in
pulsar-client-originalfollowingthe GraalVM embedded configuration convention means the
native-imagetool picks it up automatically from the classpath, keeping the config in sync with the code that owns the classes.Modifications
Added three GraalVM native-image configuration files under
pulsar-client/src/main/resources/META-INF/native-image/org.apache.pulsar/pulsar-client-original/:reflect-config.json — Registers 20 classes for reflective access:
the three
ConfigurationDataclasses (deserialized by Jackson), all sixAuthenticationimplementations (instantiated by name viaAuthenticationUtil.create()), the OAuth2 protocol model classes, schemainternals (
ProtoBufParsingInfo,ProtobufNativeSchemaData,KeyValue),DataURLStreamHandler, andSecretsSerializer.native-image.properties — Marks eight classes for runtime
initialization that would otherwise fail during native-image build due to
eager static initialization of Netty allocators, thread pools, or HTTP
clients:
PulsarByteBufAllocator,Commands,Backoff,TokenClient,GenericProtobufNativeSchema,ConnectionPool,ControlledClusterFailover, andHttpClient.resource-config.json — Includes the async-http-client default
properties files that are loaded via classloader at runtime.
Added
NativeImageConfigTestthat validates:reflect-config.jsonexist on the classpathnative-image.propertiesexist on the classpathAuthenticationimplementations shipped with the client are registeredThis test catches configuration drift early — if a class is renamed, removed, or a new
Authenticationplugin is added without updating the config, the test fails with a descriptive message.Note: the shaded
pulsar-clientJAR intentionally stripsMETA-INF/native-image/**in its shade plugin filters, which is correct since shading relocates packages and invalidates the original class names. Users building native images should depend onpulsar-client-original.Verifying this change
This change added tests and can be verified as follows:
NativeImageConfigTestthat validates all 20 reflection entries and8 runtime-initialized classes resolve on the classpath, and that all
Authenticationimplementations are registered.source tree.
SmallRyeReactiveMessagingPulsarProcessor) was validated by successfullycompiling six native-image integration tests in the Quarkus
integration-tests/reactive-messaging-pulsarmodule against Pulsar 4.2.1.Does this pull request potentially affect one of the following parts:
Documentation
doc-not-needed