当前位置: 首页>>代码示例>>C#>>正文


C# AmazonSQSClient.DeleteMessage方法代码示例

本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.DeleteMessage方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.DeleteMessage方法的具体用法?C# AmazonSQSClient.DeleteMessage怎么用?C# AmazonSQSClient.DeleteMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.SQS.AmazonSQSClient的用法示例。


在下文中一共展示了AmazonSQSClient.DeleteMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            // AWS: Get instance public address
            string myId = "localhost";
            try
            {
                myId = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
            }
            catch
            {
            }

            // AWS SQS Client
            var sqsClient = new AmazonSQSClient();

            while (true)
            {
                // Get the next message
                ReceiveMessageRequest request = new ReceiveMessageRequest()
                    .WithQueueUrl("https://queue.amazonaws.com/*****/codeCampDemo")
                    .WithMaxNumberOfMessages(1);
                var response = sqsClient.ReceiveMessage(request);

                foreach (var retrievedMessage in response.ReceiveMessageResult.Message)
                {
                    var messageJson = JsonValue.Parse(retrievedMessage.Body);

                    var message = messageJson["message"].ReadAs<string>();

                    Console.WriteLine(message);

                    message = "Echo: " + message;

                    string address = string.Format("http://{0}", messageJson["sender"].ReadAs<string>());
                    var connection = new HubConnection(address);
                    connection.Start().Wait();

                    IHubProxy pongHub = connection.CreateProxy("MvcWebRole1.Hubs.EchoHub");
                    pongHub.Invoke("DoUpdateMessage", message, myId).Wait();

                    //Process the message and then delete the message
                    DeleteMessageRequest deleteRequest = new DeleteMessageRequest()
                        .WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
                        .WithReceiptHandle(retrievedMessage.ReceiptHandle);
                    sqsClient.DeleteMessage(deleteRequest);
                }

                Thread.Sleep(1000);
            }
        }
开发者ID:igormoochnick,项目名称:EndToEndDistributedAppAws,代码行数:50,代码来源:WorkerRole.cs

示例2: DequeueByQueueUrl

        public static string DequeueByQueueUrl(string queueUrl)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new ReceiveMessageRequest()
                {
                    QueueUrl = queueUrl
                };

                var response = client.ReceiveMessage(request).Messages.First();

                var body = response.Body;

                var deleteRequest = new DeleteMessageRequest
                {
                    QueueUrl = queueUrl,
                    ReceiptHandle = response.ReceiptHandle
                };

                client.DeleteMessage(deleteRequest);

                return body;
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:24,代码来源:Repository.cs

示例3: RemoveMessage

 public virtual void RemoveMessage(AmazonSQSClient sqsClient, string queueUrl, string receiptHandle)
 {
     // Create the request
     var deleteMessageRequest = new DeleteMessageRequest
     {
         ReceiptHandle = receiptHandle,
         QueueUrl = queueUrl
     };
     // Submit the request
     sqsClient.DeleteMessage(deleteMessageRequest);
 }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:11,代码来源:SolutionCode.cs

