For each message in the batch, the response contains a ChangeMessageVisibilityBatchResultEntry tag if the message succeeds or a BatchResultErrorEntry tag if the message fails.
상속: Amazon.Runtime.AmazonWebServiceResponse
        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;
        }
        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;
        }
예제 #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);

        }
예제 #5
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 [{0}] exceeds limit of [{1]}".Fmt(request.Entries.Count, 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 [{0}]".Fmt(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;
        }