首页 > 解决方案 > 如何确保消息已被 azure 服务总线中的所有订阅处理

问题描述

由于 azure 服务总线对消息大小(256 kb)有限制,我将一条长消息存储在 blob 中,当函数应用收到消息时,我正在从 blob 存储下载内容并将其转换为消息格式。

服务总线成功处理消息后,我需要从 blob 存储中删除该文件,因为它不再需要。

但这里的问题是,同一主题下的两个订阅发送了相同的消息,一个由函数应用处理,另一个由 Web 作业处理。如果我从函数应用程序中的 blob 中删除文件,则 webjob 将无法使用该文件,反之亦然。

那么有没有什么方法可以识别出消息已经被所有订阅者成功处理了呢?

标签: azureazure-blob-storageservicebus

解决方案


Azure 服务总线消息传递为我们提供了一种将自定义或用户属性添加到服务总线消息的方法。所以

1.You can add a custom property like messageReceptionCount to your message with initial value as 0 and send it to your topic.
2.While receiving the message in your topic subscription, you can increment the messageReceptionCount by 1.
3.When the messageReceptionCount has reached the number of subscriptions in the topic you can delete it from your blob storage.

我希望这对你有用。


推荐阅读