AWS中SQS的幾項使用注意


AWS中的SQS收發message時,有幾點需要注意:

1.message可以有參數,參數的類型鎖定在“Binary”,“Number”,“String”三類。

2.message的參數有個數限制,限制在10個(小於或等於10個)。

3.鑒於參數個數限制,他的大小應當也是有限制的(尚未測出)。

4.超過10個參數怎么辦?

   將幾個參數合並為dictionary,后轉成binary存儲。

 1 Dictionary<string, int> dicIntParat = new Dictionary<string, int>();
 2             dicIntParat["DataDownloadID"] = _dataDownload.DataDownloadID;
 3             dicIntParat["CreateUserID"] = _dataDownload.CreateUserID;
 4             dicIntParat["TopicClientID"] = _dataDownload.TopicClientID;
 5             dicIntParat["ProcessStatusID"] = _dataDownload.ProcessStatusID;
 6             MemoryStream msNumber = new MemoryStream();
 7             BinaryFormatter bf = new BinaryFormatter();
 8             bf.Serialize(msNumber, dicIntParat);
 9             
10             MessageAttributeValue DataDownloadIDValue = new MessageAttributeValue();
11             DataDownloadIDValue.DataType = "Binary";
12             DataDownloadIDValue.BinaryValue = msNumber;
13             sendMessageRequest.MessageAttributes["DataDownloadID"] = DataDownloadIDValue;

讀取message時,也相應的將Binary轉換成dictionary后取值。

1  MemoryStream msNumber = new MemoryStream();
2                             BinaryFormatter bf = new BinaryFormatter();
3                             msNumber = result.Messages[i].MessageAttributes["DataDownloadID"].BinaryValue;
4                             Dictionary<string, int> dicIntParat = (Dictionary<string, int>)bf.Deserialize(msNumber);
5 
6 dd.DataDownloadID = dicIntParat["DataDownloadID"];
7 dd.CreateUserID = dicIntParat["CreateUserID"];
8 dd.TopicClientID = dicIntParat["TopicClientID"];
9 dd.ProcessStatusID = dicIntParat["ProcessStatusID"];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM