Container for the parameters to the DeleteMessageBatch operation.

Deletes multiple messages. This is a batch version of DeleteMessage. The result of the delete action on each message is reported individually in the response.

IMPORTANT: Because the batch request can result in a combination of successful and unsuccessful actions, you should check for batch errors even when the call returns an HTTP status code of 200.

NOTE:Some API actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers starting from 1. For example, a parameter list with two elements looks like this:

&Attribute.1=this

&Attribute.2=that

Inheritance: AmazonSQSRequest
Exemplo n.º 1
1
        public void DeleteBatch(IQueue queue, IEnumerable<IQueueMessage> messageBatch)
        {
            var request = new DeleteMessageBatchRequest();

            messageBatch.Cast<AwsQueueMessage>()
                .Select(message => new DeleteMessageBatchRequestEntry() { Id = message.Id, ReceiptHandle = message.ReceiptHandle})
                .ForEach(entity => request.Entries.Add(entity));

            _sqsClient.DeleteMessageBatch(request);
        }
Exemplo n.º 2
1
        public async Task DoWork(CancellationToken ctx)
        {
            var response = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = SQSQueueUrl }, ctx);

            if (!response.Messages.Any())
            {
                return;
            }

            logger.LogInformation($"Processing {response.Messages.Count} messages from SQS ({string.Join(", ", response.Messages.Select(m => m.MessageId))})");

            // Delete the messages first
            var deleteBatch = new DeleteMessageBatchRequest { QueueUrl = SQSQueueUrl };
            foreach (var message in response.Messages)
            {
                deleteBatch.Entries.Add(new DeleteMessageBatchRequestEntry(message.MessageId, message.ReceiptHandle));
            }
            await sqsClient.DeleteMessageBatchAsync(deleteBatch, ctx);

            // Then run all process tasks in parallel
            await Task.WhenAll(response.Messages.Select(m => processor.ProcessMessage(m, ctx)));
        }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.SQS.Model.DeleteMessageBatchRequest();

            if (cmdletContext.Entry != null)
            {
                request.Entries = cmdletContext.Entry;
            }
            if (cmdletContext.QueueUrl != null)
            {
                request.QueueUrl = cmdletContext.QueueUrl;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
        public async Task <DeleteMessageBatchResponse> DeleteMessagesAsync(string queueUrl,
                                                                           IEnumerable <string> receiptHandles,
                                                                           CancellationToken cancellationToken = default)
        {
            this.Logger.LogDebug($"[{nameof(this.DeleteMessagesAsync)}]");

            this.Logger.LogTrace(JsonConvert.SerializeObject(new { queueUrl, receiptHandles }));

            if (string.IsNullOrWhiteSpace(queueUrl))
            {
                throw new ArgumentNullException(nameof(queueUrl));
            }
            if (receiptHandles == null)
            {
                throw new ArgumentNullException(nameof(receiptHandles));
            }
            if (receiptHandles.Count() == 0)
            {
                throw new ArgumentException(nameof(receiptHandles));
            }

            var request = new Amazon.SQS.Model.DeleteMessageBatchRequest
            {
                QueueUrl = queueUrl,
                Entries  = receiptHandles.Select(r => new DeleteMessageBatchRequestEntry(id: Guid.NewGuid().ToString(), receiptHandle: r)).ToList(),
            };

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: request));

            var response = await this.Repository.DeleteMessageBatchAsync(request : request,
                                                                         cancellationToken : cancellationToken == default?this.CancellationToken.Token : cancellationToken);

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: response));

            return(response);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Deletes up to ten messages from the specified queue. This is a batch version of <code>
 /// <a>DeleteMessage</a> </code>. The result of the action on each message is reported
 /// individually in the response.
 /// 
 ///  <important> 
 /// <para>
 /// Because the batch request can result in a combination of successful and unsuccessful
 /// actions, you should check for batch errors even when the call returns an HTTP status
 /// code of <code>200</code>.
 /// </para>
 ///  </important> <note> 
 /// <para>
 /// Some actions take lists of parameters. These lists are specified using the <code>param.n</code>
 /// notation. Values of <code>n</code> are integers starting from 1. For example, a parameter
 /// list with two elements looks like this:
 /// </para>
 ///  
 /// <para>
 ///  <code>&amp;Attribute.1=this</code> 
 /// </para>
 ///  
 /// <para>
 ///  <code>&amp;Attribute.2=that</code> 
 /// </para>
 ///  </note>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue from which messages are deleted. Queue URLs are case-sensitive.</param>
 /// <param name="entries">A list of receipt handles for the messages to be deleted.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the DeleteMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="Amazon.SQS.Model.BatchEntryIdsNotDistinctException">
 /// Two or more batch entries in the request have the same <code>Id</code>.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.EmptyBatchRequestException">
 /// The batch request doesn't contain any entries.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request doesn't abide by the specification.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.TooManyEntriesInBatchRequestException">
 /// The batch request contains more entries than permissible.
 /// </exception>
 public Task<DeleteMessageBatchResponse> DeleteMessageBatchAsync(string queueUrl, List<DeleteMessageBatchRequestEntry> entries, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new DeleteMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     return DeleteMessageBatchAsync(request, cancellationToken);
 }
