/// <summary> /// Registers a schema with the SchemaRegistry service. /// If the schema did not previously exist in the Schema Registry instance, it is added to the instance and assigned a schema ID. /// If the schema did previous exist in the Schema Registry instance, a new version of the schema is added to the instance and assigned a new schema ID. /// </summary> /// <param name="groupName">The name of the SchemaRegistry group.</param> /// <param name="schemaName">The name of the schema.</param> /// <param name="serializationType">The serialization format of the schema.</param> /// <param name="schemaContent">The string representation of the schema's content.</param> /// <param name="cancellationToken">The cancellation token for the operation.</param> /// <returns>The properties of the schema.</returns> public virtual Response <SchemaProperties> RegisterSchema(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope(RegisterSchemaScopeName); scope.Start(); try { var response = RestClient.Register(groupName, schemaName, serializationType, schemaContent, cancellationToken); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return(Response.FromValue(properties, response)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Gets the schema content associated with the schema ID from the SchemaRegistry service. /// </summary> /// <param name="schemaId">The schema ID of the the schema from the SchemaRegistry.</param> /// <param name="cancellationToken">The cancellation token for the operation.</param> /// <returns>The properties of the schema, including the schema content provided by the service.</returns> public virtual Response <SchemaProperties> GetSchema(string schemaId, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaScopeName); scope.Start(); try { var response = RestClient.GetById(schemaId, cancellationToken); var properties = new SchemaProperties(response.Value, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return(Response.FromValue(properties, response)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Gets the schema ID associated with the schema from the SchemaRegistry service. /// </summary> /// <param name="groupName">The name of the SchemaRegistry group.</param> /// <param name="schemaName">The name of the schema.</param> /// <param name="serializationType">The serialization format of the schema.</param> /// <param name="schemaContent">The string representation of the schema's content.</param> /// <param name="cancellationToken">The cancellation token for the operation.</param> /// <returns>The properties of the schema, including the schema ID provided by the service.</returns> public virtual async Task <Response <SchemaProperties> > GetSchemaIdAsync(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaIdScopeName); scope.Start(); try { var response = await RestClient.QueryIdByContentAsync(groupName, schemaName, serializationType, schemaContent, cancellationToken).ConfigureAwait(false); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return(Response.FromValue(properties, response)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Gets the schema ID associated with the schema from the SchemaRegistry service. /// </summary> /// <param name="groupName">The name of the SchemaRegistry group.</param> /// <param name="schemaName">The name of the schema.</param> /// <param name="serializationType">The serialization format of the schema.</param> /// <param name="schemaContent">The string representation of the schema's content.</param> /// <param name="cancellationToken">The cancellation token for the operation.</param> /// <returns>The properties of the schema, including the schema ID provided by the service.</returns> public virtual Response <SchemaProperties> GetSchemaId(string groupName, string schemaName, SerializationType serializationType, string schemaContent, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaIdScopeName); scope.Start(); try { var jsonStringSchemaContent = string.Format(CultureInfo.InvariantCulture, JsonStringMask, JsonEncodedText.Encode(schemaContent, JavaScriptEncoder.UnsafeRelaxedJsonEscaping)); var response = RestClient.QueryIdByContent(groupName, schemaName, serializationType, jsonStringSchemaContent, cancellationToken); var properties = new SchemaProperties(schemaContent, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return(Response.FromValue(properties, response)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Gets the schema content associated with the schema ID from the SchemaRegistry service. /// </summary> /// <param name="schemaId">The schema ID of the the schema from the SchemaRegistry.</param> /// <param name="cancellationToken">The cancellation token for the operation.</param> /// <returns>The properties of the schema, including the schema content provided by the service.</returns> public virtual async Task <Response <SchemaProperties> > GetSchemaAsync(string schemaId, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaScopeName); scope.Start(); try { var response = await RestClient.GetByIdAsync(schemaId, cancellationToken).ConfigureAwait(false); using var reader = new StreamReader(response.Value); var content = await reader.ReadToEndAsync().ConfigureAwait(false); var properties = new SchemaProperties(content, response.Headers.Location, response.Headers.XSchemaType, response.Headers.XSchemaId, response.Headers.XSchemaVersion); return(Response.FromValue(properties, response)); } catch (Exception e) { scope.Failed(e); throw; } }