Returns information about the DeleteMessageBatch response and response metadata.
Inheritance: DeleteMessageBatchResult
Beispiel #1
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteMessageBatchResponse response = new DeleteMessageBatchResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {                    
                    if(context.TestExpression("DeleteMessageBatchResult", 2))
                    {
                        UnmarshallResult(context,response);                        
                        continue;
                    }
                    
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }

            return response;
        }
Beispiel #2
0
        private static void UnmarshallResult(XmlUnmarshallerContext context,DeleteMessageBatchResponse response)
        {
            
            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            
            if (context.IsStartOfDocument) 
               targetDepth += 2;
            
            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {

                    if (context.TestExpression("BatchResultErrorEntry", targetDepth))
                    {
                        var unmarshaller = BatchResultErrorEntryUnmarshaller.GetInstance();
                        var item = unmarshaller.Unmarshall(context);
                        response.Failed.Add(item);
                        continue;
                    }
                    if (context.TestExpression("DeleteMessageBatchResultEntry", targetDepth))
                    {
                        var unmarshaller = DeleteMessageBatchResultEntryUnmarshaller.GetInstance();
                        var item = unmarshaller.Unmarshall(context);
                        response.Successful.Add(item);
                        continue;
                    }
                } 
           }

            return;
        }
Beispiel #3
0
        private void GenerateErrorsAndLog(DeleteMessageBatchResponse result)
        {

            var failedMessages = String.Join("\n", result.Failed.Select(f => String.Format("Code:{0}, Id:{1}, Error:{2}", f.Code, f.Id, f.Message)));
            var errorMessage = "There were 1 or more errors when sending messages on commit." + failedMessages;

            if (result.Successful.Any())
                errorMessage += "\n These message went through the loophole:\n" + String.Join(", ", result.Successful.Select(s => s.Id));

            _log.Warn("Not all completed messages is removed from the queue: {0} \n{1} failed.\n{2}", _inputQueueAddress, result.Failed.Count, errorMessage);
        }
        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;
        }