v1 Update dead letter policy on subscription (DEPRECATED)

(DEPRECATED) Update dead letter policy on subscription

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" 
  
 "io" 
  
 "cloud.google.com/go/pubsub" 
 ) 
 // updateDeadLetter updates an existing subscription with a dead letter policy. 
 func 
  
 updateDeadLetter 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
 , 
  
 subID 
  
 string 
 , 
  
 fullyQualifiedDeadLetterTopic 
  
 string 
 ) 
  
 error 
  
 { 
  
 // projectID := "my-project-id" 
  
 // subID := "my-sub" 
  
 // fullyQualifiedDeadLetterTopic := "projects/my-project/topics/my-dead-letter-topic" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
  NewClient 
 
 ( 
 ctx 
 , 
  
 projectID 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "pubsub.NewClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 updateConfig 
  
 := 
  
 pubsub 
 . 
 SubscriptionConfigToUpdate 
 { 
  
 DeadLetterPolicy 
 : 
  
& pubsub 
 . 
 DeadLetterPolicy 
 { 
  
 DeadLetterTopic 
 : 
  
 fullyQualifiedDeadLetterTopic 
 , 
  
 MaxDeliveryAttempts 
 : 
  
 20 
 , 
  
 }, 
  
 } 
  
 subConfig 
 , 
  
 err 
  
 := 
  
 client 
 . 
 Subscription 
 ( 
 subID 
 ). 
 Update 
 ( 
 ctx 
 , 
  
 updateConfig 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "Update: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Updated subscription config: %+v\n" 
 , 
  
 subConfig 
 ) 
  
 return 
  
 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 .

  # subscription_id       = "your-subscription-id" 
 # role                  = "roles/pubsub.publisher" 
 # service_account_email = "serviceAccount:account_name@project_name.iam.gserviceaccount.com" 
 pubsub 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  Pubsub 
 
 . 
 new 
 subscription 
  
 = 
  
 pubsub 
 . 
 subscription 
  
 subscription_id 
 subscription 
 . 
 dead_letter_max_delivery_attempts 
  
 = 
  
 20 
 puts 
  
 "Max delivery attempts is now 
 #{ 
 subscription 
 . 
 dead_letter_max_delivery_attempts 
 } 
 ." 
 

What's next

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

Design a Mobile Site
View Site in Mobile | Classic
Share by: