DeleteMessage() public method

Deletes a message.
public DeleteMessage ( Microsoft.WindowsAzure.StorageClient.CloudQueueMessage message ) : void
message Microsoft.WindowsAzure.StorageClient.CloudQueueMessage A message.
return void
示例#1
0
文件: ToDo.cs 项目: vteori/CS421-DB
        //----------------------------------------------------------------------
        // 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 void ProcessarMensagem(CloudQueue fila, CloudQueueMessage mensagem)
        {
            const int limiteDeTentativas = 3; // número máximo de tentativas de processamento da mesma mensagem

            try
            {
                if (mensagem.DequeueCount > limiteDeTentativas)
                {
                    Trace.TraceError(
                        String.Format("A mensagem não pôde ser processada após várias tentativas: '{0}'.",
                                      mensagem.AsString));
                    return;
                }

                var mensagemDeserializada = JsonConvert.DeserializeObject<dynamic>(mensagem.AsString);
                if (mensagemDeserializada == null)
                {
                    Trace.TraceError(
                        String.Format(
                            "A mensagem não é válida; a deserialização resultou em um objeto nulo: '{0}'.",
                            mensagem.AsString));
                    return;
                }

                new DespachanteDeMensagem().Despachar(mensagemDeserializada);
            }
            catch (Exception ex)
            {
                Trace.TraceError(
                    String.Format("Erro no processamento da mensagem '{0}': '{1}'.", mensagem.AsString, ex));
            }
            finally
            {
                try
                {
                    fila.DeleteMessage(mensagem); // exclui a mensagem mesmo se houve uma exceção no seu processamento
                }
                catch (Exception ex)
                {
                    Trace.TraceError(String.Format("Erro excluindo mensagem '{0}': '{1}'.", mensagem.AsString, ex));
                }
            }
        }
        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());
            }
        }
示例#4
0
 private void DeleteQueue(CloudQueue queue)
 {
     // delete all of messages in the queue
     CloudQueueMessage msg;
     while ((msg = queue.GetMessage()) != null)
     {
         queue.DeleteMessage(msg);
     }
 }
示例#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());
                }
            }
        }
示例#6
0
        private void ProcessMessage(CloudQueue inboundQueue, CloudQueue outboundQueue, CloudQueueMessage message)
        {
            if (null == message) throw new ArgumentNullException("message");
            if (null == inboundQueue) throw new ArgumentNullException("inboundQueue");
            if (null == outboundQueue) throw new ArgumentNullException("outboundQueue");

            ProcessingTask task = ProcessingTask.FromString(message.AsString);
            if (null == task)
            {
                throw new NullReferenceException("Task is null");
            }

            if (!string.IsNullOrWhiteSpace(task.InputFilename))
            {
                DownloadBlob(this.InboundBlobContainer, task.InputFilename, this.WorkingDirectory);
            }

            Tracer.WriteLine(string.Format("Starting task '{0}'", task), "Information");

            task.ProcessingTime = DateTime.UtcNow;
            Run(this.WorkingDirectory,  this.Command, task.InputFilename);
            task.ProcessingDuration = (int)(DateTime.UtcNow - task.ProcessingTime).TotalSeconds;

            if (!string.IsNullOrWhiteSpace(task.OutputFilename))
            {
                UploadBlob(this.OutboundBlobContainer, task.OutputFilename, this.WorkingDirectory);
            }

            Tracer.WriteLine(string.Format("Finished task '{0}'", task), "Information");

            outboundQueue.AddMessage(new CloudQueueMessage(task.ToString()));
            inboundQueue.DeleteMessage(message);

            Tracer.WriteLine(string.Format("Clearing up task {0}", task), "Information");
            if (!string.IsNullOrWhiteSpace(task.InputFilename))
            {
                this.DeleteFile(task.InputFilename);
            }

            if (!string.IsNullOrWhiteSpace(task.OutputFilename))
            {
                this.DeleteFile(task.OutputFilename);
            }

            Tracer.WriteLine(string.Format("Task complete '{0}'", task), "Information");
        }
示例#7
0
文件: ToDo.cs 项目: vteori/CS421-DB
        //----------------------------------------------------------------------
        // 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;
        }