예제 #1
0
        private async Task <Response <SchemaRegistrySchema> > GetSchemaInternalAsync(string schemaId, bool async, CancellationToken cancellationToken)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaScopeName);
            scope.Start();
            try
            {
                ResponseWithHeaders <Stream, SchemaGetByIdHeaders> response;
                if (async)
                {
                    response = await RestClient.GetByIdAsync(schemaId, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    response = RestClient.GetById(schemaId, cancellationToken);
                }

                SchemaFormat format     = new SchemaFormat(response.Headers.ContentType.Split('=')[1]);
                var          properties = new SchemaProperties(format, response.Headers.SchemaId, response.Headers.SchemaGroupName, response.Headers.SchemaName);
                var          schema     = new SchemaRegistrySchema(properties, BinaryData.FromStream(response.Value).ToString());

                return(Response.FromValue(schema, response));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #2
0
        private async Task <Response <SchemaProperties> > GetSchemaPropertiesInternalAsync(
            string groupName,
            string schemaName,
            string schemaDefinition,
            SchemaFormat format,
            bool async,
            CancellationToken cancellationToken)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope(GetSchemaIdScopeName);
            scope.Start();
            try
            {
                ResponseWithHeaders <SchemaQueryIdByContentHeaders> response;
                if (async)
                {
                    response = await RestClient.QueryIdByContentAsync(groupName, schemaName, format.ContentType, new BinaryData(schemaDefinition).ToStream(), cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    response = RestClient.QueryIdByContent(groupName, schemaName, format.ContentType, new BinaryData(schemaDefinition).ToStream(), cancellationToken);
                }

                var properties = new SchemaProperties(format, response.Headers.SchemaId, response.Headers.SchemaGroupName, response.Headers.SchemaName);

                return(Response.FromValue(properties, response));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #3
0
 /// <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="schemaDefinition">The string representation of the schema's content.</param>
 /// <param name="format">The serialization format of the schema.</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,
     string schemaDefinition,
     SchemaFormat format,
     CancellationToken cancellationToken = default) =>
 RegisterSchemaInternalAsync(groupName, schemaName, schemaDefinition, format, false, cancellationToken)
 .EnsureCompleted();
예제 #4
0
 /// <summary>
 /// Registers a schema with 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="schemaDefinition">The string representation of the schema's content.</param>
 /// <param name="format">The serialization format of the schema.</param>
 /// <param name="cancellationToken">The cancellation token for the operation.</param>
 /// <returns>The properties of the schema.</returns>
 public virtual async Task <Response <SchemaProperties> > RegisterSchemaAsync(
     string groupName,
     string schemaName,
     string schemaDefinition,
     SchemaFormat format,
     CancellationToken cancellationToken = default) =>
 await RegisterSchemaInternalAsync(groupName, schemaName, schemaDefinition, format, true, cancellationToken)
 .ConfigureAwait(false);
예제 #5
0
        /// <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="schemaDefinition">The string representation of the schema's content.</param>
        /// <param name="format">The serialization format of the schema.</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>
#pragma warning disable AZC0015 // Unexpected client method return type.
        public virtual Response <SchemaProperties> GetSchemaProperties(
            string groupName,
            string schemaName,
            string schemaDefinition,
            SchemaFormat format,
            CancellationToken cancellationToken = default) =>
#pragma warning restore AZC0015 // Unexpected client method return type.
        GetSchemaPropertiesInternalAsync(groupName, schemaName, schemaDefinition, format, false, cancellationToken).EnsureCompleted();
예제 #6
0
        /// <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="schemaDefinition">The string representation of the schema's content.</param>
        /// <param name="format">The serialization format of the schema.</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>
#pragma warning disable AZC0015 // Unexpected client method return type.
        public virtual async Task <Response <SchemaProperties> > GetSchemaPropertiesAsync(
            string groupName,
            string schemaName,
            string schemaDefinition,
            SchemaFormat format,
            CancellationToken cancellationToken = default) =>
#pragma warning restore AZC0015 // Unexpected client method return type.
        await GetSchemaPropertiesInternalAsync(groupName, schemaName, schemaDefinition, format, true, cancellationToken)
        .ConfigureAwait(false);
 public static SchemaProperties SchemaProperties(SchemaFormat format, string schemaId, string groupName, string name) => new(format, schemaId, groupName, name);
 public static SchemaProperties SchemaProperties(SchemaFormat format, string schemaId) => SchemaProperties(format, schemaId, null, null);