コード例 #1
0
        private static async Task <Message> ReadAmazonSqsEvent(string queueUrl, int waitTimeoutSPerMessageSeconds)
        {
            using (AmazonSQSClient sqsClient = new AmazonSQSClient())
            {
                ReceiveMessageResponse receiveMessageResponse =
                    await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest(queueUrl)
                {
                    WaitTimeSeconds       = waitTimeoutSPerMessageSeconds,
                    MessageAttributeNames = new List <string> {
                        "All"
                    },
                    MaxNumberOfMessages = 1
                });

                Message message = receiveMessageResponse.Messages.Count == 1
                    ? GetMessage(receiveMessageResponse.Messages.First())
                    : null;

                if (message != null)
                {
                    DeleteMessageResponse response =
                        await sqsClient.DeleteMessageAsync(queueUrl,
                                                           receiveMessageResponse.Messages.First().ReceiptHandle);
                }

                return(message);
            }
        }
コード例 #2
0
ファイル: AWSComponent.cs プロジェクト: llinq/Interact
        public void RemoveQueueObjects(string queueUrl, RegionEndpoint region, string receiptHandle)
        {
            if (queueUrl.NullOrEmpty())
            {
                throw new ArgumentException("Queue url is required.");
            }


            using (var client = new AmazonSQSClient(_Credentials, region))
            {
                DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();

                deleteMessageRequest.QueueUrl      = queueUrl;
                deleteMessageRequest.ReceiptHandle = receiptHandle;

                DeleteMessageResponse response = client.DeleteMessageAsync(deleteMessageRequest).Result;

                var acceptedCodes = new List <HttpStatusCode>
                {
                    HttpStatusCode.Accepted,
                    HttpStatusCode.OK,
                    HttpStatusCode.NoContent
                };

                if (!acceptedCodes.Contains(response.HttpStatusCode))
                {
                    throw new AWSQueueMessageException($"Error on remove the message: {response.ResponseMetadata}");
                }
            }
        }
コード例 #3
0
        private bool DeleteMessageFromQueue(string msgReceiptHandle)
        {
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();

            if (useFIFOQueue == true)
            {
                deleteMessageRequest.QueueUrl = Configurations.FIFOQueueURL;
            }
            else
            {
                deleteMessageRequest.QueueUrl = Configurations.QueueURL;
            }

            deleteMessageRequest.ReceiptHandle = msgReceiptHandle;

            DeleteMessageResponse response =
                sqsClient.DeleteMessage(deleteMessageRequest);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
ファイル: SQSConsumer.cs プロジェクト: dutchbr/aws-sqs-demo
 public void start()
 {
     isRunning = true;
     try
     {
         while (true)
         {
             Thread.Sleep(1000);
             ReceiveMessageResponse response = amazonSQSClient.ReceiveMessageAsync(receiveMessageRequest).Result;
             if (response.Messages.Any())
             {
                 foreach (Amazon.SQS.Model.Message message in response.Messages)
                 {
                     if (receiver != null)
                     {
                         bool ack = true;
                         receiver.onMessage(message.Body, ack);
                         if (ack)
                         {
                             var deleteMessageRequest = new DeleteMessageRequest();
                             deleteMessageRequest.QueueUrl      = _queueUrl;
                             deleteMessageRequest.ReceiptHandle = message.ReceiptHandle;
                             DeleteMessageResponse result = amazonSQSClient.DeleteMessageAsync(deleteMessageRequest).Result;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         isRunning = false;
     }
 }
コード例 #5
0
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            var response = new DeleteMessageResponse();

            // Nothing need to do with this response here
            return(response);
        }
コード例 #6
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteMessageResponse response = new DeleteMessageResponse();

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

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

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

            return(response);
        }
コード例 #7
0
        private async Task DeleteMessageAsync(string recieptHandle)
        {
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();

            deleteMessageRequest.QueueUrl      = _queueUrl;
            deleteMessageRequest.ReceiptHandle = recieptHandle;

            DeleteMessageResponse response = await _sqsClient.DeleteMessageAsync(deleteMessageRequest);
        }
コード例 #8
0
        public DeleteMessageResponse DeleteMessage(string queueUrl, string messageHandle)
        {
            var deleteRequest = new DeleteMessageRequest {
                QueueUrl = queueUrl, ReceiptHandle = messageHandle
            };
            DeleteMessageResponse deleteResponse = SQSClient.DeleteMessage(deleteRequest);

            return(deleteResponse);
        }
コード例 #9
0
        /// <summary>
        /// delete a message from the queue
        /// </summary>
        /// <param name="messageId"></param>
        public bool DeleteMessage(string recieptHandle)
        {
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest
            {
                QueueUrl      = _QueueUrl,
                ReceiptHandle = recieptHandle
            };
            DeleteMessageResponse awsResp = _AmazonSQSClient.DeleteMessageAsync(deleteMessageRequest).Result;

            return(awsResp.HttpStatusCode == System.Net.HttpStatusCode.OK);
        }
コード例 #10
0
        private static async Task <string> DeleteMessage(List <string> results, Message message, string queueUrl)
        {
            var deleteMessageRequest = new DeleteMessageRequest()
            {
                QueueUrl      = queueUrl,
                ReceiptHandle = message.ReceiptHandle
            };
            DeleteMessageResponse delResponse = await _sqsClient.DeleteMessageAsync(deleteMessageRequest);

            return($"Message {message.Body} deleted with status {delResponse.HttpStatusCode}");
        }
コード例 #11
0
        public static string Delete(string queue_url, string msg_id)
        {
            AmazonSQS            sqs      = AWSClientFactory.CreateAmazonSQSClient();
            DeleteMessageRequest d_msgreq = new DeleteMessageRequest();

            d_msgreq.QueueUrl      = queue_url;
            d_msgreq.ReceiptHandle = msg_id;
            DeleteMessageResponse d_msgres = sqs.DeleteMessage(d_msgreq);

            return("Deleted Message \n" + d_msgres.ResponseMetadata.ToString());
        }
コード例 #12
0
        private void DeleteMessge(Amazon.SQS.Model.Message message)
        {
            DeleteMessageResponse objDeleteMessageResponse = new DeleteMessageResponse();
            var deleteMessageRequest = new DeleteMessageRequest()
            {
                QueueUrl = sellerInfo.QueueUrl, ReceiptHandle = message.ReceiptHandle
            };

            objDeleteMessageResponse = sqsClient.DeleteMessage(deleteMessageRequest);
            nLogger.Log(LogLevel.Info, string.Format("Message deleted: {0}", message.MessageId));
        }
コード例 #13
0
        public bool DeleteMessage(string receiptHandle)
        {
            DeleteMessageRequest  deleteMessageRequest  = new DeleteMessageRequest(this.queueUrl, receiptHandle);
            DeleteMessageResponse deleteMessageResponse = this.sqsClient.DeleteMessage(deleteMessageRequest);

            if (deleteMessageResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                return(true);
            }

            return(false);
        }
コード例 #14
0
ファイル: SQSSample.aspx.cs プロジェクト: sagibalaji/test
        protected void btnDeleteMessage_Click(object sender, EventArgs e)
        {
            string selectedQueue = this.QueuesList.SelectedItem.Value.ToString();

            DeleteMessageResponse objDeleteMessageResponse = new DeleteMessageResponse();

            objDeleteMessageResponse = objClient.DeleteMessage(new DeleteMessageRequest()
            {
                QueueUrl = selectedQueue, ReceiptHandle = Session["MessageReceiptHandle"].ToString()
            });
            Response.Write("<script>alert('Message Deleted Successfully!');</script>");

            txtReceivedMessage.Text = string.Empty;
        }
コード例 #15
0
        public async Task AcknowledgeAsync(string messageId)
        {
            string receiptHandle = _messageIdsToReceiptHandles[messageId];

            var deleteMessageRequest = new DeleteMessageRequest
            {
                QueueUrl      = _config.QueueUrl,
                ReceiptHandle = receiptHandle
            };

            DeleteMessageResponse deleteMessageResponse = await _amazonSQS.DeleteMessageAsync(deleteMessageRequest);

            deleteMessageResponse.ThrowIfUnsuccessful();
        }
コード例 #16
0
ファイル: Consumer.cs プロジェクト: itsdrew/SQSSample
        // Deletes a single message from queue.
        public static void DeleteMessageFromQueue(string receiptHandle)
        {
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest {
                QueueUrl      = Config.queueUrl,
                ReceiptHandle = receiptHandle
            };

            DeleteMessageResponse response = Client.DeleteMessage(deleteMessageRequest);

            if (!response.HttpStatusCode.Equals(HttpStatusCode.OK))
            {
                Console.WriteLine("Delete failed");
            }
        }
コード例 #17
0
        public async Task DeleteMessage(IAmazonSQS sqsClient, Message message, string queueUrl)
        {
            try
            {
                Console.WriteLine($"\nDeleting message {message.MessageId} from queue...");
                DeleteMessageResponse response = await sqsClient.DeleteMessageAsync(queueUrl, message.ReceiptHandle);

                Console.WriteLine($"Delete message request status code :  {response.HttpStatusCode}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Deleting SQS message failed: {e}");
                throw;
            }
        }
コード例 #18
0
        private static void ReceiveMessage(string queueUrl, AmazonSQSClient sqsClient)
        {
            ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();

            receiveMessageRequest.QueueUrl = queueUrl;

            var counter = 0;

            var lenght = NumbersOfMessagesInQueue(queueUrl, sqsClient);

            while (counter < lenght)
            {
                ReceiveMessageResponse receiveMessageResponse =
                    Task.Run(async() => await sqsClient.ReceiveMessageAsync(receiveMessageRequest)).Result;

                if (receiveMessageResponse.HttpStatusCode == HttpStatusCode.OK)
                {
                    Message message = receiveMessageResponse.Messages[0];

                    ReportFilters filter = JsonSerializer.Deserialize <ReportFilters>(message.Body);

                    Console.WriteLine("*********************************");
                    Console.WriteLine($"SQS Message Id: {message.MessageId}");
                    Console.WriteLine($"SQS Message Id: {message.ReceiptHandle}");
                    Console.WriteLine($"Message Id: {filter.Id}");
                    Console.WriteLine($"Message DataIni: {filter.DataIni}");
                    Console.WriteLine($"Message DateEnd: {filter.DataEnd}");
                    Console.WriteLine("*********************************");
                    Console.WriteLine($"Deleting Message...");

                    DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();
                    deleteMessageRequest.QueueUrl      = queueUrl;
                    deleteMessageRequest.ReceiptHandle = message.ReceiptHandle;
                    DeleteMessageResponse response =
                        Task.Run(async() => await sqsClient.DeleteMessageAsync(deleteMessageRequest)).Result;
                    if (response.HttpStatusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine($"Deleted Message...");
                    }
                    else
                    {
                        Console.WriteLine($"ERROR: {response.HttpStatusCode}");
                    }
                    Console.WriteLine();
                }
                counter++;
            }
        }
コード例 #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting..");


            string sQueue = "https://sqs.eu-west-1.amazonaws.com/{CODE}/{QUEUENAME}"; // Region / CODE and QueueName

            try
            {
                var config = new AmazonSQSConfig()
                {
                    ServiceURL = "https://sqs.eu-west-1.amazonaws.com/" // Region and URL
                };

                AmazonSQSClient _client = new AmazonSQSClient("ACCESSKEY", "ACCESSSECRET", config);

                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();

                receiveMessageRequest.QueueUrl = sQueue;

                ReceiveMessageResponse receiveMessageResponse = _client.ReceiveMessage(receiveMessageRequest);

                foreach (var oMessage in receiveMessageResponse.Messages)
                {
                    Console.WriteLine(oMessage.Body);



                    // Delete the message from the queue
                    DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest();

                    deleteMessageRequest.QueueUrl      = sQueue;
                    deleteMessageRequest.ReceiptHandle = oMessage.ReceiptHandle;

                    DeleteMessageResponse response = _client.DeleteMessage(deleteMessageRequest);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }



            Console.WriteLine("Complete");
            Console.WriteLine("Press any key to close");
            Console.ReadKey();
        }
コード例 #20
0
        public static void DeleteMessage(AmazonSQSClient _sqs,
                                         string _queueUrl,
                                         string _receiptHandle)
        {
            DeleteMessageRequest request = new DeleteMessageRequest
            {
                QueueUrl      = _queueUrl,
                ReceiptHandle = _receiptHandle
            };

            DeleteMessageResponse response = _sqs.DeleteMessage(request);

            if (response != null)
            {
            }
        }
コード例 #21
0
        public override T Unmarshall <T>(IResponseContext context)
        {
            try
            {
                var response = new DeleteMessageResponse();
                ResultUnmarshall(context, response);

                var xmlRootNode = GetXmlElement(context.ContentStream);
                response.ResponseMetadata.RequestId = xmlRootNode.SelectSingleNode("ResponseMetadata/RequestId")?.InnerText;

                return(response as T);
            }
            catch (Exception ex)
            {
                throw ErrorUnmarshall(ex.Message, ex, context.StatusCode);
            }
        }
コード例 #22
0
        public QueueGermPlasmEvent GetNext(ILambdaContext context)
        {
            Message message = null;

            try
            {
                context.Logger.LogLine($"trying to receive messages with timeout: {this.client.Config.Timeout}.");
                CancellationTokenSource       token = new CancellationTokenSource();
                Task <ReceiveMessageResponse> receivedMessageTask = client.ReceiveMessageAsync(this.request, token.Token);
                if (!receivedMessageTask.Wait(12000))
                {
                    context.Logger.LogLine($"message was not received");
                    try
                    {
                        token.Cancel();
                    }
                    catch (Exception)
                    {
                        context.Logger.LogLine($"receive message was cancelled.");
                        return(null);
                    }
                }
                ReceiveMessageResponse receivedMessage = receivedMessageTask.Result;
                context.Logger.LogLine($"{receivedMessage.Messages.Count} messages received");
                message = receivedMessage.Messages.FirstOrDefault();
                if (message == null)
                {
                    return(null);
                }
            }
            catch (Exception exc)
            {
                context.Logger.LogLine($"Exception: {exc}.");
                return(null);
            }
            deleteRequest.ReceiptHandle = message.ReceiptHandle;

            DeleteMessageResponse deleteResponse = client.DeleteMessageAsync(deleteRequest).Result;

            if (deleteResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception($"failed to delete message {message.MessageId} from queue: {request.QueueUrl}: received message: {deleteResponse.HttpStatusCode}");
            }
            return(JsonConvert.DeserializeObject <QueueGermPlasmEvent>(message.Body));
        }
コード例 #23
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteMessageResponse response = new DeleteMessageResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
コード例 #24
0
        public async Task <bool> DeleteMessageAsync()
        {
            DeleteMessageRequest request = new DeleteMessageRequest()
            {
                QueueUrl      = this.queueUrl,
                ReceiptHandle = "OK"
            };

            DeleteMessageResponse response = await this.clientSQS.DeleteMessageAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #25
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DeleteMessageResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

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

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                }
            }

            return;
        }
コード例 #26
0
        public async void DeleteMessageWithDegradation_Test()
        {
            var request = new DeleteMessageRequest();

            var message = new DeleteMessageResponse
            {
                HttpStatusCode = HttpStatusCode.OK
            };

            amazonSQSMock
            .Setup(e => e.DeleteMessageAsync(request, cancellationToken))
            .ReturnsAsync(message);

            var response = await target.DeleteMessageWithDegradation(request, cancellationToken);

            response.Should().NotBeNull();
            response.Should().Be(message);

            amazonSQSMock.VerifyAll();
        }
コード例 #27
0
        public async Task <DeleteMessageResponse> DeleteMessageWithDegradation(DeleteMessageRequest request, CancellationToken cancellationToken)
        {
            var                   failedAttemptCount = 0;
            Exception             lastException      = null;
            DeleteMessageResponse response           = null;

            while (failedAttemptCount < 10 && !cancellationToken.IsCancellationRequested)
            {
                var delayTime = SuspendTimeInMilliseconds(failedAttemptCount);

                if (delayTime > 0)
                {
                    await Task.Delay(delayTime, cancellationToken);
                }

                try
                {
                    response = await sqsClient.DeleteMessageAsync(request, cancellationToken);

                    if (response?.HttpStatusCode == HttpStatusCode.OK)
                    {
                        return(response);
                    }

                    lastException = new HttpRequestException($"Got HttpStatusCode {response?.HttpStatusCode} by request");
                    failedAttemptCount++;
                }
                catch (AmazonSQSException ex)
                {
                    lastException = ex;
                    failedAttemptCount++;
                }
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            throw new GetResponseFailedException(lastException);
        }
コード例 #28
0
        public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", true)
                                .Build();

            Console.Title = configuration["ApplicationName"];


            var profile = configuration["AWSProfile"];

            var credentials = new StoredProfileAWSCredentials(profile);
            var sqsClient   = new AmazonSQSClient(credentials, RegionEndpoint.EUWest1);

            // Create queue if not exist

            GetQueueUrlResponse queue = sqsClient.GetQueueUrlAsync("BFQueue").Result;

            var receiveMessageRequest = new ReceiveMessageRequest
            {
                QueueUrl          = queue.QueueUrl,
                WaitTimeSeconds   = 10,
                VisibilityTimeout = 10
            };

            while (true)
            {
                Console.WriteLine("Polling Queue");
                var messagesResponse = sqsClient.ReceiveMessageAsync(receiveMessageRequest).Result;
                foreach (var message in messagesResponse.Messages)
                {
                    Console.WriteLine($"Message: { message.Body }");

                    var deleteMessageRequest     = new DeleteMessageRequest(queue.QueueUrl, message.ReceiptHandle);
                    DeleteMessageResponse result = sqsClient.DeleteMessageAsync(deleteMessageRequest).Result;
                }
            }
        }
コード例 #29
0
 public DeleteMessageResponse DeleteMessage(string messagesIDs)
 {
     string[] messagesToDelete = messagesIDs.Split(',');
     DeleteMessageResponse response = new DeleteMessageResponse();
     try
     {
         Traveler traveler = _repository.FindBy<Traveler>(t => t.TravelerID == _currentTravelerId);
         IEnumerable<TravelerMessage> messages = traveler.Messages.Where(m => messagesToDelete.Contains(m.MessageID.ToString()));
         List<TravelerMessage> buffer = new List<TravelerMessage>();
         if (messages != null)
         {
             foreach (TravelerMessage message in messages)
             {
                 if (message.FolderID != (int)FolderType.Trash)
                 {
                     message.FolderID = (int)FolderType.Trash;
                     _repository.Save<TravelerMessage>(message);
                 }
                 else
                 {
                     buffer.Add(message);
                 }
             }
             foreach (TravelerMessage messageToDelete in buffer)
             {
                 _repository.Remove<TravelerMessage>(messageToDelete);
             }
             buffer.Clear();
             _repository.Commit();
             response.MarkSuccess();
         }
     }
     catch (Exception ex)
     {
         ReportError(ex, response);
     }
     return response;
 }
コード例 #30
0
ファイル: MessagePumpService.cs プロジェクト: ggkilmon/AwsFun
        public void ConsumeMessage()
        {
            try
            {
                logger.Debug("Receiving message(s)");
                ReceiveMessageRequest  request  = new ReceiveMessageRequest(QUEUE_URL);
                ReceiveMessageResponse response = _client.ReceiveMessage(request);
                logger.Debug("Message(s) received with status code: {0}", response.HttpStatusCode);
                if (response.Messages.Count > 0)
                {
                    foreach (var m in response.Messages)
                    {
                        var model = JsonConvert.DeserializeObject <MessagePumpModel>(m.Body);
                        logger.Debug("Message {0}; Guid {2}; {1}", m.MessageId, model.Message, model.Id);

                        try
                        {
                            logger.Debug("Deleting message {0}", m.MessageId);
                            DeleteMessageRequest  deleteRequest  = new DeleteMessageRequest(QUEUE_URL, m.ReceiptHandle);
                            DeleteMessageResponse deleteResponse = _client.DeleteMessage(deleteRequest);
                            logger.Debug("Message {0} deleted with status code: {1}", m.MessageId, deleteResponse.HttpStatusCode);
                        }
                        catch (Exception ex)
                        {
                            logger.Debug("Delete message failed; left on queue for consumption again; {0}", ex.ToString());
                        }
                    }
                }
                else
                {
                    logger.Debug("Retrieved 0 messages");
                }
            }
            catch (Exception ex)
            {
                logger.Error("Retrieve message failed; {0}", ex.ToString());
            }
        }
コード例 #31
0
        static void Main(string[] args)
        {
            var appSettings = ConfigurationManager.AppSettings;

            string sqsQueueName   = appSettings["AWSQueue" + args[0].ToString().ToUpper().Trim()].ToString();
            string sqsDLQueueName = appSettings["AWSDeadLetterQueue" + args[0].ToString().ToUpper().Trim()].ToString();
            int    maxSQSRetries  = Convert.ToInt32(appSettings["MaxSQSRetries"].ToString());
            string urlWMIService  = appSettings["WMIServiceURL" + args[0].ToString().ToUpper().Trim()].ToString();
            int    batchSize      = Convert.ToInt32(appSettings["BatchSize"].ToString());

            IAmazonSQS     sqsClient     = new AmazonSQSClient();
            IAWSSQSWrapper awsSQSWrapper = new AWSSQSWrapper(sqsClient);

            //Display our current list of Amazon SQS queues
            Console.WriteLine("Checking to see if AWS environment is available...\n");
            ListQueuesResponse lqr = awsSQSWrapper.LisQueues();

            bool queueExists   = false;
            bool dlqueueExists = false;

            if (lqr.QueueUrls != null)
            {
                foreach (String queueUrl in lqr.QueueUrls)
                {
                    if (queueUrl.ToUpper().Trim().EndsWith(sqsQueueName.ToUpper().Trim()))
                    {
                        queueExists = true;
                        Console.WriteLine("Queue Exists: {0}", queueUrl);

                        GetQueueAttributesResponse gQAR = awsSQSWrapper.GetQueueAttributes(queueUrl);
                        if (gQAR.Attributes != null)
                        {
                            foreach (KeyValuePair <string, string> tmp in gQAR.Attributes)
                            {
                                Console.WriteLine("     Attribute: {0}  Value:{1}", tmp.Key.ToString(), tmp.Value.ToString());
                            }
                        }
                    }

                    if (queueUrl.ToUpper().Trim().EndsWith(sqsDLQueueName.ToUpper().Trim()))
                    {
                        dlqueueExists = true;
                        Console.WriteLine("Queue Exists: {0}", queueUrl);

                        GetQueueAttributesResponse gQAR = awsSQSWrapper.GetQueueAttributes(queueUrl);
                        if (gQAR.Attributes != null)
                        {
                            foreach (KeyValuePair <string, string> tmp in gQAR.Attributes)
                            {
                                Console.WriteLine("     Attribute: {0}  Value:{1}", tmp.Key.ToString(), tmp.Value.ToString());
                            }
                        }
                    }
                }
            }

            if (!dlqueueExists)
            {
                Console.WriteLine("The dead letter queue was missing, let's build it...\n");
                awsSQSWrapper.CreateQueue(sqsDLQueueName, false);
                Console.WriteLine("Dead Letter Queue built successfuly.\n");
                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }

            if (!queueExists)
            {
                Console.WriteLine("Message queue was missing, let's build it...\n");
                awsSQSWrapper.CreateQueue(sqsQueueName, false);
                awsSQSWrapper.AttachDeadLetterQueue(sqsQueueName, sqsDLQueueName, maxSQSRetries);
                Console.WriteLine("Message queue built successfuly.\n");
                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }

            Console.WriteLine("AWS environment ready.\n");
            Console.WriteLine("Press any key...");
            Console.ReadKey();

            GetQueueUrlResponse awsGQUR = sqsClient.GetQueueUrl(sqsQueueName);

            Console.WriteLine("Creating test messages...");
            CreateMessages(awsSQSWrapper, awsGQUR.QueueUrl.ToString(), 10);
            Console.WriteLine("Creating test messages complete.");
            Console.WriteLine("Press any key...");
            Console.ReadKey();

            string response = GetREST();

            Console.WriteLine("GET Received: {0}", response);
            Console.WriteLine("Press any key...");
            Console.ReadKey();

            //string awsMessage = GetMessage(awsSQSWrapper, awsGQUR.QueueUrl);

            bool continueReceiving = true;

            while (continueReceiving)
            {
                ReceiveMessageResponse awsRMR = awsSQSWrapper.ReceiveMessage(awsGQUR.QueueUrl);

                if (awsRMR.Messages.Count > 0)
                {
                    response = PostREST(awsRMR.Messages[0].Body.ToString());
                    Console.WriteLine("POST Returned: {0}", response);
                    DeleteMessageResponse awsDMR = awsSQSWrapper.DeleteMessage(awsGQUR.QueueUrl, awsRMR.Messages[0].ReceiptHandle.ToString());
                    Console.WriteLine("Message Deleted: {0}", awsRMR.Messages[0].ReceiptHandle.ToString());
                }
                else
                {
                    continueReceiving = false;
                }
            }

            Console.WriteLine("\n\nAll messages sent.");
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
コード例 #32
0
 public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
 {
     var response = new DeleteMessageResponse();
     // Nothing need to do with this response here
     return response;
 }