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)

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