新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于云存儲(chǔ)實(shí)現(xiàn)用Windows Azure Storage增強(qiáng)應(yīng)用程序的引擎

        基于云存儲(chǔ)實(shí)現(xiàn)用Windows Azure Storage增強(qiáng)應(yīng)用程序的引擎

        作者: 時(shí)間:2010-04-17 來(lái)源:網(wǎng)絡(luò) 收藏

          現(xiàn)在,我們需要一個(gè)簡(jiǎn)單的包裝來(lái)與我們的隊(duì)列交互。從本質(zhì)上說(shuō),我們需要能夠?qū)⑾⒉迦腙?duì)列,獲取任何掛起的消息并清除該隊(duì)列(請(qǐng)參見圖 3)。

          圖 3 用于與隊(duì)列交互的包裝

        namespace HollywoodHackers..Queue 
        { 
          public class StdQueueT> : 
          Base where T : QueueMessageBase, new() 
          { 
            protected CloudQueue queue; 
            protected CloudQueueClient client; 
         
            public StdQueue(string queueName) 
            { 
              client = new CloudQueueClient 
              (Base.QueueBaseUri, StorageBase.Credentials); 
              queue = client.GetQueueReference(queueName); 
              queue.CreateIfNotExist(); 
            } 
            public void AddMessage(T message) 
            { 
              CloudQueueMessage msg = 
              new CloudQueueMessage(message.ToBinary()); 
              queue.AddMessage(msg); 
            } 
            public void DeleteMessage(CloudQueueMessage msg) 
            { 
              queue.DeleteMessage(msg); 
            } 
            public CloudQueueMessage GetMessage() 
            { 
              return queue.GetMessage(TimeSpan.FromSeconds(60)); 
            } 
          } 
          public class ToastQueue : StdQueueToastQueueMessage> 
          { 
            public ToastQueue() 
              : base(toasts) 
            { 
            } 
          } 
        }

        我們還需要為表設(shè)置一個(gè)包裝,以便在用戶登錄到站點(diǎn)之前可以用戶通知。可以使用 PartitionKey(行集合的標(biāo)識(shí)符)和 RowKey(可唯一標(biāo)識(shí)特定分區(qū)中的每個(gè)單獨(dú)行)組織表數(shù)據(jù)。選擇 PartitionKey 和 RowKey 使用的數(shù)據(jù)是在使用表時(shí)所做的最重要的設(shè)計(jì)決策之一。

          這些特點(diǎn)允許跨存儲(chǔ)節(jié)點(diǎn)進(jìn)行負(fù)載平衡,并在中提供內(nèi)置的可伸縮性選項(xiàng)。不考慮數(shù)據(jù)的數(shù)據(jù)中心關(guān)聯(lián)性,使用同一分區(qū)鍵的表存儲(chǔ)中的行將保留在相同的物理數(shù)據(jù)存儲(chǔ)中。因?yàn)獒槍?duì)每個(gè)用戶存儲(chǔ)對(duì)應(yīng)的消息,所以分區(qū)鍵將是 UserName,而 RowKey 則成為標(biāo)識(shí)每行的 GUID(請(qǐng)參見圖 4)。

          圖 4 表存儲(chǔ)的包裝

        namespace HollywoodHackers.Storage.Repositories 
        { 
          public class UserTextNotificationRepository : StorageBase 
          { 
            public const string EntitySetName = 
            UserTextNotifications; 
            CloudTableClient tableClient; 
            UserTextNotificationContext notificationContext; 
            public UserTextNotificationRepository() 
              : base() 
            { 
              tableClient = new CloudTableClient 
              (StorageBase.TableBaseUri, StorageBase.Credentials); 
              notificationContext = new UserTextNotificationContext 
              (StorageBase.TableBaseUri,StorageBase.Credentials); 
         
              tableClient.CreateTableIfNotExist(EntitySetName); 
            } 
            public UserTextNotification[] 
            GetNotificationsForUser(string userName) 
            { 
              var q = from notification in 
                  notificationContext.UserNotifications 
                  where notification.TargetUserName == 
                  userName select notification; 
              return q.ToArray(); 
            } 
            public void AddNotification 
            (UserTextNotification notification) 
            { 
              notification.RowKey = Guid.NewGuid().ToString(); 
              notificationContext.AddObject 
              (EntitySetName, notification); 
              notificationContext.SaveChanges(); 
            } 
          } 
        }



        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 西昌市| 米林县| 广东省| 连城县| 漳州市| 满洲里市| 家居| 简阳市| 大埔区| 太保市| 大兴区| 成武县| 清涧县| 英吉沙县| 曲阳县| 财经| 朔州市| 陇川县| 永城市| 桂东县| 孝昌县| 桦南县| 靖宇县| 加查县| 桃江县| 万全县| 乡城县| 翁牛特旗| 裕民县| 南平市| 久治县| 青田县| 大厂| 大石桥市| 永德县| 前郭尔| 阳城县| 淳安县| 兰溪市| 东乡县| 鹿邑县|