Class ApicurioSchemaRegistryClient

java.lang.Object
com.aim2be.platform.schema.ApicurioSchemaRegistryClient
All Implemented Interfaces:
SchemaRegistryClient

public class ApicurioSchemaRegistryClient extends Object implements SchemaRegistryClient
Apicurio Registry implementation of SchemaRegistryClient (ADR-0011 §B, primary path).

Wraps a Spring-injected RegistryClient (Apicurio 2.5.x v2 REST API) plus a configured group ID. Every method emits an OpenTelemetry CLIENT span tagged with schema.registry=apicurio, schema.subject, schema.global_id (when known), and outcome=success|error.

Authentication is via mTLS through the Envoy/SPIRE sidecar (Stage B L0 Tranche-0); no in-process credential material is held by this client. The registry URL + group ID come from SchemaRegistryProperties.

  • Constructor Details

    • ApicurioSchemaRegistryClient

      public ApicurioSchemaRegistryClient(io.apicurio.registry.rest.client.RegistryClient delegate, String groupId, String compatibility, io.opentelemetry.api.OpenTelemetry openTelemetry)
      Parameters:
      delegate - the Apicurio v2 REST client; not null
      groupId - the artifact group ID under which subjects live; not null. Apicurio v2 namespaces every artifact under a group; the platform default is default per SchemaRegistryProperties.getGroupId().
      compatibility - the compatibility rule to enforce on EVERY registered artifact (BACKWARD, FORWARD, FULL, NONE; case- insensitive). Applied via Apicurio's per-artifact rule API on first registration; subsequent registrations are validated against this rule server-side. Pass null or blank to skip rule application (matches the legacy "no compatibility enforcement" behaviour).
      openTelemetry - OpenTelemetry instance for tracer acquisition; not null. Tests pass OpenTelemetry.noop() to silence spans.
  • Method Details

    • register

      public long register(String subject, byte[] schemaBytes, SchemaRegistryClient.SchemaType type)
      Description copied from interface: SchemaRegistryClient
      Registers schemaBytes under subject, returning the registry-assigned global ID.

      Idempotent: a re-registration of identical bytes returns the same global ID (Apicurio's IfExists=RETURN_OR_UPDATE semantics).

      Specified by:
      register in interface SchemaRegistryClient
      Parameters:
      subject - the subject name (typically <topic>-value or <topic>-key per ADR-0011 §B)
      schemaBytes - the schema body bytes; UTF-8 JSON for Avro/JSON, binary for Protobuf; must be non-null
      type - the schema type (AVRO / PROTOBUF / JSON)
      Returns:
      the registry-assigned global ID
    • fetchByGlobalId

      public SchemaRegistryClient.Schema fetchByGlobalId(long globalId)
      Description copied from interface: SchemaRegistryClient
      Fetches a schema by registry global ID.
      Specified by:
      fetchByGlobalId in interface SchemaRegistryClient
      Parameters:
      globalId - the global ID returned by a prior SchemaRegistryClient.register(java.lang.String, byte[], com.aim2be.platform.schema.SchemaRegistryClient.SchemaType) call
      Returns:
      the schema record, or null if no such globalId. Sentinel-field contract: the Apicurio v2 REST API has no direct globalId → (subject, version) lookup, so impls that hydrate via the content-by-globalId endpoint return a SchemaRegistryClient.Schema with subject="" and version=0 as sentinels. Callers that need subject/version coordinates must use SchemaRegistryClient.fetchLatestBySubject(String) instead.
    • fetchLatestBySubject

      public SchemaRegistryClient.Schema fetchLatestBySubject(String subject)
      Description copied from interface: SchemaRegistryClient
      Fetches the latest schema body registered under subject.
      Specified by:
      fetchLatestBySubject in interface SchemaRegistryClient
      Parameters:
      subject - the subject name
      Returns:
      the schema record, or null if no such subject
    • kind

      Description copied from interface: SchemaRegistryClient
      Returns the implementation kind. Used for observability tagging (the kind shows up as schema.registry on every OTel span this client emits) and for callers that need to choose between Apicurio globalId semantics and Confluent schemaId semantics in their producer code path.
      Specified by:
      kind in interface SchemaRegistryClient
      Returns:
      the implementation kind; never null
    • getGroupId

      public String getGroupId()
      Returns:
      the artifact group ID under which this client operates; never null. Useful for diagnostic logging.
    • getDelegate

      public io.apicurio.registry.rest.client.RegistryClient getDelegate()
      Returns:
      the underlying Apicurio v2 REST client. Exposed for the DualSchemaRegistryClient coordinator to share a single RegistryClient bean across primary + fallback paths.