Questo contenuto non è disponibile nella lingua selezionata.
Chapter 5. Managing Service Registry content using the Maven plug-in
When developing client applications, you can use the Service Registry Maven plug-in to manage schema and API artifacts stored in Service Registry:
- Section 5.1, “Adding schema and API artifacts using the Maven plug-in”
- Section 5.2, “Downloading schema and API artifacts using the Maven plug-in”
- Section 5.3, “Testing schema and API artifacts using the Maven plug-in”
- Section 5.4, “Adding artifact references manually using the Service Registry Maven plug-in”
- Section 5.5, “Adding artifact references automatically using the Service Registry Maven plug-in”
Prerequisites
- Service Registry is installed and running in your environment.
- Apache Maven is installed and configured in your environment.
5.1. Adding schema and API artifacts using the Maven plug-in Copia collegamentoCollegamento copiato negli appunti!
The most common use case for the Maven plug-in is adding artifacts during a build of your client application. You can accomplish this by using the register
execution goal.
Prerequisites
- You have created a Maven project for your client application. For more details, see the Apache Maven documentation.
Procedure
Update your Maven
pom.xml
file to use theapicurio-registry-maven-plugin
to register an artifact. The following example shows registering Apache Avro and GraphQL schemas:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify
register
as the execution goal to upload the schema artifact to Service Registry. - 2
- Specify the Service Registry URL with the
../apis/registry/v2
endpoint. - 3
- If authentication is required, you can specify your authentication server and client credentials.
- 4
- Specify the Service Registry artifact group ID. You can specify the
default
group if you do not want to use a unique group ID. - 5
- You can register multiple artifacts using the specified group ID, artifact ID, and location.
-
Build your Maven project, for example, by using the
mvn package
command.
5.2. Downloading schema and API artifacts using the Maven plug-in Copia collegamentoCollegamento copiato negli appunti!
You can use the Maven plug-in to download artifacts from Service Registry. This is often useful, for example, when generating code from a registered schema.
Prerequisites
- You have created a Maven project for your client application. For more details, see the Apache Maven documentation.
Procedure
Update your Maven
pom.xml
file to use theapicurio-registry-maven-plugin
to download an artifact. The following example shows downloading Apache Avro and GraphQL schemas.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify
download
as the execution goal. - 2
- Specify the Service Registry URL with the
../apis/registry/v2
endpoint. - 3
- If authentication is required, you can specify your authentication server and client credentials.
- 4
- Specify the Service Registry artifact group ID. You can specify the
default
group if you do not want to use a unique group. - 5
- You can download multiple artifacts to a specified directory using the artifact ID.
-
Build your Maven project, for example, by using the
mvn package
command.
5.3. Testing schema and API artifacts using the Maven plug-in Copia collegamentoCollegamento copiato negli appunti!
You might want to verify that an artifact can be registered without actually making any changes. This is often useful when rules are configured in Service Registry. Testing the artifact results in a failure if the artifact content violates any of the configured rules.
When testing artifacts using the Maven plug-in, even if the artifact passes the test, no content is added to Service Registry.
Prerequisites
- You have created a Maven project for your client application. For more details, see the Apache Maven documentation.
Procedure
Update your Maven
pom.xml
file to use theapicurio-registry-maven-plugin
to test an artifact. The following example shows testing an Apache Avro schema:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify
test-update
as the execution goal to test the schema artifact. - 2
- Specify the Service Registry URL with the
../apis/registry/v2
endpoint. - 3
- If authentication is required, you can specify your authentication server and client credentials.
- 4
- Specify the Service Registry artifact group ID. You can specify the
default
group if you do not want to use a unique group. - 5
- You can test multiple artifacts from a specified directory using the artifact ID.
-
Build your Maven project, for example, by using the
mvn package
command.
5.4. Adding artifact references manually using the Service Registry Maven plug-in Copia collegamentoCollegamento copiato negli appunti!
Service Registry artifact types such as Apache Avro, Google Protobuf, and JSON Schema can include artifact references from one artifact file to another. You can create efficiencies by defining reusable schema or API artifacts, and then referencing them from multiple locations in artifact references.
This section shows a simple example of using the Service Registry Maven plug-in to manually register an artifact reference to a simple Avro schema artifact stored in Service Registry. This example assumes that the following Exchange
schema artifact has already been created in Service Registry:
Exchange schema
This example then creates a TradeKey
schema artifact, which includes a reference to the nested Exchange
schema artifact:
TradeKey schema with nested reference to Exchange schema
Prerequisites
- You have created a Maven project for your client application. For more details, see the Apache Maven documentation.
-
The referenced
Exchange
schema artifact is already created in Service Registry.
Procedure
Update your Maven
pom.xml
file to use theapicurio-registry-maven-plugin
to register theTradeKey
schema, which includes a nested reference to theExchange
schema as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify
register
as the execution goal to upload the schema artifacts to Service Registry. - 2
- Specify the Service Registry URL by using the
../apis/registry/v2
endpoint. - 3
- If authentication is required, you can specify your authentication server and client credentials.
- 4
- Specify the Service Registry artifact group ID. You can specify the
default
group if you do not want to use a unique group ID. - 5
- Specify the Service Registry artifact reference using its group ID, artifact ID, version, type, and location. You can register multiple artifact references in this way.
-
Build your Maven project, for example, by using the
mvn package
command.
5.5. Adding artifact references automatically using the Service Registry Maven plug-in Copia collegamentoCollegamento copiato negli appunti!
Service Registry artifact types such as Apache Avro, Google Protobuf, and JSON Schema can include artifact references from one artifact file to another. You can create efficiencies by defining reusable schema or API artifacts, and then referencing them from multiple locations in artifact references.
You can specify a single artifact and configure the Service Registry Maven plugin to automatically detect all references to artifacts located in the same directory, and to automatically register those references.
This section shows a simple example of using the Maven plug-in to register an Avro schema and automatically detect and register an artifact reference to a simple schema artifact. This example assumes that the parent TradeKey
artifact and the nested Exchange
schema artifact are both available in the same directory:
TradeKey schema with nested reference to Exchange schema
Exchange schema
Prerequisites
- You have created a Maven project for your client application. For more details, see the Apache Maven documentation.
-
The
TradeKey
schema artifact and the nestedExchange
schema artifact files are both located in the same directory.
Procedure
Update your Maven
pom.xml
file to use theapicurio-registry-maven-plugin
to register theTradeKey
schema, which includes a nested reference to theExchange
schema as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify
register
as the execution goal to upload the schema artifacts to Service Registry. - 2
- Specify the Service Registry URL by using the
../apis/registry/v2
endpoint. - 3
- If authentication is required, you can specify your authentication server and client credentials.
- 4
- Specify the parent artifact group ID that contains the references. You can specify the
default
group if you do not want to use a unique group ID. - 5
- Specify the location of the parent artifact file. All referenced artifacts must also be located in the same directory.
- 6
- Set the
<analyzeDirectory>
option to true to automatically detect and register all references to artifacts in the same directory. You can register multiple artifact references in this way.
-
Build your Maven project, for example, by using the
mvn package
command.