Microsoft Graph为创建/删除发送了大量不必要的通知

时间:2017-06-29 13:04:45

标签: microsoft-graph

为了提高效率,我们将系统从轮询升级为使用webhooks订阅和delta查询。

然而,对于webhooks,我发现我们收到了大量不必要/虚假的通知。

例如,如果用户取消某个事件,我们看到的是几个update通知,后跟一个deleted通知,只需几毫秒。

这非常令人讨厌,因为它创造了一种情况,而不是立即对通知做出反应(如果工作队列是空的),我们不得不添加一个油门/去抖,这样我们就可以得到一个从webhooks读取更准确。

删除也会导致更新的示例如下:

[2017-06-28T23:17:40.657Z][meetingroom1.outlookDidNotify] Received notification {
  "subscriptionId": "54c27b11-c2e2-4962-89dd-cf316bf3eecb",
  "subscriptionExpirationDateTime": "2017-06-28T23:59:59.999+00:00",
  "changeType": "updated",
  "resource": "Users/f4a2ac63-ddf7-40dc-80da-4e05acf6488a/Events/AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA=",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.Event",
    "@odata.id": "Users/f4a2ac63-ddf7-40dc-80da-4e05acf6488a/Events/AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA=",
    "@odata.etag": "W/\"DwAAABYAAAAPLFcVBl+pRZA4tM1jHR47AAD+zvOL\"",
    "id": "AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA="
  },
  "clientState": "…"
}
[2017-06-28T23:17:40.658Z][meetingroom1.outlookDidNotify] Received notification {
  "subscriptionId": "54c27b11-c2e2-4962-89dd-cf316bf3eecb",
  "subscriptionExpirationDateTime": "2017-06-28T23:59:59.999+00:00",
  "changeType": "deleted",
  "resource": "Users/f4a2ac63-ddf7-40dc-80da-4e05acf6488a/Events/AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA=",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.Event",
    "@odata.id": "Users/f4a2ac63-ddf7-40dc-80da-4e05acf6488a/Events/AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA=",
    "@odata.etag": "W/\"CQAAAA==\"",
    "id": "AAMkADc1MWNjZWM3LTNhZDYtNGYwYi04OWYxLTU0N2E0MmI5YTE4MwBGAAAAAAAKhIOGniPIR6bsTEhp5zDzBwAPLFcVBl_pRZA4tM1jHR47AAAAAAENAAAPLFcVBl_pRZA4tM1jHR47AAD5gM31AAA="
  },
  "clientState": "…"
}

同样在几分之一秒内为同一事件发送多个更新通知。

创建的事件可以在一秒钟内跟随多个更新事件:

[2017-06-28T15:57:45.044Z][meetingroom2.outlookDidNotify] Received notification {
  "subscriptionId": "de0147cc-cdef-4141-b601-4eb32cec1377",
  "subscriptionExpirationDateTime": "2017-06-28T23:59:59.999+00:00",
  "changeType": "created",
  "resource": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.Event",
    "@odata.id": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
    "@odata.etag": "W/\"DwAAABYAAADlDV58cGeaS7ZJcZ6ff+AvAAD9kqa/\"",
    "id": "AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA="
  },
  "clientState": "…"
}
[2017-06-28T15:57:45.954Z][meetingroom2.outlookDidNotify] Received notification {
  "subscriptionId": "de0147cc-cdef-4141-b601-4eb32cec1377",
  "subscriptionExpirationDateTime": "2017-06-28T23:59:59.999+00:00",
  "changeType": "updated",
  "resource": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.Event",
    "@odata.id": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
    "@odata.etag": "W/\"DwAAABYAAADlDV58cGeaS7ZJcZ6ff+AvAAD9kqa/\"",
    "id": "AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA="
  },
  "clientState": "…"
}
[2017-06-28T15:57:47.409Z][meetingroom2.outlookDidNotify] Received notification {
  "subscriptionId": "de0147cc-cdef-4141-b601-4eb32cec1377",
  "subscriptionExpirationDateTime": "2017-06-28T23:59:59.999+00:00",
  "changeType": "updated",
  "resource": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.Event",
    "@odata.id": "Users/97e22591-9c20-4030-a11e-102ba89741fc/Events/AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA=",
    "@odata.etag": "W/\"DwAAABYAAADlDV58cGeaS7ZJcZ6ff+AvAAD9kqbB\"",
    "id": "AAMkADFlY2YyODZiLTc1OGItNGE1Yy1iNDI1LWNjMGQ5MDRjNDU2ZABGAAAAAACfo61cAY_iTZYbfhL-JgzZBwDlDV58cGeaS7ZJcZ6ff_AvAAAAAAENAADlDV58cGeaS7ZJcZ6ff_AvAAD9hgs0AAA="
  },
  "clientState": "…"
}

1 个答案:

答案 0 :(得分:2)

通知是Outlook日历行为的结果。您可以考虑仅订阅某些更改类型或使用$ filter进行订阅。

POST https://graph.microsoft.com/V1.0/subscriptions 

Header:
Content-type = application/json

Body:
{
  "resource": "me/mailFolders('Inbox')/messages?$filter=IsRead%20eq%20false",
  "notificationUrl": "https://mywebhook.azurewebsites.net/api/send/NotifyClient",
  "changeType": "Created,Deleted ",
  "expirationDateTime": "2017-06-30T18:23:45.935Z",
  "clientState": "Message unread"
}