v1 List subscriptions in project (DEPRECATED)

(DEPRECATED) List subscriptions in project

Code sample

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" 
  
 "cloud.google.com/go/pubsub" 
  
 "google.golang.org/api/iterator" 
 ) 
 func 
  
 list 
 ( 
 projectID 
  
 string 
 ) 
  
 ([] 
 * 
 pubsub 
 . 
 Subscription 
 , 
  
 error 
 ) 
  
 { 
  
 // projectID := "my-project-id" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
  NewClient 
 
 ( 
 ctx 
 , 
  
 projectID 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 nil 
 , 
  
 fmt 
 . 
 Errorf 
 ( 
 "pubsub.NewClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 var 
  
 subs 
  
 [] 
 * 
 pubsub 
 . 
 Subscription 
  
 it 
  
 := 
  
 client 
 . 
 Subscriptions 
 ( 
 ctx 
 ) 
  
 for 
  
 { 
  
 s 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 nil 
 , 
  
 fmt 
 . 
 Errorf 
 ( 
 "Next: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 subs 
  
 = 
  
 append 
 ( 
 subs 
 , 
  
 s 
 ) 
  
 } 
  
 return 
  
 subs 
 , 
  
 nil 
 } 
 

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 .

  pubsub 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  Pubsub 
 
 . 
 new 
 subscriptions 
  
 = 
  
 pubsub 
 . 
 list_subscriptions 
 puts 
  
 "Subscriptions:" 
 subscriptions 
 . 
 each 
  
 do 
  
 | 
 subscription 
 | 
  
 puts 
  
 subscription 
 . 
 name 
 end 
 

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: