AWS中SQS的幾項使用注意

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

1.message能夠有參數,參數的類型鎖定在「Binary」,「Number」,「String」三類。code

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

3.鑑於參數個數限制,他的大小應當也是有限制的(還沒有測出)。blog

4.超過10個參數怎麼辦?string

   將幾個參數合併爲dictionary,後轉成binary存儲。io

 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後取值。class

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"];
相關文章
相關標籤/搜索