Delete a revision from a schema

Delete a revision from a schema

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C++

Before trying this sample, follow the C++ setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub C++ API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  namespace 
  
 pubsub 
  
 = 
  
 :: 
 google 
 :: 
 cloud 
 :: 
 pubsub 
 ; 
 []( 
 pubsub 
 :: 
 SchemaServiceClient 
  
 client 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 project_id 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 schema_id 
 , 
  
 std 
 :: 
 string 
  
 const 
&  
 revision_id 
 ) 
  
 { 
  
 std 
 :: 
 string 
  
 const 
  
 schema_id_with_revision 
  
 = 
  
 schema_id 
  
 + 
  
 "@" 
  
 + 
  
 revision_id 
 ; 
  
 google 
 :: 
 pubsub 
 :: 
 v1 
 :: 
 DeleteSchemaRevisionRequest 
  
 request 
 ; 
  
 request 
 . 
 set_name 
 ( 
  
 pubsub 
 :: 
 Schema 
 ( 
 project_id 
 , 
  
 schema_id_with_revision 
 ). 
 FullName 
 ()); 
  
 auto 
  
 schema 
  
 = 
  
 client 
 . 
 DeleteSchemaRevision 
 ( 
 request 
 ); 
  
 if 
  
 ( 
 ! 
 schema 
 ) 
  
 throw 
  
 std 
 :: 
 move 
 ( 
 schema 
 ). 
 status 
 (); 
  
 std 
 :: 
 cout 
 << 
 "Deleted schema. Its metadata is:" 
 << 
 " 
 \n 
 " 
 << 
 schema 
 - 
> DebugString 
 () 
 << 
 " 
 \n 
 " 
 ; 
 } 
 

C#

Before trying this sample, follow the C# setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub C# API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  using 
  
  Google.Cloud.PubSub.V1 
 
 ; 
 public 
  
 class 
  
 DeleteSchemaRevisionSample 
 { 
  
 public 
  
 void 
  
 DeleteSchemaRevision 
 ( 
 string 
  
 projectId 
 , 
  
 string 
  
 schemaId 
 , 
  
 string 
  
 revisionId 
 ) 
  
 { 
  
  SchemaServiceClient 
 
  
 schemaService 
  
 = 
  
  SchemaServiceClient 
 
 . 
  Create 
 
 (); 
  
  DeleteSchemaRevisionRequest 
 
  
 request 
  
 = 
  
 new 
  
  DeleteSchemaRevisionRequest 
 
  
 { 
  
 SchemaName 
  
 = 
  
  SchemaName 
 
 . 
  FromProjectSchema 
 
 ( 
 projectId 
 , 
  
 schemaId 
  
 + 
  
 "@" 
  
 + 
  
 revisionId 
 ) 
  
 }; 
  
 schemaService 
 . 
  DeleteSchemaRevision 
 
 ( 
 request 
 ); 
  
 } 
 } 
 

Go

Before trying this sample, follow the Go setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub Go API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/v2/apiv1" 
  
 "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb" 
 ) 
 func 
  
 deleteSchemaRevision 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
 , 
  
 schemaID 
 , 
  
 revisionID 
  
 string 
 ) 
  
 error 
  
 { 
  
 // projectID := "my-project-id" 
  
 // schemaID := "my-schema-id" 
  
 // revisionID := "my-revision-id" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSchemaClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "pubsub.NewSchemaClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 req 
  
 := 
  
& pubsubpb 
 . 
 DeleteSchemaRevisionRequest 
 { 
  
 Name 
 : 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/schemas/%s@%s" 
 , 
  
 projectID 
 , 
  
 schemaID 
 , 
  
 revisionID 
 ), 
  
 } 
  
 if 
  
 _ 
 , 
  
 err 
  
 := 
  
 client 
 . 
 DeleteSchemaRevision 
 ( 
 ctx 
 , 
  
 req 
 ); 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "client.DeleteSchemaRevision: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Deleted a schema revision: %s@%s" 
 , 
  
 schemaID 
 , 
  
 revisionID 
 ) 
  
 return 
  
 nil 
 } 
 

Java

Before trying this sample, follow the Java setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub Java API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 com.google.api.gax.rpc. NotFoundException 
 
 ; 
 import 
  
 com.google.cloud.pubsub.v1. SchemaServiceClient 
 
 ; 
 import 
  
 com.google.pubsub.v1. DeleteSchemaRevisionRequest 
 
 ; 
 import 
  
 com.google.pubsub.v1. SchemaName 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 public 
  
 class 
 DeleteSchemaRevisionExample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 ... 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 projectId 
  
 = 
  
 "your-project-id" 
 ; 
  
 String 
  
 schemaId 
  
 = 
  
 "your-schema-id@your-revision-id" 
 ; 
  
 deleteSchemaRevisionExample 
 ( 
 projectId 
 , 
  
 schemaId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 deleteSchemaRevisionExample 
 ( 
 String 
  
 projectId 
 , 
  
 String 
  
 schemaId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
  SchemaName 
 
  
 schemaName 
  
 = 
  
  SchemaName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 schemaId 
 ); 
  
 try 
  
 ( 
  SchemaServiceClient 
 
  
 schemaServiceClient 
  
 = 
  
  SchemaServiceClient 
 
 . 
 create 
 ()) 
  
 { 
  
  DeleteSchemaRevisionRequest 
 
  
 request 
  
 = 
  
  DeleteSchemaRevisionRequest 
 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 schemaName 
 . 
  toString 
 
 ()). 
 build 
 (); 
  
 schemaServiceClient 
 . 
 deleteSchemaRevision 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Deleted a schema revision:" 
  
 + 
  
 schemaName 
 ); 
  
 } 
  
 catch 
  
 ( 
  NotFoundException 
 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 schemaName 
  
 + 
  
 "not found." 
 ); 
  
 } 
  
 } 
 } 
 

Ruby

Before trying this sample, follow the Ruby setup instructions in the Pub/Sub quickstart using client libraries . For more information, see the Pub/Sub Ruby API reference documentation .

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  # schema_id = "your-schema-id" 
 # revision_id = "your-revision-id" 
 pubsub 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  Pubsub 
 
 . 
 new 
 schemas 
  
 = 
  
 pubsub 
 . 
 schemas 
 result 
  
 = 
  
 schemas 
 . 
 delete_schema_revision 
  
 \ 
  
 name 
 : 
  
 pubsub 
 . 
 schema_path 
 ( 
 " 
 #{ 
 schema_id 
 } 
 @ 
 #{ 
 revision_id 
 } 
 " 
 ) 
 puts 
  
 "Schema 
 #{ 
 schema_id 
 } 
 @ 
 #{ 
 revision_id 
 } 
 deleted." 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: