Menu Close

Chapter 4. Managing artifacts in Service Registry

This chapter provides details on different approaches to managing artifacts in Service Registry:

4.1. Managing artifacts using the Registry REST API

The Registry REST API enables client applications to manage artifacts in the registry, for example, in a CI/CD pipeline deployed in production. This REST API provides create, read, update, and delete operations for artifacts, versions, metadata, and rules stored in the registry.

When creating artifacts in Service Registry using the REST API, if you do not specify a unique artifact ID, Service Registry generates one automatically as a UUID.

This chapter shows a simple curl-based example of using the Registry REST API to create and retrieve a Apache Avro schema artifact in the registry.

Prerequisites

Procedure

  1. Create an artifact in the registry using the /artifacts operation. The following example curl command creates a simple artifact for a share price application:

    $ 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"}]}' http://MY-REGISTRY-HOST/artifacts

    This example shows creating an Avro schema artifact with an artifact ID of share-price.

    MY-REGISTRY-HOST is the host name on which Service Registry is deployed. For example: my-cluster-service-registry-myproject.example.com.

  2. Verify that the response includes the expected JSON body to confirm that the artifact was created. For example:

    {"createdOn":1578310374517,"modifiedOn":1578310374517,"id":"share-price","version":1,"type":"AVRO","globalId":8}
  3. Retrieve the artifact from the registry using its artifact ID. For example, in this case the specified ID is share-price:

    $ curl https://MY-REGISTRY-URL/artifacts/share-price
    '{"type":"record","name":"price","namespace":"com.example","fields":[{"name":"symbol","type":"string"},{"name":"price","type":"string"}]}

Additional resources

4.2. Managing artifacts using the Service Registry Maven plug-in

Service Registry provides a Maven plug-in to enable you to upload or download registry artifacts as part of your development build. For example, this plug-in is useful for testing and validating that your schema updates are compatible with client applications.

Prerequisites

  • Service Registry must be installed and running in your environment
  • Maven must be installed and configured in your environment

Procedure

  1. Update your Maven pom.xml file to use the apicurio-registry-maven-plugin to upload an artifact. The following example shows registering an Apache Avro schema artifact:

    <plugin>
    <groupId>io.apicurio</groupId>
    <artifactId>apicurio-registry-maven-plugin</artifactId>
    <version>${registry.version}</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <goals>
          <goal>register</goal> 1
        </goals>
        <configuration>
          <registryUrl>https://my-cluster-service-registry-myproject.example.com</registryUrl> 2
          <artifactType>AVRO</artifactType>
          <artifacts>
            <schema1>${project.basedir}/schemas/schema1.avsc</schema1> 3
          </artifacts>
        </configuration>
      </execution>
    </executions>
    </plugin>
    1
    Specify register as the execution goal to upload an artifact to the registry.
    2
    You must specify the Service Registry URL.
    3
    You can upload multiple artifacts using the artifact ID and location.
  2. You can also update your Maven pom.xml file to download a previously registered artifact:

    <plugin>
    <groupId>io.apicurio</groupId>
    <artifactId>apicurio-registry-maven-plugin</artifactId>
    <version>${registry.version}</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <goals>
          <goal>download</goal> 1
        </goals>
        <configuration>
          <registryUrl>https://my-cluster-service-registry-myproject.example.com</registryUrl> 2
              <ids>
                <param1>schema1</param1> 3
              </ids>
          <outputDirectory>${project.build.directory}</outputDirectory>
       </configuration>
     </execution>
    </executions>
    </plugin>
    1
    Specify download as the execution goal.
    2
    You must specify the Service Registry URL.
    3
    You can download multiple artifacts to a specified directory using the artifact ID.

Additional resources

4.3. Managing artifacts in a Java client application

You can also manage artifacts in the registry using a Java client application. The Service Registry Java client classes enable you to create, read, update, or delete artifacts in the registry.

Prerequisites

  • See Section 1.1.5, “Client serializers/deserializers”
  • You must have implemented a client application in Java that imports the Service Registry client classes: io.apicurio.registry.client.RegistryClient
  • Service Registry must be installed and running in your environment.

Procedure

  • Update your client application to create a new artifact in the registry. The following example shows creating an Apache Avro schema artifact from a Kafka producer client application:

    String registryUrl_node1 = PropertiesUtil.property(clientProperties, "registry.url.node1",
      "https://my-cluster-service-registry-myproject.example.com"); 1
       try (RegistryService service = RegistryClient.create(registryUrl_node1))
       {
        String artifactId = ApplicationImpl.INPUT_TOPIC + "-value";
        try {
         service.getArtifactMetaData(artifactId); 2
        }
        catch (WebApplicationException e) {
         CompletionStage < ArtifactMetaData > csa = service.createArtifact( 3
            ArtifactType.AVRO,
            artifactId,
             new ByteArrayInputStream(LogInput.SCHEMA$.toString().getBytes())
            );
        csa.toCompletableFuture().get();
        }
     }
    1
    Configure the client application with the Service Registry URL in the client properties. You can create properties for more than one registry node.
    2
    Check to see if the schema artifact already exists in the registry based on the artifact ID.
    3
    Create the new schema artifact in the registry.

Additional resources