GetMessage() public méthode

Gets a single message from the queue.
public GetMessage ( ) : Microsoft.WindowsAzure.StorageClient.CloudQueueMessage
Résultat Microsoft.WindowsAzure.StorageClient.CloudQueueMessage
Exemple #1
0
        //----------------------------------------------------------------------
        // ToDo.CountMutualFriends
        //
        // Input   : requestQueue - queue to sent messages to worker roles
        //           responseQueue - queue to receive messages from worker roles
        // Return  : A dictionary which contains the number of mutual friends for each user
        // Purpose : Count the number of mutual friends for each user
        // Note    : You should implement the case of arriving messages from worker roles via responseQueue.
        //           The messages have numbers of mutual friends for each user
        //           in a way you describe in ToDo.CountMutualFriendsInEachWorkerRole.
        //           You should check whether there is a message of the counts in the responseQueue,
        //           and aggregate the counts from worker roles.
        //
        // * Data type of dictionary which will be returned is Dictionary<int, int>.
        //   Key (first generic type parameter) of this dictionary indicates user ID.
        //   Value (second generic type parameter) of this dictionary indicates
        //    the number of mutual friends of the user.
        //----------------------------------------------------------------------
        public static Dictionary<int, int> CountMutualFriends(CloudQueue requestQueue, CloudQueue responseQueue)
        {
            Dictionary<int, int> countMutualFriends = new Dictionary<int, int>();

            // request each worker role to count mutual friends it found
            for (int i = 0; i < ToDo.NumWorkerRoleInstances; i++)
                requestQueue.AddMessage(new CloudQueueMessage("COUNT_MUTUAL_FRIENDS_#" + i));

            // wait for finishing all of worker roles
            int numFinishedRoles = 0;
            while (numFinishedRoles < ToDo.NumWorkerRoleInstances)
            {
                // retrieve a new message from the queue
                CloudQueueMessage msg = responseQueue.GetMessage();
                if (msg == null)
                {
                    System.Threading.Thread.Sleep(sleepTime);
                    continue;
                }

                // remove message from queue
                responseQueue.DeleteMessage(msg);

                string msgStr = msg.AsString;

                if (msgStr.StartsWith("COMPLETE_COUNTING_MUTUAL_FRIENDS"))
                {
                    numFinishedRoles++;
                }
                else
                {
                    // YOU MUST IMPLEMENT ADDITIONAL CODE HERE
                    //
                    // * To receive the number of friends of users from worker roles, using response queue,
                    //
                    // check whether there is a message for the counts in the response queue,
                    // and aggregate the counts from every worker role.

                    String[] split = msgStr.Split(new Char[] { ':' });
                    int key = Convert.ToInt32(split[0]);
                    int value = Convert.ToInt32(split[1]);

                    if (countMutualFriends.ContainsKey(key))
                        countMutualFriends[key] += value;
                    else
                        countMutualFriends.Add(key, value);
                }
            }

            return countMutualFriends;
        }
        private static IEnumerable<CloudQueueMessage> ObterMensagens(CloudQueue fila)
        {
            TimeSpan tempoDeInvisibilidade = TimeSpan.FromMinutes(60);
                // um valor bem alto para não interferir nos testes

            while (true)
            {
                CloudQueueMessage mensagem = fila.GetMessage(tempoDeInvisibilidade);
                if (mensagem != null)
                {
                    yield return mensagem;
                }
                else
                {
                    yield break;
                }
            }
        }
        public void PollForMessage(CloudQueue queue)
        {
            var message = queue.GetMessage();
            if (message == null)
            {
                Thread.Sleep(500);
                return;
            }

            try
            {
                this.Handle(message);
                queue.DeleteMessage(message);
            }
            catch (Exception e)
            {
                if (e.IsUnsafeToSuppress())
                {
                    throw;
                }
                Trace.TraceError(e.ToString());
            }
        }
Exemple #4
0
 private void DeleteQueue(CloudQueue queue)
 {
     // delete all of messages in the queue
     CloudQueueMessage msg;
     while ((msg = queue.GetMessage()) != null)
     {
         queue.DeleteMessage(msg);
     }
 }
