Interface ISchemaTypeResolver
Resolves Schema Registry schema IDs to .NET types.
public interface ISchemaTypeResolver
- Extension Methods
Remarks
This interface bridges the Schema Registry (which stores schemas by ID) with
the .NET type system. It uses the JSON Schema title property to map
schemas to registered .NET types.
Resolution Flow:
- Extract schema ID from wire format header
- Fetch schema from Schema Registry
- Parse
titleproperty from JSON Schema - Look up registered .NET type by message type name
- Cache resolution for O(1) subsequent lookups
Methods
IsTypeRegistered(string)
Gets a value indicating whether a type is registered for the given message type name.
bool IsTypeRegistered(string messageTypeName)
Parameters
messageTypeNamestringThe message type name to check.
Returns
RegisterType(Type)
Registers a message type for schema resolution.
void RegisterType(Type messageType)
Parameters
messageTypeTypeThe message type to register.
Remarks
Runtime type registration for scenarios where the type is only known at runtime.
RegisterType(Type, string)
Registers a message type for schema resolution with a custom type name.
void RegisterType(Type messageType, string messageTypeName)
Parameters
messageTypeTypeThe message type to register.
messageTypeNamestringThe message type name to use for matching.
RegisterType<T>()
Registers a message type for schema resolution.
void RegisterType<T>() where T : IDispatchMessage
Type Parameters
TThe message type to register.
Remarks
The type name is extracted from the type and used for matching against
the JSON Schema title property. Call this method at startup for
all message types that may be received.
RegisterType<T>(string)
Registers a message type for schema resolution with a custom type name.
void RegisterType<T>(string messageTypeName) where T : IDispatchMessage
Parameters
messageTypeNamestringThe message type name to use for matching.
Type Parameters
TThe message type to register.
Remarks
Use this overload when the .NET type name differs from the schema title.
ResolveTypeAsync(int, string, CancellationToken)
Resolves a schema ID to a .NET type.
Task<SchemaTypeResolution> ResolveTypeAsync(int schemaId, string subject, CancellationToken cancellationToken)
Parameters
schemaIdintThe Schema Registry schema ID.
subjectstringThe subject name (for logging/diagnostics).
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<SchemaTypeResolution>
The type resolution result.
Exceptions
- SchemaRegistryException
The schema could not be fetched from the registry.