private void SendMessage(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         MessageId = helper.SendMessage(MessageBody, QueueUrl);
         Log.LogMessage(MessageImportance.Normal, "Sent message to Queue {0}", QueueUrl);
     }
 }
 private void GrantRights(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         helper.GrantSendMessageRights(QueueUrl, SourceArn);
         Log.LogMessage(MessageImportance.Normal, "Granted rights for source {0} to SendMessage to SQS at {1}", SourceArn, QueueUrl);
     }
 }
 private void DeleteQueue(AwsClientDetails clientDetails)
 {
     using (var helper = new SQSHelper(clientDetails))
     {
         helper.DeleteQueue(QueueUrl);
         Log.LogMessage(MessageImportance.Normal, "Deleted SQS Queue at {0}", QueueUrl);
     }
 }
        private void DeleteMessage(AwsClientDetails clientDetails)
        {
            using (var helper = new SQSHelper(clientDetails))
            {
                helper.DeleteMessage(QueueUrl, ReceiptHandle);

                Log.LogMessage(MessageImportance.Normal, "Deleted message {0} from queue {1}", ReceiptHandle, QueueUrl);
            }
        }
        public void DeleteQueue_Should_DeleteQueue()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            // Qreate a queue to delete.
            string queueUrl = helper.CreateQueue("TestQ");

            helper.DeleteQueue(queueUrl);
        }
        public void CreateQueueTwice_Should_Succeed()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string url1 = helper.CreateQueue("TestQ2");
            string url2 = helper.CreateQueue("TestQ2");

            Assert.AreEqual(url1, url2, "Url's should match");
        }
        public void CreateQueue_Should_CreateQueue()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            System.Diagnostics.Debug.WriteLine(queueUrl, "queueUrl:");

            Assert.IsNotEmpty(queueUrl);
        }
        public void ReceiveMessage_Should_ReceiveMessageAndNotRemoveIt()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            // Add a message to the queue to ensure that their is one and wait for 2 seconds to allow
            // the message to propogate.
            // Add the time on to ensure the correct message is received.
            string expectedMessage = "Sample test message " + DateTime.Now.ToLongTimeString();
            helper.SendMessage(expectedMessage, queueUrl);

            // Messages can be very slow to appear on the queue.
            Thread.Sleep(60000);

            // Get the sent message.
            Amazon.SQS.Model.Message message = helper.ReceiveMessage(queueUrl);
            Assert.IsNotNull(message, "No messages");

            try
            {
                Assert.AreEqual(expectedMessage, message.Body, "Expected message body first time");

                // Ensure that we can get the message a second time.
                Amazon.SQS.Model.Message message2 = helper.ReceiveMessage(queueUrl);
                Assert.IsNotNull(message2, "Message should not have been removed.");
                Assert.AreEqual(expectedMessage, message2.Body, "Expected message body second time");
            }
            finally
            {
                // Delete the message.
                helper.DeleteMessage(queueUrl, message.ReceiptHandle);
            }
        }
        private void ReceiveMessage(AwsClientDetails clientDetails)
        {
            using (var helper = new SQSHelper(clientDetails))
            {
                Amazon.SQS.Model.Message message = helper.ReceiveMessage(QueueUrl);

                if (message != null)
                {
                    MessageId = message.MessageId;
                    MessageBody = message.Body;
                    ReceiptHandle = message.ReceiptHandle;
                    HasMessage = true;
                    Log.LogMessage(MessageImportance.Normal, "Recieved message {0} from queue {1}", MessageId, QueueUrl);
                }
                else
                {
                    MessageId = string.Empty;
                    MessageBody = string.Empty;
                    ReceiptHandle = string.Empty;
                    HasMessage = false;
                    Log.LogMessage(MessageImportance.Normal, "No message received from queue {0}", QueueUrl);
                }
            }
        }
Esempio n. 10
0
        public void WaitForMessage_Should_ThrowTimeoutException()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            string queueUrl = helper.CreateQueue("TestQ");

            // Get the sent message.
            helper.WaitForMessage(queueUrl, 10, 5);
        }
Esempio n. 11
0
        public void SendMessage_Should_ReturnMessageId()
        {
            var store = new ClientDetailsStore();
            AwsClientDetails clientDetails = store.Load(Container);

            SQSHelper helper = new SQSHelper(clientDetails);

            const string messageBody = "TestMessageBody";
            string queueUrl = helper.CreateQueue("TestQ");

            string messageId = helper.SendMessage(messageBody, queueUrl);

            Assert.IsNotEmpty(messageId);
        }
        private void ReceiveMessage(AwsClientDetails clientDetails)
        {
            using (var helper = new SQSHelper(clientDetails))
            {
                Amazon.SQS.Model.Message message = helper.WaitForMessage(QueueUrl, TimeOutSeconds, PollIntervalSeconds);

                MessageId = message.MessageId;
                MessageBody = message.Body;
                ReceiptHandle = message.ReceiptHandle;
                Log.LogMessage(MessageImportance.Normal, "Recieved message {0} from queue {1}", MessageId, QueueUrl);
            }
        }
        private void GetQueueAttributes(AwsClientDetails clientDetails)
        {
            using (var helper = new SQSHelper(clientDetails))
            {
                GetQueueAttributesResult attributes = helper.GetQueueAttributes(QueueUrl);
                Log.LogMessage(MessageImportance.Normal, "Got SQS attributes for Queue {0}", QueueUrl);

                ApproximateNumberOfMessages = GetAttributeValue(attributes, "ApproximateNumberOfMessages");
                ApproximateNumberOfMessagesNotVisible = GetAttributeValue(attributes, "ApproximateNumberOfMessagesNotVisible");
                VisibilityTimeout = GetAttributeValue(attributes, "VisibilityTimeout");
                CreatedTimestamp = GetAttributeValue(attributes, "CreatedTimestamp");
                LastModifiedTimestamp = GetAttributeValue(attributes, "LastModifiedTimestamp");
                //Policy is not a string.
                //Policy = GetAttributeValue(attributes, "Policy");
                MaximumMessageSize = GetAttributeValue(attributes, "MaximumMessageSize");
                MessageRetentionPeriod = GetAttributeValue(attributes, "MessageRetentionPeriod");
                QueueArn = GetAttributeValue(attributes, "QueueArn");
            }
        }