Exemplo n.º 6
0
 IAsyncResult invokeDeleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new DeleteMessageBatchRequestMarshaller().Marshall(deleteMessageBatchRequest);
     var unmarshaller = DeleteMessageBatchResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteMessageBatch operation.
 /// <seealso cref="Amazon.SQS.IAmazonSQS.DeleteMessageBatch"/>
 /// </summary>
 /// 
 /// <param name="deleteMessageBatchRequest">Container for the necessary parameters to execute the DeleteMessageBatch operation on
 ///          AmazonSQS.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking
 ///         EndDeleteMessageBatch operation.</returns>
 public IAsyncResult BeginDeleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest, AsyncCallback callback, object state)
 {
     return invokeDeleteMessageBatch(deleteMessageBatchRequest, callback, state, false);
 }
Exemplo n.º 8
0
 /// <summary>
 /// <para>This is a batch version of DeleteMessage. It takes multiple receipt handles and deletes each one of the messages. The result of the
 /// delete operation on each message is reported individually in the response.</para>
 /// </summary>
 /// 
 /// <param name="deleteMessageBatchRequest">Container for the necessary parameters to execute the DeleteMessageBatch service method on
 ///          AmazonSQS.</param>
 /// 
 /// <returns>The response from the DeleteMessageBatch service method, as returned by AmazonSQS.</returns>
 /// 
 /// <exception cref="BatchEntryIdsNotDistinctException"/>
 /// <exception cref="TooManyEntriesInBatchRequestException"/>
 /// <exception cref="InvalidBatchEntryIdException"/>
 /// <exception cref="EmptyBatchRequestException"/>
 public DeleteMessageBatchResponse DeleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest)
 {
     IAsyncResult asyncResult = invokeDeleteMessageBatch(deleteMessageBatchRequest, null, null, true);
     return EndDeleteMessageBatch(asyncResult);
 }
Exemplo n.º 9
0
		internal DeleteMessageBatchResponse DeleteMessageBatch(DeleteMessageBatchRequest request)
        {
            var task = DeleteMessageBatchAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteMessageBatch operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch operation on AmazonSQSClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteMessageBatch
        ///         operation.</returns>
        public IAsyncResult BeginDeleteMessageBatch(DeleteMessageBatchRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.Instance;

            return BeginInvoke<DeleteMessageBatchRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Deletes up to ten messages from the specified queue. This is a batch version of <a>DeleteMessage</a>.
 /// The result of the delete action on each message is reported individually in the response.
 /// 
 ///  <important> 
 /// <para>
 ///  Because the batch request can result in a combination of successful and unsuccessful
 /// actions, you should check for batch errors even when the call returns an HTTP status
 /// code of 200. 
 /// </para>
 ///  </important> <note>Some API actions take lists of parameters. These lists are specified
 /// using the <code>param.n</code> notation. Values of <code>n</code> are integers starting
 /// from 1. For example, a parameter list with two elements looks like this: </note> 
 /// <para>
 /// <code>&amp;Attribute.1=this</code>
 /// </para>
 ///  
 /// <para>
 /// <code>&amp;Attribute.2=that</code>
 /// </para>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param>
 /// <param name="entries">A list of receipt handles for the messages to be deleted.</param>
 /// <param name="options">
  ///     A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
  ///     procedure using the AsyncState property.
  /// </param>
 /// 
 /// <returns>The response from the DeleteMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="Amazon.SQS.Model.BatchEntryIdsNotDistinctException">
 /// Two or more batch entries have the same <code>Id</code> in the request.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.EmptyBatchRequestException">
 /// Batch request does not contain an entry.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request does not abide by the specification.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.TooManyEntriesInBatchRequestException">
 /// Batch request contains more number of entries than permissible.
 /// </exception>
 public void DeleteMessageBatchAsync(string queueUrl, List<DeleteMessageBatchRequestEntry> entries,  AmazonServiceCallback<DeleteMessageBatchRequest, DeleteMessageBatchResponse> callback, AsyncOptions options = null)
 {
     var request = new DeleteMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     DeleteMessageBatchAsync(request, callback, options);
 }
Exemplo n.º 12
0
        IAsyncResult invokeDeleteMessageBatch(DeleteMessageBatchRequest request, AsyncCallback callback, object state, bool synchronized)
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.Instance;

            return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer);
        }
