2015-10-15 161 views
8

下面是一段代碼:超時錯誤AWS SNSClient發佈請求

     //Publishing the topic 
         snsClient.Publish(new PublishRequest 
         { 
          Subject = Constants.SNSTopicMessage, 
          Message = snsMessageObj.ToString(), 
          TopicArn = Settings.TopicArn 
         }); 

我收到以下錯誤:

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

,這裏是詳細的錯誤的截圖: enter image description here

但是無法想出如何解決這個問題。任何提示或鏈接都會有幫助。

•網絡中斷髮生時:當一個或多個的下列條件,則可能會發生

+0

也許太明顯,但snsClient有效(即正確連接,現有的憑據,地區...)? – Gonfva

+0

是@Gonfva。它們是有效的。我能夠做這些操作。但我很少遇到錯誤。但仍然需要解決。 –

回答

2

我們遇到了完全相同的問題。我們每天發生這種錯誤的次數大約是40次,這比我們發送的成功推送通知量的0.1%還要少。

我們的解決方案?將AWSSDK NuGet包從1.5.30.1更新到2.3.52.0(易於升級的最新v2發行版)。只要我們更新,錯誤就會停止。我瀏覽了很多發行說明,並且找不到任何具體提及此問題的內容。我們不知道爲什麼更新可行,但它確實如此。

我希望這可以幫助你和其他人解決這個問題。

+0

感謝您的意見。我會更新版本並會讓你知道結果。 –

+0

是的。你是對的。漸變確實解決了這個問題。現在,我沒有收到任何這些超時。 Thx一噸。 –

0

此問題。

•代理服務器阻止HTTP請求。

•發生域名系統(DNS)問題。

•發生網絡認證問題。

[https://nilangshah.wordpress.com/2007/03/01/the-underlying-connection-was-closed-unable-to-connect-to-the-remote-server/]1

+0

這個問題很少發生。就像6000 sns信息最多隻有10-15次一樣。所以,我不確定你對這些問題的建議。 –

+0

@ ch.smrutiranjanparida,檢查您的Amazon sns初始化代碼。亞馬遜會在幾次後自動停止連接。所以,我認爲你應該粘貼所有的代碼。所以人們可以很容易地理解,你從哪個句子中得到這樣的問題。 –

+0

@BhavikPatel,這裏是初始化代碼: snsClient = new AmazonSimpleNotificationServiceClient(Settings.AccessKey,Settings.SecretKey,regionEndPoint); –

0
  • 確保您的有效載荷大小不應超過超過256 KB
  • 做出的PutObjectRequest

確保你已經配置了timeout屬性看看樣品AWS SNS請求代碼(來自https://stackoverflow.com/a/13016803/2318852

// Create topic 
string topicArn = client.CreateTopic(new CreateTopicRequest 
{ 
    Name = topicName 
}).CreateTopicResult.TopicArn; 

// Set display name to a friendly value 
client.SetTopicAttributes(new SetTopicAttributesRequest 
{ 
    TopicArn = topicArn, 
    AttributeName = "DisplayName", 
    AttributeValue = "StackOverflow Sample Notifications" 
}); 

// Subscribe an endpoint - in this case, an email address 
client.Subscribe(new SubscribeRequest 
{ 
    TopicArn = topicArn, 
    Protocol = "email", 
    Endpoint = "[email protected]" 
}); 

// When using email, recipient must confirm subscription 
Console.WriteLine("Please check your email and press enter when you are subscribed..."); 
Console.ReadLine(); 

// Publish message 
client.Publish(new PublishRequest 
{ 
    Subject = "Test", 
    Message = "Testing testing 1 2 3", 
    TopicArn = topicArn 
}); 

// Verify email receieved 
Console.WriteLine("Please check your email and press enter when you receive the message..."); 
Console.ReadLine(); 

// Delete topic 
client.DeleteTopic(new DeleteTopicRequest 
{ 
    TopicArn = topicArn 
}); 
+0

有什麼辦法檢查有效負載大小。就像其他人一樣,或者嘗試catch塊代碼。 –

+0

我檢查了有效載荷。在我的情況下,它是最大3kb-4kb。限制是256kb。所以我不認爲有效載荷是一個問題。@ bhavik –