示例4: Main

        public static void Main(string[] args)
        {
            IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USWest2);

            try
            {
                Console.WriteLine("===========================================");
                Console.WriteLine("Getting Started with Amazon SQS");
                Console.WriteLine("===========================================\n");                
                
                //Creating a queue
                Console.WriteLine("Create a queue called MyQueue.\n");
                CreateQueueRequest sqsRequest = new CreateQueueRequest();
                sqsRequest.QueueName = "MyQueue";
                CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
                String myQueueUrl;
                myQueueUrl = createQueueResponse.QueueUrl;

                //Confirming the queue exists
                ListQueuesRequest listQueuesRequest = new ListQueuesRequest();
                ListQueuesResponse listQueuesResponse = sqs.ListQueues(listQueuesRequest);

                Console.WriteLine("Printing list of Amazon SQS queues.\n");
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    Console.WriteLine("  QueueUrl: {0}", queueUrl);
                }
                Console.WriteLine();

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                SendMessageRequest sendMessageRequest = new SendMessageRequest();
                sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation
                sendMessageRequest.MessageBody = "This is my message text.";
                sqs.SendMessage(sendMessageRequest);
                
                //Receiving a message
                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.QueueUrl = myQueueUrl;
                ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);

                Console.WriteLine("Printing received message.\n");
                foreach (Message message in receiveMessageResponse.Messages)
                {
                    Console.WriteLine("  Message");
                    Console.WriteLine("    MessageId: {0}", message.MessageId);
                    Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                    Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                    Console.WriteLine("    Body: {0}", message.Body);

                    foreach (KeyValuePair<string, string> entry in message.Attributes)
                    {
                        Console.WriteLine("  Attribute");
                        Console.WriteLine("    Name: {0}", entry.Key);
                        Console.WriteLine("    Value: {0}", entry.Value);
                    }
                }
                String messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;

                //Deleting a message
                Console.WriteLine("Deleting the message.\n");
                DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
                deleteRequest.QueueUrl = myQueueUrl;
                deleteRequest.ReceiptHandle = messageRecieptHandle;
                sqs.DeleteMessage(deleteRequest);

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
开发者ID:jamisliao,项目名称:aws-sdk-net-samples,代码行数:79,代码来源:Program.cs

示例5: Reject

        /// <summary>
        /// Rejects the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="requeue">if set to <c>true</c> [requeue].</param>
        public void Reject(Message message, bool requeue)
        {
            if (!message.Header.Bag.ContainsKey("ReceiptHandle"))
                return;

            var receiptHandle = message.Header.Bag["ReceiptHandle"].ToString();

            try
            {
                _logger.InfoFormat("SqsMessageConsumer: Rejecting the message {0} with receipt handle {1} on the queue {2} with requeue paramter {3}", message.Id, receiptHandle, _queueUrl, requeue);
                
                using (var client = new AmazonSQSClient())
                {
                    if (requeue)
                    {
                        client.ChangeMessageVisibility(new ChangeMessageVisibilityRequest(_queueUrl, receiptHandle, 0));
                    }
                    else
                    {
                        client.DeleteMessage(_queueUrl, receiptHandle);
                    }
                }

                _logger.InfoFormat("SqsMessageConsumer: Message {0} with receipt handle {1} on the queue {2} with requeue paramter {3} has been rejected", message.Id, receiptHandle, _queueUrl, requeue);
            }
            catch (Exception exception)
            {
                _logger.ErrorException("SqsMessageConsumer: Error during rejecting the message {0} with receipt handle {1} on the queue {2}", exception, message.Id, receiptHandle, _queueUrl);
                throw;
            }
        }
开发者ID:andrewm1986,项目名称:Paramore,代码行数:36,代码来源:SQSMessageConsumer.cs

示例6: SQSDeleteMessage

    public static void SQSDeleteMessage()
    {
      #region SQSDeleteMessage
      var client = new AmazonSQSClient();

      var request = new ReceiveMessageRequest
      {
        AttributeNames = new List<string>() { "All" },
        MaxNumberOfMessages = 5,
        QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue",
        VisibilityTimeout = (int)TimeSpan.FromMinutes(10).TotalSeconds,
        WaitTimeSeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds
      };

      var response = client.ReceiveMessage(request);

      if (response.Messages.Count > 0)
      {
        foreach (var message in response.Messages)
        {
          Console.Write("Message ID '" + message.MessageId + "' ");

          var delRequest = new DeleteMessageRequest
          {
            QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue",
            ReceiptHandle = message.ReceiptHandle
          };

          var delResponse = client.DeleteMessage(delRequest);
        }
      }
      else
      {
        Console.WriteLine("No messages to delete.");
      }
      #endregion

      Console.ReadLine();
    }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:39,代码来源:SQSSamples.cs


注:本文中的Amazon.SQS.AmazonSQSClient.DeleteMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。