private static void UnmarshallResult(XmlUnmarshallerContext context, ChangeMessageVisibilityBatchResponse 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.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Failed.Add(item);
                        continue;
                    }
                    if (context.TestExpression("ChangeMessageVisibilityBatchResultEntry", targetDepth))
                    {
                        var unmarshaller = ChangeMessageVisibilityBatchResultEntryUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Successful.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ChangeMessageVisibilityBatchResponse response = new ChangeMessageVisibilityBatchResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ChangeMessageVisibilityBatchResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Example #3
0
        public override T Unmarshall <T>(IResponseContext context)
        {
            try
            {
                var response = new ChangeMessageVisibilityBatchResponse();
                ResultUnmarshall(context, response);

                var xmlRootNode = GetXmlElement(context.ContentStream);

                if (TryGetXmlElements(xmlRootNode, "ChangeMessageVisibilityBatchResult/BatchResultErrorEntry", out var batchErrorList))
                {
                    BatchResultErrorEntryUnmarshaller(batchErrorList, response.BatchResultErrorEntry);
                }

                if (TryGetXmlElements(xmlRootNode, "ChangeMessageVisibilityBatchResult/ChangeMessageVisibilityBatchResultEntry", out var batchResultList))
                {
                    ChangeMessageVisibilityBatchResultEntryUnmarshaller(batchResultList, response.ChangeMessageVisibilityBatchResultEntry);
                }

                response.ResponseMetadata.RequestId = xmlRootNode.SelectSingleNode("ResponseMetadata/RequestId")?.InnerText;

                return(response as T);
            }
            catch (Exception ex)
            {
                throw ErrorUnmarshall(ex.Message, ex, context.StatusCode);
            }
        }
Example #4
0
        private void GenerateErrorsAndLog(ChangeMessageVisibilityBatchResponse 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 messages is set back to visible in the queue: {0} \n{1} failed.These will appear later when the global visibility time runs out. Details:\n{2}", _inputQueueAddress, result.Failed.Count, errorMessage);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, ChangeMessageVisibilityBatchResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("ChangeMessageVisibilityBatchResultEntry", targetDepth))
                    {
                        response.Successful.Add(ChangeMessageVisibilityBatchResultEntryUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                    if (context.TestExpression("BatchResultErrorEntry", targetDepth))
                    {
                        response.Failed.Add(BatchResultErrorEntryUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }



            return;
        }
Example #6
0
        public ChangeMessageVisibilityBatchResponse ChangeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request)
        {
            if (request.Entries == null || request.Entries.Count <= 0)
            {
                throw new EmptyBatchRequestException("No entires in request");
            }
            if (request.Entries.Count > SqsQueueDefinition.MaxBatchCvItems)
            {
                throw new TooManyEntriesInBatchRequestException(
                          $"Count of [{request.Entries.Count}] exceeds limit of [{SqsQueueDefinition.MaxBatchCvItems}]");
            }

            var q = GetQueue(request.QueueUrl);

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

            var entryIds = new HashSet <string>();

            foreach (var entry in request.Entries)
            {
                if (entryIds.Contains(entry.Id))
                {
                    throw new BatchEntryIdsNotDistinctException($"Duplicate Id of [{entry.Id}]");
                }

                entryIds.Add(entry.Id);

                var success = false;
                BatchResultErrorEntry batchError = null;

                try
                {
                    success = q.ChangeVisibility(new ChangeMessageVisibilityRequest
                    {
                        QueueUrl          = request.QueueUrl,
                        ReceiptHandle     = entry.ReceiptHandle,
                        VisibilityTimeout = entry.VisibilityTimeout
                    });
                }
                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 ChangeMessageVisibilityBatchResultEntry
                    {
                        Id = entry.Id
                    });
                }
                else
                {
                    var entryToQueue = batchError ?? new BatchResultErrorEntry
                    {
                        Id      = entry.Id,
                        Message = "FakeCvError",
                        Code    = "123"
                    };

                    response.Failed.Add(entryToQueue);
                }
            }

            return(response);
        }