Exemplo n.º 13
0
        private void execute()
        {
            FolderVaultMapping mapping = Context.Mapping;
            ReceiveMessageRequest req = new ReceiveMessageRequest() { QueueUrl = mapping.NotificationQueueURL, MaxNumberOfMessages = 10 };
            List<QueueMessage> messages = new List<QueueMessage>();
            DeleteMessageBatchRequest deleter;
            ReceiveMessageResult result;
            List<Message> resultMessages;
            HashSet<string> exceptions = new HashSet<string>();
            long id = 0;

            using (AmazonSQSClient client = new AmazonSQSClient(mapping.AccessKey, mapping.SecretKey, mapping.Endpoint))
            {
                while (KeepRunning())
                {
                    try
                    {
                        messages.Clear();
                        result = client.ReceiveMessage(req).ReceiveMessageResult;
                        resultMessages = new List<Message>(result.Message);

                        for(int i = 0; i < resultMessages.Count; i++)
                        {
                            if (exceptions.Contains(resultMessages[i].MessageId))
                            {
                                resultMessages.RemoveAt(i);
                                i--;
                            }
                        }

                        if (resultMessages.Count > 0)
                        {
                            foreach (Message m in resultMessages)
                            {
                                try
                                {
                                    messages.Add(new QueueMessage(m.ReceiptHandle, m.MessageId, m.Body));
                                }
                                catch (InvalidDataException ex)
                                {
                                    Console.Error.WriteLine("Received an error parsing " + m.MessageId);
                                    Console.Error.WriteLine(ex);
                                    exceptions.Add(m.MessageId);
                                }
                            }

                            try
                            {
                                deleter = new DeleteMessageBatchRequest() { QueueUrl = mapping.NotificationQueueURL };

                                foreach (QueueMessage message in messages)
                                {
                                    try
                                    {
                                        Console.WriteLine("Handling a " + message.Action + " message with ID " + message.MessageId);
                                        if (message.Action == "ResultNotice" || handleMessage(message))
                                        {
                                            deleter.Entries.Add(new DeleteMessageBatchRequestEntry() { Id = "Delete" + (id++), ReceiptHandle = message.ReceiptHandle });
                                        }
                                        else
                                        {
                                            Console.WriteLine("    Unknown action");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.Error.WriteLine(ex);
                                        exceptions.Add(message.MessageId);
                                    }
                                }

                                if (deleter.Entries.Count > 0)
                                {
                                    client.DeleteMessageBatch(deleter);
                                }
                            }
                            catch(Exception ex)
                            {
                                Console.Error.WriteLine(ex);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < Settings.Default.PollInterval.TotalSeconds && KeepRunning(); i++)
                            {
                                Thread.Sleep(1000);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }

            activePollers.Remove(this);
        }
Exemplo n.º 14
0
 public Task<DeleteMessageBatchResponse> DeleteMessageBatchAsync(DeleteMessageBatchRequest request, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
        public DeleteMessageBatchResponse DeleteMessageBatch(DeleteMessageBatchRequest request)
        {
            if (request.Entries == null || request.Entries.Count <= 0)
            {
                throw new EmptyBatchRequestException("No entires in request");
            }

            if (request.Entries.Count > SqsQueueDefinition.MaxBatchDeleteItems)
            {
                throw new TooManyEntriesInBatchRequestException("Count of [{0}] exceeds limit of [{1}]".Fmt(request.Entries.Count, SqsQueueDefinition.MaxBatchDeleteItems));
            }

            var q = GetQueue(request.QueueUrl);

            var response = new DeleteMessageBatchResponse
            {
                Failed = new List<BatchResultErrorEntry>(),
                Successful = new List<DeleteMessageBatchResultEntry>()
            };

            var entryIds = new HashSet<string>();

            foreach (var entry in request.Entries)
            {
                var success = false;
                BatchResultErrorEntry batchError = null;

                try
                {
                    if (entryIds.Contains(entry.Id))
                    {
                        throw new BatchEntryIdsNotDistinctException("Duplicate Id of [{0}]".Fmt(entry.Id));
                    }

                    entryIds.Add(entry.Id);

                    success = q.DeleteMessage(new DeleteMessageRequest
                    {
                        QueueUrl = request.QueueUrl,
                        ReceiptHandle = entry.ReceiptHandle
                    });
                }
                catch (ReceiptHandleIsInvalidException rhex)
                {
                    batchError = new BatchResultErrorEntry
                    {
                        Id = entry.Id,
                        Message = rhex.Message,
                        Code = rhex.ErrorCode
                    };
                }
                catch (MessageNotInflightException mfex)
                {
                    batchError = new BatchResultErrorEntry
                    {
                        Id = entry.Id,
                        Message = mfex.Message,
                        Code = mfex.ErrorCode
                    };
                }

                if (success)
                {
                    response.Successful.Add(new DeleteMessageBatchResultEntry
                    {
                        Id = entry.Id
                    });
                }
                else
                {
                    var entryToQueue = batchError ?? new BatchResultErrorEntry
                    {
                        Id = entry.Id,
                        Message = "FakeDeleteError",
                        Code = "456"
                    };

                    response.Failed.Add(entryToQueue);
                }
            }

            return response;
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteMessageBatch operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch operation on AmazonSQSClient.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void DeleteMessageBatchAsync(DeleteMessageBatchRequest request, AmazonServiceCallback<DeleteMessageBatchRequest, DeleteMessageBatchResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new DeleteMessageBatchRequestMarshaller();
     var unmarshaller = DeleteMessageBatchResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<DeleteMessageBatchRequest,DeleteMessageBatchResponse> responseObject 
                     = new AmazonServiceResult<DeleteMessageBatchRequest,DeleteMessageBatchResponse>((DeleteMessageBatchRequest)req, (DeleteMessageBatchResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<DeleteMessageBatchRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteMessageBatch operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<DeleteMessageBatchResponse> DeleteMessageBatchAsync(DeleteMessageBatchRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.Instance;

            return InvokeAsync<DeleteMessageBatchRequest,DeleteMessageBatchResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteMessageBatch operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS.DeleteMessageBatch"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<DeleteMessageBatchResponse> DeleteMessageBatchAsync(DeleteMessageBatchRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, DeleteMessageBatchRequest, DeleteMessageBatchResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Deletes multiple messages.      This is a batch version of <a>DeleteMessage</a>. The
        /// result of the delete      action on each message is reported individually in the response.
        /// 
        ///     <important>      
        /// <para>
        ///         Because the batch request can result in a combination of successful and unsuccessful
        /// actions,         you should check for batch errors even when the call returns an HTTP
        /// status code of 200.      
        /// </para>
        ///     </important>    <note>Some API actions take lists of parameters. These lists are
        /// specified using the <code>param.n</code> notation. Values      of <code>n</code> are
        /// integers starting from 1. For example, a parameter list with two elements looks like
        /// this:     </note>    
        /// <para>
        /// <code>&amp;Attribute.1=this</code>
        /// </para>
        ///     
        /// <para>
        /// <code>&amp;Attribute.2=that</code>
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch service method.</param>
        /// 
        /// <returns>The response from the DeleteMessageBatch service method, as returned by SQS.</returns>
        /// <exception cref="BatchEntryIdsNotDistinctException">
        /// Two or more batch entries have the same <code>Id</code> in the request.
        /// </exception>
        /// <exception cref="EmptyBatchRequestException">
        /// Batch request does not contain an entry.
        /// </exception>
        /// <exception cref="InvalidBatchEntryIdException">
        /// The <code>Id</code> of a batch entry in a batch request does not abide      by the
        /// specification.
        /// </exception>
        /// <exception cref="TooManyEntriesInBatchRequestException">
        /// Batch request contains more number of entries than permissible.
        /// </exception>
        public DeleteMessageBatchResponse DeleteMessageBatch(DeleteMessageBatchRequest request)
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.Instance;

            return Invoke<DeleteMessageBatchRequest,DeleteMessageBatchResponse>(request, marshaller, unmarshaller);
        }
Exemplo n.º 20
0
    public static void SQSDeleteMessageBatch()
    {
      #region SQSDeleteMessageBatch
      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);
      var batchEntries = new List<DeleteMessageBatchRequestEntry>();

      if (response.Messages.Count > 0)
      {
        foreach (var message in response.Messages)
        {
          var batchEntry = new DeleteMessageBatchRequestEntry
          {
            Id = message.MessageId,
            ReceiptHandle = message.ReceiptHandle
          };

          batchEntries.Add(batchEntry);
        }

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

        var delResponse = client.DeleteMessageBatch(delRequest);

        if (delResponse.Failed.Count > 0)
        {
          Console.WriteLine("Failed deletions:");

          foreach (var failure in delResponse.Failed)
          {
            Console.WriteLine("  For ID '" + failure.Id + "': ");
            Console.WriteLine("    Code = " + failure.Code);
            Console.WriteLine("    Message = " + failure.Message);
            Console.WriteLine("    Sender's fault? = " + failure.SenderFault);
          }
        }

        if (delResponse.Successful.Count > 0)
        {
          Console.WriteLine("Successful deletions:");

          foreach (var success in delResponse.Successful)
          {
            Console.WriteLine("  ID '" + success.Id + "'");
          }
        }
      }
      else
      {
        Console.WriteLine("No messages to delete.");
      }
      #endregion

      Console.ReadLine();
    }
Exemplo n.º 21
0
 /// <summary>
 /// Deletes multiple messages.      This is a batch version of <a>DeleteMessage</a>. The
 /// result of the delete      action on each message is reported individually in the response.
 /// 
 ///     <important>      
 /// <para>
 ///         Because the batch request can result in a combination of successful and unsuccessful
 /// actions,         you should check for batch errors even when the call returns an HTTP
 /// status code of 200.      
 /// </para>
 ///     </important>    <note>Some API actions take lists of parameters. These lists are
 /// specified using the <code>param.n</code> notation. Values      of <code>n</code> are
 /// integers starting from 1. For example, a parameter list with two elements looks like
 /// this:     </note>    
 /// <para>
 /// <code>&amp;Attribute.1=this</code>
 /// </para>
 ///     
 /// <para>
 /// <code>&amp;Attribute.2=that</code>
 /// </para>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param>
 /// <param name="entries">A list of receipt handles for the messages to be deleted.</param>
 /// 
 /// <returns>The response from the DeleteMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="BatchEntryIdsNotDistinctException">
 /// Two or more batch entries have the same <code>Id</code> in the request.
 /// </exception>
 /// <exception cref="EmptyBatchRequestException">
 /// Batch request does not contain an entry.
 /// </exception>
 /// <exception cref="InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request does not abide      by the
 /// specification.
 /// </exception>
 /// <exception cref="TooManyEntriesInBatchRequestException">
 /// Batch request contains more number of entries than permissible.
 /// </exception>
 public DeleteMessageBatchResponse DeleteMessageBatch(string queueUrl, List<DeleteMessageBatchRequestEntry> entries)
 {
     var request = new DeleteMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     return DeleteMessageBatch(request);
 }
 private Amazon.SQS.Model.DeleteMessageBatchResponse CallAWSServiceOperation(IAmazonSQS client, Amazon.SQS.Model.DeleteMessageBatchRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Queue Service (SQS)", "DeleteMessageBatch");
     try
     {
         #if DESKTOP
         return(client.DeleteMessageBatch(request));
         #elif CORECLR
         return(client.DeleteMessageBatchAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// <para>Deletes multiple messages. This is a batch version of DeleteMessage. The result of the delete action on each message is reported
        /// individually in the response.</para> <para><b>IMPORTANT:</b> Because the batch request can result in a combination of successful and
        /// unsuccessful actions, you should check for batch errors even when the call returns an HTTP status code of 200. </para>
        /// <para><b>NOTE:</b>Some API actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers
        /// starting from 1. For example, a parameter list with two elements looks like this: </para> <para> <c>&amp;amp;Attribute.1=this</c> </para>
        /// <para> <c>&amp;amp;Attribute.2=that</c> </para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteMessageBatch service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the DeleteMessageBatch service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.BatchEntryIdsNotDistinctException" />
        /// <exception cref="T:Amazon.SQS.Model.TooManyEntriesInBatchRequestException" />
        /// <exception cref="T:Amazon.SQS.Model.InvalidBatchEntryIdException" />
        /// <exception cref="T:Amazon.SQS.Model.EmptyBatchRequestException" />
		public DeleteMessageBatchResponse DeleteMessageBatch(DeleteMessageBatchRequest request)
        {
            var task = DeleteMessageBatchAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Delete multiple messages from the queue at once 
        /// </summary>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool DeleteMessages(IList<Message> messages)
        {
            ClearErrorInfo ();

            try
            {
                var request = new DeleteMessageBatchRequest
                {
                    QueueUrl = queueurl.QueueUrl,
                    Entries = messages.Select (i => new DeleteMessageBatchRequestEntry (i.MessageId, i.ReceiptHandle)).ToList ()
                };
                var response = queue.DeleteMessageBatch (request);

                if (response.Failed != null && response.Failed.Count > 0)
                {
                    ErrorMessage = String.Format ("ErrorCount: {0}, Messages: [{1}]", response.Failed.Count,
                        String.Join (",", response.Failed.Select (i => i.Message).Distinct ()));

                    //var retryList = messages.Where (i => response.Failed.Any (j => j.Id == i.MessageId));
                    //foreach (var e in retryList)
                    //    DeleteMessage (e);
                }

                return String.IsNullOrEmpty (ErrorMessage);
            }
            catch (Exception ex)
            {
                ErrorCode    = e_Exception;
                ErrorMessage = ex.Message;
            }

            return false;
        }
Exemplo n.º 25
0
        /// <summary>
        /// <para>This is a batch version of DeleteMessage. It takes multiple receipt handles and deletes each one of the messages. The result of the
        /// delete operation on each message is reported individually in the response.</para>
        /// </summary>
        /// 
        /// <param name="deleteMessageBatchRequest">Container for the necessary parameters to execute the DeleteMessageBatch service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the DeleteMessageBatch service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.BatchEntryIdsNotDistinctException" />
        /// <exception cref="T:Amazon.SQS.Model.TooManyEntriesInBatchRequestException" />
        /// <exception cref="T:Amazon.SQS.Model.InvalidBatchEntryIdException" />
        /// <exception cref="T:Amazon.SQS.Model.EmptyBatchRequestException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<DeleteMessageBatchResponse> DeleteMessageBatchAsync(DeleteMessageBatchRequest deleteMessageBatchRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteMessageBatchRequestMarshaller();
            var unmarshaller = DeleteMessageBatchResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, DeleteMessageBatchRequest, DeleteMessageBatchResponse>(deleteMessageBatchRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Task for deleting messages from SQS
 /// </summary>
 /// <param name="state"></param>
 private void DeleteTask(CancellationToken ct, List<Message> messages, Tuple<int, int> range)
 {
     try
     {
         using (AmazonSQSClient client = new AmazonSQSClient(
                 this.AWSAccessKey, this.AWSSecretAccessKey,
                 new AmazonSQSConfig()
                     {
                         ServiceURL = this.AWSSQSServiceUrl,
                         MaxErrorRetry = 10
                     }))
         {
             DeleteMessageBatchRequest deleteRequest = new DeleteMessageBatchRequest();
             deleteRequest.QueueUrl = this.QueueUrl;
             for (int i = range.Item1; i < range.Item2; i++)
             {
                 deleteRequest.Entries.Add(new DeleteMessageBatchRequestEntry()
                 {
                     Id = messages[i].MessageId,
                     ReceiptHandle = messages[i].ReceiptHandle
                 });
                 // send 10x or the remainder of the set
                 if ((deleteRequest.Entries.Count == 10) |
                     (i == range.Item2 - 1))
                 {
                     if (ct.IsCancellationRequested)
                     {
                         break;
                     }
                     client.DeleteMessageBatch(deleteRequest);
                     deleteRequest.Entries.Clear();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         EventLog.WriteEntry(this.GetType().Name,
             ex.Message + "\n" + ex.StackTrace,
             EventLogEntryType.Error);
     }
 }