Schema Administration

What You Will Learn

How to use the RemoteSchemasAdmin API to programmatically manage Protobuf schemas on an Infinispan Server: create, update, retrieve, check existence, and remove schemas.

Prerequisites

  • Java 17+

  • An Infinispan Server running on localhost:11222 (or Docker/Podman available for Testcontainers)

Start an Infinispan Server with Docker or Podman:

docker run -it --rm -p 11222:11222 -e USER=admin -e PASS=password quay.io/infinispan/server:latest
Tip
You can replace docker with podman in the command above if you use Podman.
Tip
If no server is running, the tutorial code automatically starts an Infinispan Server using Testcontainers.

Step 1: Get the Schema Admin API

Connect to the server and obtain the RemoteSchemasAdmin instance:

      // Connect to the server
      remoteCacheManager = TutorialsConnectorHelper.connect();
      schemasAdmin = remoteCacheManager.administration().schemas();

Step 2: Create or Update a Schema

Create a schema from a string content to see how error handling works, then fix the schema using the Schema.Builder API:

   static RemoteSchemasAdmin.SchemaOpResult createSchemaWithError() {
      return schemasAdmin.createOrUpdate(Schema.
            buildFromStringContent(SCHEMA_NAME, "What is love?"));
   }

   static RemoteSchemasAdmin.SchemaOpResult updateSchemaWithCorrections() {
      Schema schema = new Schema.Builder(SCHEMA_NAME)
            .packageName("hello")
            .addMessage("Greeting")
            .addField(Type.Scalar.STRING, "content", 1)
            .build();
      RemoteSchemasAdmin.SchemaOpResult result =
            schemasAdmin.createOrUpdate(schema);
     return result;
   }

The createOrUpdate method returns a SchemaOpResult that indicates success or errors.

Step 3: Retrieve, Check, and Remove Schemas

Get a schema by name, check if it exists, and remove it:

   static Optional<Schema> getOptionalSchema() {
      Optional<Schema> schemaOpt = schemasAdmin.get(SCHEMA_NAME);
      return schemaOpt;
   }

   static RemoteSchemasAdmin.SchemaOpResult removeSchema() {
      RemoteSchemasAdmin.SchemaOpResult result;
      result = schemasAdmin.remove(SCHEMA_NAME);
      return result;
   }

   static boolean schemaExists() {
      return schemasAdmin.exists(SCHEMA_NAME);
   }

Step 4: Run the Tutorial

mvn package exec:java

What’s Next