我正在使用Azure Notification Service。
我记录了发送给azure的每个推送通知的结果。
我有时会得到以下结果/响应:
"远程服务器返回错误:(401)未经授权。 ExpiredToken: .TrackingId:f38f2e96-23b9-4c5b-880克-1358c5c15316_G4,时间戳:2016年9月1日 晚上9:48:14"
我在1秒的时间内连续2到10。然后它又开始工作了。
这是我的日志:
Date Result
2016-09-01 22:07:02.81 Enqueued
2016-09-01 22:07:02.67 Enqueued
2016-09-01 22:05:34.03 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:9bf11f89-9c54-4213-8e42
2016-09-01 22:04:44.52 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:36fb0e8b-7d0f-4145-a125
2016-09-01 22:04:44.51 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:23c76f68-52ca-404a-ad31
2016-09-01 22:04:44.09 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:ceb11915-745a-4924-80cf
2016-09-01 22:04:44.09 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:75c61cba-fadc-4c05-8fe2
2016-09-01 22:03:52.82 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:e3696e3d-a44b-4179-a14a
2016-09-01 22:03:52.82 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:ea3c040b-e358-461b-a56f
2016-09-01 22:03:52.40 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:2eb9901d-e267-4053-a6a4
2016-09-01 22:03:52.40 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:163730b1-b7ef-43e8-adaf
2016-09-01 22:03:51.98 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:f28412c5-262f-4891-b991
2016-09-01 22:03:51.55 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:48b5dc83-ee3a-4d3f-b525
2016-09-01 22:03:51.55 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:a64ce0b1-dd6d-4972-8990
2016-09-01 22:03:51.13 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:b43bde8d-febb-4624-99c6
2016-09-01 22:03:51.13 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:17bd762d-0b4b-450c-bf09
2016-09-01 22:03:50.71 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:9abef735-bf42-4494-9721
2016-09-01 22:03:50.71 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:3f9b9c82-e37e-48c4-931e
2016-09-01 22:03:50.29 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:685a2286-6f0b-4fdf-9dd6
2016-09-01 22:03:50.28 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:3715eee2-b4b6-4ec4-9141
2016-09-01 22:03:49.87 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:91212080-719f-4b95-b9da
2016-09-01 22:03:49.86 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:bd1f5ae4-1a38-40d6-87ba
2016-09-01 22:03:48.01 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:47307851-cd9b-4632-94b6
2016-09-01 22:03:22.07 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:c8a21d16-de82-4fef-b2e
2016-09-01 22:03:22.07 The remote server returned an error: (401) Unauthorized. ExpiredToken: .TrackingId:1fe9246d-19fc-4818-b8a8
2016-09-01 22:03:11.44 Enqueued
2016-09-01 22:03:11.34 Enqueued
此错误消息的含义是什么?
[经过一番思考]
这可能是一个线程问题吗?我实现此代码的方式是,每个任务都有一个NotificationHubClient
的单例实例,然后调用SendGcmNativeNotificationAsync()
。
答案 0 :(得分:1)
这可能是赛车问题。要解决此问题,您是否可以为每项任务创建新的NotificationHubClient
(NotificationHubClient
是非常轻量级的对象)。
答案 1 :(得分:1)
NotificationHub .NET SDK刚刚解决了一个问题,其中SAS令牌在频繁使用且寿命长的连接客户端上过期。您可以在GitHub上查看此问题:https://github.com/Azure/azure-notificationhubs-dotnet/commit/be52eefcd418f8e0540620a0ea64be0c9dea2488
我们最初将NotificationHubClient实例注册为单例,并且遇到了同一问题。但是,一旦我们转到每个请求调用NotificationHubClient.CreateFromConnectionString(),我们最终会遇到端口耗尽问题,我们怀疑这是您创建大量HttpClient而不是重用它们时出现的潜在问题的结果。根本问题是NotificationHubClient在其构造函数中为与NotificationHub的基础通信创建了一个新的HttpClient实例,因此实际上您最终使用这种方法创建了一堆短暂的HttpClient。
他们的2.0.2更新是几天前发布的,因此,如果您的业务量很大,则应该在拉下最新更新后以单例实例化NotificationHubClient。
希望这会有所帮助!