Schema Management with the .NET Client

Tip
The source code for this tutorial is available on GitHub.

This tutorial demonstrates how to register and manage Protobuf schemas on the Infinispan server using the .NET Hot Rod client.

Prerequisites

  • A running Infinispan server.

  • .NET 10 or later.

Running the Example

dotnet run --project schemas

Code Walkthrough

Registering a Schema

Use CreateOrUpdate to register a .proto schema on the server. Invalid schemas are rejected with an error.

var schemas = client.Administration().Schemas();

await schemas.CreateOrUpdate("greeting.proto", """
    syntax = "proto2";
    message Greeting {
        required string name = 1;
        optional string text = 2;
    }
    """);

Error Handling

When you attempt to register an invalid schema, the server returns an error.

try
{
    await schemas.CreateOrUpdate("invalid.proto", "not a valid .proto file");
}
catch (Exception ex)
{
    Console.WriteLine($"Invalid schema rejected: {ex.Message}");
}

Expected Output

Invalid schema rejected: ...
Schema 'greeting.proto' registered.
Schemas deleted.