Exemple #5
0
        public override void Run()
        {
            Trace.WriteLine("BackgroundProcesses entry point called", "Information");
            Trace.WriteLine(Thread.CurrentThread.Name, "Information");
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
                Trace.WriteLine("storage account configured", "Information");
                queueClient = storageAccount.CreateCloudQueueClient();
                queue = queueClient.GetQueueReference(messageQueueName);
                queue.CreateIfNotExist();
                queue.Clear();
            }
            catch (Exception e)
            {
                LogAccessor logAccessor = new LogAccessor();
                logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString());
            }
            while (true)
            {
                try
                {
                    CloudQueueMessage msg = queue.GetMessage();

                    if (msg != null)
                    {
                        Trace.WriteLine("Queue Message Recieved", "Information");
                        // parse message retrieved from queue
                        string userFullName = "";
                        string presetDocURL = "";
                        var messageParts = msg.AsString.Split(new char[] { ',' });
                        var mediaURI = messageParts[0];
                        int ID = Int32.Parse(messageParts[1]);
                        var operation = messageParts[2];
                        var type = messageParts[3];
                        int displayWidth = Int32.Parse(messageParts[4]);
                        int displayHeight = Int32.Parse(messageParts[5]);
                        try
                        {
                            userFullName = messageParts[6];
                            presetDocURL = messageParts[7];
                        }
                        catch (Exception)
                        {

                        }
                        if (operation.Equals("thumbnail"))
                        {
                            UploadManager uploadManager = new UploadManager();

                            string thumbnailURI = uploadManager.generateThumbnail(mediaURI, ID, type, displayWidth, displayHeight, presetDocURL);
                        }
                        else if (operation.Equals("documentConversion"))
                        {
                            UploadManager uploadManager = new UploadManager();
                            uploadManager.convertDocument(mediaURI, type, ID, userFullName, presetDocURL);
                        }
                        else if (operation.Equals("userDocumentConversion"))
                        {
                            UploadManager uploadManager = new UploadManager();
                            uploadManager.convertUserDocument(mediaURI, type, ID, userFullName, presetDocURL);
                        }
                        queue.DeleteMessage(msg);
                    }

                    Thread.Sleep(500);
                    //Trace.WriteLine("Working - thread sleep", "Information");
                }
                catch (Exception e)
                {
                    LogAccessor logAccessor = new LogAccessor();
                    logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString());
                }
            }
        }
Exemple #6
0
        //----------------------------------------------------------------------
        // ToDo.FindMutualFriends
        //
        // Input   : requestQueue - queue data structure to send messages to worker roles
        //           responseQueue - queue data structure to receive messages from worker roles
        // Return  : Number of mutual friend pairs
        //           (summation of the number of mutual friend pairs found from worker roles)
        // Purpose : Find every mutual friend pair, that means, do a self-join on follower table.
        // Note    :
        //----------------------------------------------------------------------
        public static int FindMutualFriends(CloudQueue requestQueue, CloudQueue responseQueue)
        {
            int numMutualFriends = 0;

            // send a request to each worker role for finding mutual friends
            for (int i = 0; i < ToDo.NumWorkerRoleInstances; i++)
                requestQueue.AddMessage(new CloudQueueMessage("FIND_MUTUAL_FRIENDS_#" + i));

            // wait for finishing every worker role
            int numFinishedInstances = 0;
            while (numFinishedInstances < ToDo.NumWorkerRoleInstances)
            {
                // retrieve a new response message from queue
                CloudQueueMessage msg = responseQueue.GetMessage();
                if (msg == null)
                {
                    System.Threading.Thread.Sleep(sleepTime);
                    continue;
                }

                // remove the response message from queue
                responseQueue.DeleteMessage(msg);

                string msgStr = msg.AsString;

                if (msgStr.StartsWith("COMPLETE_FINDING_MUTUAL_FRIENDS "))
                {
                    // a worker role instance finished finding mutual friends
                    numFinishedInstances++;

                    numMutualFriends += int.Parse(msgStr.Substring(msgStr.LastIndexOf(" ") + 1));
                }
                else
                {
                    System.Diagnostics.Trace.TraceError("Unexpected message!!! (" + msgStr + ")");
                }
            }

            return numMutualFriends/2;
        }