Google Pub/Sub settings programmatically enable message retention for topics

WBOY
Release: 2024-02-09 08:10:08
forward
1190 people have browsed it

Google Pub/Sub 设置以编程方式启用主题的消息保留

php Xiaobian Xigua brings you new skills about Google Pub/Sub. You can now set message retention programmatically to ensure messages in your topic are not lost. This is a very useful feature, especially when working with important data or tasks that require long processing times. By enabling message retention, you can confidently process messages without worrying that they will be lost in the process. Next, we'll detail how to programmatically enable message retention for a topic using Google Pub/Sub settings. Stay tuned!

Question content

In Google pub/sub, if a topic is created, we can set the retention policy

https://console.cloud.google.com/cloudpubsub

By clicking, editing, editing topic, updating

Is it possible to update this value programmatically?

I saw that the subscription level has this configuration https://github.com/googleapis/google-cloud-go/blob/main/pubsub/subscription.go#L564 But not at the topic level?

Workaround

Yes, message retention can be configured programmatically in the topic. In Go, you can set RetentionDuration in TopicConfig and pass it to CreateTopicWithConfig Do this on creation:

tc := TopicConfig{
    RetentionDuration = 168 * time.Hour
}
topic, err := c.CreateTopicWithConfig(context.Background(), "my-topic", tc)
Copy after login

To do this on update, set the property in TopicConfigToUpdate and pass it to Update:

topic := client.Topic("my-topic")
topicConfig, err := topic.Update(ctx, pubsub.TopicConfigToUpdate{
  RetentionDuration = 168 * time.Hour
})
Copy after login

The above is the detailed content of Google Pub/Sub settings programmatically enable message retention for topics. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!