• 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"];
  • 相关阅读:
    NPOI开发手记
    jQuery.form开发手记
    jQuery.Flot开发手记
    node.js初探
    Linux私房菜阅读笔记
    c#实现常用排序算法
    Excel自定义函数开发手记
    浅谈知识管理
    Git学习手记
    c# 屏蔽快捷键
  • 原文地址:https://www.cnblogs.com/riusmary/p/8521352.html
Copyright © 2020-2023  润新知