public Schema CreateAvroSchema(string projectId, string schemaId, string pathToDefinition)
    {
        SchemaServiceClient schemaService = SchemaServiceClient.Create();
        var    schemaName       = SchemaName.FromProjectSchema(projectId, schemaId);
        string schemaDefinition = File.ReadAllText(pathToDefinition);
        Schema schema           = new Schema
        {
            Name       = schemaName.ToString(),
            Type       = Schema.Types.Type.Avro,
            Definition = schemaDefinition
        };
        CreateSchemaRequest createSchemaRequest = new CreateSchemaRequest
        {
            Parent   = "projects/" + projectId,
            SchemaId = schemaId,
            Schema   = schema
        };

        try
        {
            schema = schemaService.CreateSchema(createSchemaRequest);
            Console.WriteLine($"Schema {schema.Name} created.");
        }
        catch (RpcException e) when(e.Status.StatusCode == StatusCode.AlreadyExists)
        {
            Console.WriteLine($"Schema {schemaName} already exists.");
        }
        return(schema);
    }
예제 #2
0
 /// <summary>Snippet for CreateSchema</summary>
 public void CreateSchema()
 {
     // Snippet: CreateSchema(string, Schema, string, CallSettings)
     // Create client
     SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create();
     // Initialize request argument(s)
     string parent   = "projects/[PROJECT]";
     Schema schema   = new Schema();
     string schemaId = "";
     // Make the request
     Schema response = schemaServiceClient.CreateSchema(parent, schema, schemaId);
     // End snippet
 }
예제 #3
0
 /// <summary>Snippet for CreateSchema</summary>
 public void CreateSchemaResourceNames()
 {
     // Snippet: CreateSchema(ProjectName, Schema, string, CallSettings)
     // Create client
     SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create();
     // Initialize request argument(s)
     ProjectName parent   = ProjectName.FromProject("[PROJECT]");
     Schema      schema   = new Schema();
     string      schemaId = "";
     // Make the request
     Schema response = schemaServiceClient.CreateSchema(parent, schema, schemaId);
     // End snippet
 }
예제 #4
0
 /// <summary>Snippet for CreateSchema</summary>
 public void CreateSchemaRequestObject()
 {
     // Snippet: CreateSchema(CreateSchemaRequest, CallSettings)
     // Create client
     SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create();
     // Initialize request argument(s)
     CreateSchemaRequest request = new CreateSchemaRequest
     {
         ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
         Schema   = new Schema(),
         SchemaId = "",
     };
     // Make the request
     Schema response = schemaServiceClient.CreateSchema(request);
     // End snippet
 }