2017-12-27 406 views
0

在一個項目中,我的要求是獲得天藍色的死亡信件數。如果計數大於0,那麼我必須得到每個死信的詳細信息,如死信的描述或原因,然後保存到cosmos數據庫中。 要獲得一紙空文計數我使用代碼:獲取天藍色的死亡信息並保存到宇宙數據庫中

NamespaceManager namespaceManager=Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(sbConnectionString);  
var abc = namespaceManager.GetQueue("").MessageCountDetails;   
var deadLetterCount = messageDetails.DeadLetterMessageCount;  

,並保存到宇宙數據庫,代碼爲:

DocumentDBModel objItem = new DocumentDBModel();  
       objItem.DeadLetterReason = "TestReason";  
       objItem.DeadLetterDescription = "TestDescription"; 
       objItem.DeadLetterDate = DateTime.Now;  
       objItem.Body = "TestBody";  
       DbSettings objSettings = new DbSettings();  
       objSettings.Uri = "";  
       objSettings.Key = "";  
       objSettings.DatabaseId = "TestDB";  
       objSettings.Collection = "TestCollection";   
       DocumentDBRepository<DocumentDBModel> abc = new 
     DocumentDBRepository<DocumentDBModel>(objSettings);  
       abc.CreateAsync(objItem).Wait();  

但是當我運行上面的代碼,我本着讓例外:

var abc = namespaceManager.GetQueue("").MessageCountDetails;  


<b> Method not found: 'Void System.Runtime.Serialization.DataContractSerializer..ctor(System.Type, System.Collections.Generic.IEnumerable`1<System.Type>, Int32, Boolean, Boolean, System.Runtime.Serialization.IDataContractSurrogate)'. 
    at Microsoft.ServiceBus.Messaging.MessagingDescriptionSerializer`1.CreateSerializer[T]() 
    at Microsoft.ServiceBus.Messaging.MessagingDescriptionSerializer`1..ctor() 
    at Microsoft.ServiceBus.Messaging.ServiceBusResourceOperations.GetAsyncResult`1..ctor(TrackingContext trackingContext, IResourceDescription[] collectionDescriptions, String[] collectionResourceNames, IEnumerable`1 managementAddresses, NamespaceManagerSettings settings, TimeSpan timeout, AsyncCallback callback, Object state) 
    at Microsoft.ServiceBus.NamespaceManager.OnBeginGetQueue(String path, AsyncCallback callback, Object state) 
    at Microsoft.ServiceBus.NamespaceManager.GetQueue(String path) 
    at WebApplication2.Controllers.ValuesController.Get() </b> 

請建議可能是什麼原因導致此問題。 - 列表項

+0

Web應用程序中[WindowsAzure.ServiceBus](https://www.nuget.org/packages/WindowsAzure.ServiceBus/)的版本是什麼?您是否正在創建網絡核心Web應用程序,目標框架是什麼? –

+0

我正在使用WIndowsAzure.ServiceBus版本2.1.0和框架是ASP.Net核心2.0 –

回答

1

由於WindowsAzure.ServiceBus注意事項如下:

請注意,這個包需要.NET框架4.5.2全部檔案。

此外,我可能遇到與使用WIndowsAzure.ServiceBus 2.1.0時提到的相同的問題。另外,我已經檢查了其他版本,但最終失敗了。

對磊科2.0,你可以充分利用.NET Standard client library for Azure Service Bus和引用包Microsoft.Azure.ServiceBus。爲了檢索死信隊列,你可以按照這個tutorial

我的要求是得到天藍色的死書。如果計數大於0,那麼我必須得到每個死信的詳細信息,如死信的描述或原因,然後保存到cosmos數據庫中。

我注意到你在WebAPI端點內處理這個處理。我建議你註冊MessageReceiver.RegisterMessageHandlerDeadletterQueue/Program.cs中提到的回調,然後在.NET Core 2.x中將它作爲後臺任務來實現。詳情你可以關注here

此外,你可以從你的web應用程序分發這個處理。您可以利用WebJob來觸發您的服務總線死區信息隊列(例如,特定隊列的死信隊列名稱如下所示:$"{your-queue-name}/$DeadLetterQueue"),並使用DocumentDB綁定將死信號隊列信息保存到您的cosmos數據庫中。詳情請參考How to use Azure Service Bus with the WebJobs SDKAzure WebJobs SDK Extensions

+0

非常感謝您的支持。我會嘗試你的建議。 –

相關問題