Delay message processing and delete before processing

淺唱寂寞╮ 提交于 2019-12-12 08:24:33

问题


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.

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 ?


回答1:


Depends on if you write the subscribers as well or not:

You have control over your subscribers code:

  1. In your Pubsub messages add a timestamp for when you want that message to be processed.
  2. In your clients(subscribers), have logic to acknowledge the message only if the timestamp to process the message is reached.
  3. Pubsub itself will re-try delivering the message until it's acknowledged (or 10 days)

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:

  1. Public message as before to my-topic.
  2. You will have a subscriber for that topic that can do the same throttling as shown above:
  3. If the time for that message has reached your handler will publish/relay that message to my-delayed-topic.

You can also implement the logic above with task-queue+pubsub-topic instead of pubsub-topic+pubsub-topic.



来源:https://stackoverflow.com/questions/39742091/delay-message-processing-and-delete-before-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!