이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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
    Copy to Clipboard Toggle word wrap

    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}
    Copy to Clipboard Toggle word wrap
  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"}]}
    Copy to Clipboard Toggle word wrap

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>
    Copy to Clipboard Toggle word wrap
    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>
    Copy to Clipboard Toggle word wrap
    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();
        }
     }
    Copy to Clipboard Toggle word wrap
    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

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat