Chapter 1. Introduction to Service Registry This chapter introduces Service Registry concepts and features and provides details on the supported artifact types that are stored in the registry: Section 1.1, "What is Service Registry?" Section 1.2, "Schema and API artifacts in Service Registry" Section 1.3, "Manage content using the Service Registry web console" Section 1.4, "Service Registry REST API for clients" Section 1.5, "Service Registry storage options" Section 1.6, "Validate Kafka messages using schemas and Java client serializers/deserializers" Section 1.7, "Stream data to external systems with Kafka Connect converters" Section 1.8, "Service Registry demonstration examples" Section 1.9, "Service Registry available distributions" 1.1. What is Service Registry? Service Registry is a datastore for sharing standard event schemas and API designs across event-driven and API architectures. You can use Service Registry to decouple the structure of your data from your client applications, and to share and manage your data types and API descriptions at runtime using a REST interface. Client applications can dynamically push or pull the latest schema updates to or from Service Registry at runtime without needing to redeploy. Developer teams can query Service Registry for existing schemas required for services already deployed in production, and can register new schemas required for new services in development. You can enable client applications to use schemas and API designs stored in Service Registry by specifying the Service Registry URL in your client application code. Service Registry can store schemas used to serialize and deserialize messages, which are referenced from your client applications to ensure that the messages that they send and receive are compatible with those schemas. Using Service Registry to decouple your data structure from your applications reduces costs by decreasing overall message size, and creates efficiencies by increasing consistent reuse of schemas and API designs across your organization. Service Registry provides a web console to make it easy for developers and administrators to manage registry content. You can configure optional rules to govern the evolution of your Service Registry content. These include rules to ensure that uploaded content is valid, or is compatible with other versions. Any configured rules must pass before new versions can be uploaded to Service Registry, which ensures that time is not wasted on invalid or incompatible schemas or API designs. Service Registry is based on the Apicurio Registry open source community project. For details, see https://github.com/apicurio/apicurio-registry . Service Registry capabilities Multiple payload formats for standard event schema and API specifications such as Apache Avro, JSON Schema, Google Protobuf, AsyncAPI, OpenAPI, and more. Pluggable Service Registry storage options in AMQ Streams or PostgreSQL database. Rules for content validation, compatibility, and integrity to govern how Service Registry content evolves over time. Service Registry content management using web console, REST API, command line, Maven plug-in, or Java client. Full Apache Kafka schema registry support, including integration with Kafka Connect for external systems. Kafka client serializers/deserializers (SerDes) to validate message types at runtime. Compatibility with existing Confluent schema registry client applications. Cloud-native Quarkus Java runtime for low memory footprint and fast deployment times. Operator-based installation of Service Registry on OpenShift. OpenID Connect (OIDC) authentication using Red Hat Single Sign-On. 1.2. Schema and API artifacts in Service Registry The items stored in Service Registry, such as event schemas and API designs, are known as registry artifacts . The following shows an example of an Apache Avro schema artifact in JSON format for a simple share price application: Example Avro schema { "type": "record", "name": "price", "namespace": "com.example", "fields": [ { "name": "symbol", "type": "string" }, { "name": "price", "type": "string" } ] } When a schema or API design is added as an artifact in Service Registry, client applications can then use that schema or API design to validate that the client messages conform to the correct data structure at runtime. Groups of schemas and APIs An artifact group is an optional named collection of schema or API artifacts. Each group contains a logically related set of schemas or API designs, typically managed by a single entity, belonging to a particular application or organization. You can create optional artifact groups when adding your schemas and API designs to organize them in Service Registry. For example, you could create groups to match your development and production application environments, or your sales and engineering organizations. Schema and API groups can contain multiple artifact types. For example, you could have Protobuf, Avro, JSON Schema, OpenAPI, or AsyncAPI artifacts all in the same group. You can create schema and API artifacts and groups using the Service Registry web console, REST API, command line, Maven plug-in, or Java client application. The following simple example shows using the Core Registry REST API: USD curl -X POST -H "Content-type: application/json; artifactType=AVRO" \ -H "X-Registry-ArtifactId: share-price" \ --data '{"type":"record","name":"price","namespace":"com.example", \ "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' \ https://my-registry.example.com/apis/registry/v2/groups/my-group/artifacts This example creates an artifact group named my-group and adds an Avro schema with an artifact ID of share-price . Note Specifying a group is optional when using the Service Registry web console, and a default group is created automatically. When using the REST API or Maven plug-in, specify the default group in the API path if you do not want to create a unique group. Additional resources For information on supported artifact types, see Chapter 9, Service Registry artifact reference . For information on the Core Registry API, see the Apicurio Registry REST API documentation . References to other schemas and APIs Some Service Registry artifact types can include artifact references from one artifact file to another. You can create efficiencies by defining reusable schema or API components, and then referencing them from multiple locations. For example, you can specify a reference in JSON Schema or OpenAPI using a USDref statement, or in Google Protobuf using an import statement, or in Apache Avro using a nested namespace. The following example shows a simple Avro schema named TradeKey that includes a reference to another schema named Exchange using a nested namespace: Tradekey schema with nested Exchange schema { "namespace": "com.kubetrade.schema.trade", "type": "record", "name": "TradeKey", "fields": [ { "name": "exchange", "type": "com.kubetrade.schema.common.Exchange" }, { "name": "key", "type": "string" } ] } Exchange schema { "namespace": "com.kubetrade.schema.common", "type": "enum", "name": "Exchange", "symbols" : ["GEMINI"] } An artifact reference is stored in Service Registry as a collection of artifact metadata that maps from an artifact type-specific reference to an internal Service Registry reference. Each artifact reference in Service Registry is composed of the following: Group ID Artifact ID Artifact version Artifact reference name You can manage artifact references using the Service Registry core REST API, Maven plug-in, and Java serializers/deserializers (SerDes). Service Registry stores the artifact references along with the artifact content. Service Registry also maintains a collection of all artifact references so you can search them or list all references for a specific artifact. Supported artifact types Service Registry currently supports artifact references for the following artifact types only: Avro Protobuf JSON Schema OpenAPI AsyncAPI Additional resources For details on managing artifact references, see: Chapter 4, Managing Service Registry content using the REST API . Chapter 5, Managing Service Registry content using the Maven plug-in . For a Java example, see the Apicurio Registry SerDes with references demonstration . 1.3. Manage content using the Service Registry web console You can use the Service Registry web console to browse and search the schema and API artifacts and optional groups stored in the registry, and to add new schema and API artifacts, groups, and versions. You can search for artifacts by label, name, group, and description. You can view an artifact's content or its available versions, or download an artifact file locally. You can also configure optional rules for registry content, both globally and for each schema and API artifact. These optional rules for content validation and compatibility are applied when new schema and API artifacts or versions are uploaded to the registry. For more details, see Chapter 10, Service Registry content rule reference . Figure 1.1. Service Registry web console The Service Registry web console is available from http://MY_REGISTRY_URL/ui . Additional resources Chapter 3, Managing Service Registry content using the web console 1.4. Service Registry REST API for clients Client applications can use the Core Registry API v2 to manage the schema and API artifacts in Service Registry. This API provides operations for the following features: Admin Export or import Service Registry data in a .zip file, and manage logging levels for the Service Registry instance at runtime. Artifacts Manage schema and API artifacts stored in Service Registry. You can also manage the lifecycle state of an artifact: enabled, disabled, or deprecated. Artifact metadata Manage details about a schema or API artifact. You can edit details such as artifact name, description, or labels. Details such as artifact group, and when the artifact was created or modified are read-only. Artifact rules Configure rules to govern the content evolution of a specific schema or API artifact to prevent invalid or incompatible content from being added to Service Registry. Artifact rules override any global rules configured. Artifact versions Manage versions that are created when a schema or API artifact is updated. You can also manage the lifecycle state of an artifact version: enabled, disabled, or deprecated. Global rules Configure rules to govern the content evolution of all schema and API artifacts to prevent invalid or incompatible content from being added to Service Registry. Global rules are applied only if an artifact does not have its own specific artifact rules configured. Search Browse or search for schema and API artifacts and versions, for example, by name, group, description, or label. System Get the Service Registry version and the limits on resources for the Service Registry instance. Users Get the current Service Registry user. Compatibility with other schema registry REST APIs Service Registry also provides compatibility with the following schema registries by including implementations of their respective REST APIs: Service Registry Core Registry API v1 Confluent Schema Registry API v6 Confluent Schema Registry API v7 CNCF CloudEvents Schema Registry API v0 Applications using Confluent client libraries can use Service Registry as a drop-in replacement. For more details, see Replacing Confluent Schema Registry . Additional resources For more information on the Core Registry API v2, see the Apicurio Registry REST API documentation . For API documentation on the Core Registry API v2 and all compatible APIs, browse to the /apis endpoint of your Service Registry instance, for example, http://MY-REGISTRY-URL/apis . 1.5. Service Registry storage options Service Registry provides the following options for the underlying storage of registry data: Table 1.1. Service Registry data storage options Storage option Description PostgreSQL database PostgreSQL is the recommended data storage option for performance, stability, and data management (backup/restore, and so on) in a production environment. AMQ Streams Kafka storage is provided for production environments where database management expertise is not available, or where storage in Kafka is a specific requirement. Additional resources For more details on storage options, see Installing and deploying Service Registry on OpenShift . 1.6. Validate Kafka messages using schemas and Java client serializers/deserializers Kafka producer applications can use serializers to encode messages that conform to a specific event schema. Kafka consumer applications can then use deserializers to validate that messages have been serialized using the correct schema, based on a specific schema ID. Figure 1.2. Service Registry and Kafka client SerDes architecture Service Registry provides Kafka client serializers/deserializers (SerDes) to validate the following message types at runtime: Apache Avro Google Protobuf JSON Schema The Service Registry Maven repository and source code distributions include the Kafka SerDes implementations for these message types, which Kafka client application developers can use to integrate with Service Registry. These implementations include custom Java classes for each supported message type, for example, io.apicurio.registry.serde.avro , which client applications can use to pull schemas from Service Registry at runtime for validation. Additional resources Chapter 7, Validating Kafka messages using serializers/deserializers in Java clients 1.7. Stream data to external systems with Kafka Connect converters You can use Service Registry with Apache Kafka Connect to stream data between Kafka and external systems. Using Kafka Connect, you can define connectors for different systems to move large volumes of data into and out of Kafka-based systems. Figure 1.3. Service Registry and Kafka Connect architecture Service Registry provides the following features for Kafka Connect: Storage for Kafka Connect schemas Kafka Connect converters for Apache Avro and JSON Schema Core Registry API to manage schemas You can use the Avro and JSON Schema converters to map Kafka Connect schemas into Avro or JSON schemas. These schemas can then serialize message keys and values into the compact Avro binary format or human-readable JSON format. The converted JSON is less verbose because the messages do not contain the schema information, only the schema ID. Service Registry can manage and track the Avro and JSON schemas used in the Kafka topics. Because the schemas are stored in Service Registry and decoupled from the message content, each message must only include a tiny schema identifier. For an I/O bound system like Kafka, this means more total throughput for producers and consumers. The Avro and JSON Schema serializers and deserializers (SerDes) provided by Service Registry are used by Kafka producers and consumers in this use case. Kafka consumer applications that you write to consume change events can use the Avro or JSON SerDes to deserialize these events. You can install the Service Registry SerDes in any Kafka-based system and use them along with Kafka Connect, or with a Kafka Connect-based system such as Debezium. Additional resources Configuring Debezium to use Avro serialization and Service Registry Example of using Debezium to monitor the PostgreSQL database used by Apicurio Registry Apache Kafka Connect documentation 1.8. Service Registry demonstration examples Service Registry provides open source example applications that demonstrate how to use Service Registry in different use case scenarios. For example, these include storing schemas used by Kafka serializer and deserializer (SerDes) Java classes. These classes fetch the schema from Service Registry for use when producing or consuming operations to serialize, deserialize, or validate the Kafka message payload. These applications demonstrate use cases such as the following examples: Apache Avro Kafka SerDes Apache Avro Maven plug-in Apache Camel Quarkus and Kafka CloudEvents Confluent Kafka SerDes Custom ID strategy Event-driven architecture with Debezium Google Protobuf Kafka SerDes JSON Schema Kafka SerDes REST clients Additional resources For more details, see https://github.com/Apicurio/apicurio-registry-examples 1.9. Service Registry available distributions Service Registry provides the following distribution options. Table 1.2. Service Registry Operator and images Distribution Location Release category Service Registry Operator OpenShift web console under Operators OperatorHub General Availability Container image for Service Registry Operator Red Hat Ecosystem Catalog General Availability Container image for Kafka storage in AMQ Streams Red Hat Ecosystem Catalog General Availability Container image for database storage in PostgreSQL Red Hat Ecosystem Catalog General Availability Table 1.3. Service Registry zip downloads Distribution Location Release category Example custom resource definitions for installation Red Hat Software Downloads General Availability Service Registry v1 to v2 migration tool Red Hat Software Downloads General Availability Maven repository Red Hat Software Downloads General Availability Source code Red Hat Software Downloads General Availability Kafka Connect converters Red Hat Software Downloads General Availability Note You must have a subscription for Red Hat Integration and be logged into the Red Hat Customer Portal to access the available Service Registry distributions.

Commands:
{ "type": "record", "name": "price", "namespace": "com.example", "fields": [ { "name": "symbol", "type": "string" }, { "name": "price", "type": "string" } ] }
curl -X POST -H "Content-type: application/json; artifactType=AVRO" -H "X-Registry-ArtifactId: share-price" --data '{"type":"record","name":"price","namespace":"com.example", "fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}' https://my-registry.example.com/apis/registry/v2/groups/my-group/artifacts
{ "namespace": "com.kubetrade.schema.trade", "type": "record", "name": "TradeKey", "fields": [ { "name": "exchange", "type": "com.kubetrade.schema.common.Exchange" }, { "name": "key", "type": "string" } ] }
{ "namespace": "com.kubetrade.schema.common", "type": "enum", "name": "Exchange", "symbols" : ["GEMINI"] }