问题描述
我需要这种能力来发送针对移动应用中某项操作的推送通知,但要等到用户撤消该操作,直到说10秒钟.
I need this ability to send push notifications for an action in a mobile app but wait for the user to undo the action until say 10 seconds.
是否可以将主题中发布的消息的处理延迟10秒?然后(有时,如果用户撤消操作)在10秒钟之前删除该消息,是否不需要处理?
Is it possible to delay the processing of a message published in a topic by 10 seconds ? And then (sometimes, if user does undo) delete the message before 10 seconds, if it doesn't need to be processed ?
推荐答案
取决于是否也写订阅者:
Depends on if you write the subscribers as well or not:
您可以控制您的订阅者代码:
You have control over your subscribers code:
- 在您的Pubsub消息中添加时间戳记待处理的邮件.
- 在您的客户(订户)中,有逻辑地仅在处理消息的时间戳记时才确认消息达到了.
- Pubsub本身将重试传递消息,直到被确认(或10天)
- In your Pubsub messages add a timestamp for when you want thatmessage to be processed.
- In your clients (subscribers), have logic toacknowledge the message only if the timestamp to process the messageis reached.
- Pubsub itself will re-try delivering the message untilit's acknowledged (or 10 days)
如果您无法控制订户,则可以拥有一个my-topic和my-delayed-topic.人们可以将其发布到前一个主题,而该主题将只有一个订阅者,您将实现该订阅者:
If you don't have control over your subscriber you can have a my-topic and my-delayed-topic. Folks can publish to the former topic and that topic will have only one subscriber which you will implement:
- 向我的主题发送公开消息.
- 您,该主题的订阅者可以进行与上述相同的调节:
- 如果该消息的时间已到,您的处理程序将将该消息发布/中继到my-delayed-topic.
- Public message as before to my-topic.
- You will have a subscriber for that topic that can do the same throttling as shown above:
- If the time for that message has reached your handler will publish/relay that message to my-delayed-topic.
您还可以使用task-queue + pubsub-topic而不是pubsub-topic + pubsub-topic来实现上述逻辑.
You can also implement the logic above with task-queue+pubsub-topic instead of pubsub-topic+pubsub-topic.
这篇关于延迟消息处理并在处理之前删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!