我正在使用亞馬遜AWS Ruby SDK用於Amazon SNS,但我在註冊設備時遇到了一些問題。有時,當設備被重新註冊我得到這樣AWS::SNS::Errors::InvalidParameter Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:**** already exists with the same Token, but different attributes.
錯誤。如何檢查端點是否已經存在,更重要的是,我如何得到一個給定的令牌端點?如何檢查移動設備是否已註冊
回答
感謝BvdBijl的想法,我做了一個擴展方法來刪除發現現有的一個,如果再添加它。
using System;
using System.Text.RegularExpressions;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
namespace Amazon.SimpleNotificationService
{
public static class AmazonSimpleNotificationServiceClientExtensions
{
private const string existingEndpointRegexString = "Reason: Endpoint (.+) already exists with the same Token";
private static Regex existingEndpointRegex = new Regex(existingEndpointRegexString);
public static CreatePlatformEndpointResponse CreatePlatformEndpointIdempotent(
this AmazonSimpleNotificationServiceClient client,
CreatePlatformEndpointRequest request)
{
try
{
var result = client.CreatePlatformEndpoint(request);
return result;
}
catch (AmazonSimpleNotificationServiceException e)
{
if (e.ErrorCode == "InvalidParameter")
{
var match = existingEndpointRegex.Match(e.Message);
if (match.Success) {
string arn = match.Groups[1].Value;
client.DeleteEndpoint(new DeleteEndpointRequest
{
EndpointArn = arn,
});
return client.CreatePlatformEndpoint(request);
}
}
throw;
}
}
}
}
這麼瘋狂,這實際上是我可以看到的唯一方法它也是如此。 – chadkouse
不用刪除和創建平臺終端,你可以只調用: SetEndpointAttributes 與屬性 '啓用= TRUE; – Kamil
感覺奇怪不必解析了這一點,可能會改變未來的錯誤消息。很荒謬,他們不只是返回重複的端點阿爾恩給我們。 – user3344977
它看起來像amazone解決了這個問題。 我使用回報率和嘗試註冊和現有GCM代碼時曾經有過同樣的問題,我得到了一個錯誤信息說
"AWS::SNS::Errors::InvalidParameter Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:**** already exists with the same Token, but different attributes."
雖然我用相同(空)的屬性。現在,當我把現有GCM代碼(有相同的屬性與原)我得到的端點阿爾恩,而不是錯誤消息。
ListEndpointsByPlatformApplication僅返回100個端點,您必須使用nextToken才能獲得更多。這是我的實現。
public void deleteEndpoint(string token, string PlatformApplicationArn)
{
ListEndpointsByPlatformApplicationRequest listRequest = new ListEndpointsByPlatformApplicationRequest();
listRequest.PlatformApplicationArn = PlatformApplicationArn;
Logger.Info("Deleting endpoint with token -> " + token);
var list = snsClient.ListEndpointsByPlatformApplication(listRequest);
do
{
foreach (var x in list.Endpoints.Where(x => x.Attributes["Token"] == token))
{
snsClient.DeleteEndpoint(new DeleteEndpointRequest() { EndpointArn = x.EndpointArn });
Logger.Info("Endpoint removed-> " + x.EndpointArn);
return;
}
listRequest.NextToken = list.NextToken;
list = snsClient.ListEndpointsByPlatformApplication(listRequest);
}
while (list.NextToken != null);
}
考慮一下,如果我有足夠的終點是指1個十萬,那麼這個過程將需要一些什麼權利推遲檢查總終點的令牌。有沒有辦法直接刪除端點而不進行處理? –
- 1. ASP.NET移動設備註冊
- 2. 檢查jQuery「Fancybox」是否已經註冊?
- 3. 檢查用戶名是否已註冊
- 4. 知道設備是否移動並註冊GPS協調
- 5. 確定設備是否已移動
- 6. Twitter數字:如何檢查用戶是否已經註冊
- 7. 如何檢查ActiveX DLL是否已經註冊?
- 8. 如何檢查.NET DLL是否已註冊?
- 9. 檢測監聽器是否已註冊
- 10. 檢查滑塊是否已移動
- 11. 檢查DependencyProperty已註冊
- 12. 如何檢測移動設備移動?
- 13. 如何檢查Touch ID是否已註冊但在iPhone上已禁用?
- 14. 在Provisioning Portal上註冊設備時,是否已使用設備ID?
- 15. 如何檢查新指紋是否已添加到設備?
- 16. 如何檢查WaitHandle是否已設置?
- 17. 如何檢查LogWriter是否已設置?
- 18. 如何檢查iOS設備自啓動以來是否已重新啓動
- 19. 如何檢查MIDI設備是否也是USB設備?
- 20. 檢查無線設備是否啓動
- 21. 如何檢查IntentService是否已啓動
- 22. 如何檢測請求是否來自移動設備
- 23. 如何檢測Android設備是否被觸摸或移動
- 24. Java Servlets - 如何檢測用戶是否來自移動設備?
- 25. 如何檢測Windows移動設備是否擴展了鍵盤?
- 26. 如何檢測Windows移動設備是否有攝像頭? c#
- 27. 檢查用戶是否使用移動設備
- 28. 如何檢測某種類型是否已註冊
- 29. 如何檢測新聽衆是否已註冊?
- 30. 檢查廣播接收機是否已經註冊?
我與SNS的node.js有同樣的問題。你有沒有找到一些解決方案? –
我正在使用.net庫,並且在嘗試重新註冊時沒有收到錯誤 –
只有當您希望存儲與註冊相關的附加屬性時纔會出現錯誤,然後稍後您將使用不同的設置的屬性。 –