ListQueues() public method

Returns a list of your queues. The maximum number of queues that can be returned is 1,000. If you specify a value for the optional QueueNamePrefix parameter, only queues with a name that begins with the specified value are returned.
public ListQueues ( ListQueuesRequest request ) : ListQueuesResponse
request Amazon.SQS.Model.ListQueuesRequest Container for the necessary parameters to execute the ListQueues service method.
return Amazon.SQS.Model.ListQueuesResponse
Beispiel #1
2
        private AmazonSQSClient InitializeQueue()
        {
            var client = new AmazonSQSClient(Utility.GetRegionEndpoint());
            
            ListQueuesRequest listQueuesRequest = new ListQueuesRequest
                                                      {
                                                          QueueNamePrefix = QueueName
                                                      };
            var listQueuesResponse = client.ListQueues(listQueuesRequest);
            bool found = listQueuesResponse.ListQueuesResult.QueueUrls.Any(s => s == QueueName);

            if (found == false)
            {
                var createQueueResponse = client.CreateQueue(new CreateQueueRequest
                                                                 {
                                                                     QueueName = QueueName
                                                                 });
                QueueUrl = createQueueResponse.CreateQueueResult.QueueUrl;
            }
            else
            {
                QueueUrl = client.GetQueueUrl(
                    new GetQueueUrlRequest
                        {
                            QueueName = _queueName
                        }
                    ).GetQueueUrlResult.QueueUrl;
            }
            return client;
        }
        public void When_obtaining_details_on_a_message_queue(string queueName, bool exists)
        {
            // Arrange
            var client = new AmazonSQSClient("access key", "secret key");

            if (exists)
            {
                client.CreateQueue(new CreateQueueRequest().WithQueueName(queueName));
            }
            else
            {
                var response = client.ListQueues(new ListQueuesRequest().WithQueueNamePrefix(queueName));
                if (response.ListQueuesResult.QueueUrl.Any())
                {
                    client.DeleteQueue(new DeleteQueueRequest().WithQueueUrl(response.ListQueuesResult.QueueUrl.First()));
                }
            }

            Thread.Sleep(2000); // Give the queues some time to spin up
          
            var factory = new AmazonSqsMessageQueueDetailFactory(client);


            // Act
            var result = factory.Build<TestMessage>(queueName);

            // Assert
            Assert.That(result.Uri, Is.StringContaining(queueName));
            Assert.That(result.Exists, Is.EqualTo(exists));
        }  
        public static void DeleteAllQueues()
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var response = client.ListQueues(new ListQueuesRequest());

                foreach (var queueUrl in response.QueueUrls)
                {
                    PurgeQueueByQueueUrl(queueUrl);

                    client.DeleteQueue(queueUrl);
                }
            }
        }
        public static void Main(string[] args)
        {
            IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USWest2);

            try
            {
                Console.WriteLine("===========================================");
                Console.WriteLine("Getting Started with Amazon SQS");
                Console.WriteLine("===========================================\n");                
                
                //Creating a queue
                Console.WriteLine("Create a queue called MyQueue.\n");
                CreateQueueRequest sqsRequest = new CreateQueueRequest();
                sqsRequest.QueueName = "MyQueue";
                CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
                String myQueueUrl;
                myQueueUrl = createQueueResponse.QueueUrl;

                //Confirming the queue exists
                ListQueuesRequest listQueuesRequest = new ListQueuesRequest();
                ListQueuesResponse listQueuesResponse = sqs.ListQueues(listQueuesRequest);

                Console.WriteLine("Printing list of Amazon SQS queues.\n");
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    Console.WriteLine("  QueueUrl: {0}", queueUrl);
                }
                Console.WriteLine();

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                SendMessageRequest sendMessageRequest = new SendMessageRequest();
                sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation
                sendMessageRequest.MessageBody = "This is my message text.";
                sqs.SendMessage(sendMessageRequest);
                
                //Receiving a message
                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.QueueUrl = myQueueUrl;
                ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);

                Console.WriteLine("Printing received message.\n");
                foreach (Message message in receiveMessageResponse.Messages)
                {
                    Console.WriteLine("  Message");
                    Console.WriteLine("    MessageId: {0}", message.MessageId);
                    Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                    Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                    Console.WriteLine("    Body: {0}", message.Body);

                    foreach (KeyValuePair<string, string> entry in message.Attributes)
                    {
                        Console.WriteLine("  Attribute");
                        Console.WriteLine("    Name: {0}", entry.Key);
                        Console.WriteLine("    Value: {0}", entry.Value);
                    }
                }
                String messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;

                //Deleting a message
                Console.WriteLine("Deleting the message.\n");
                DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
                deleteRequest.QueueUrl = myQueueUrl;
                deleteRequest.ReceiptHandle = messageRecieptHandle;
                sqs.DeleteMessage(deleteRequest);

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
 public virtual bool AppMode_TestSqsAccess(RegionEndpoint regionEndpoint, SessionAWSCredentials credentials)
 {
     try
     {
         var sqsClient = new AmazonSQSClient(credentials, regionEndpoint);
         sqsClient.ListQueues(new ListQueuesRequest());
         return true;
     }
     catch
     {
         return false;
     }
 }
        public static void Main(string[] args)
        {
            var sqs = new AmazonSQSClient();

            try
            {
                Console.WriteLine("===========================================");
                Console.WriteLine("Getting Started with Amazon SQS");
                Console.WriteLine("===========================================\n");

                //Confirming the queue exists
                var listQueuesRequest = new ListQueuesRequest();
                var listQueuesResponse = sqs.ListQueues(listQueuesRequest);
                string myQueueUrl = string.Empty;

                Console.WriteLine("Printing list of Amazon SQS queues.\n");
                bool queueExists = false;
                if (listQueuesResponse.QueueUrls != null)
                {
                    foreach (String queueUrl in listQueuesResponse.QueueUrls)
                    {
                        Console.WriteLine("  QueueUrl: {0}", queueUrl);
                        if (queueUrl.EndsWith("MyQueue"))
                        {
                            queueExists = true;
                            myQueueUrl = queueUrl;
                            break;
                        }
                    }
                }
                Console.WriteLine();

                if (!queueExists)
                {
                    //Creating a queue
                    Console.WriteLine("Create a queue called MyQueue.\n");
                    var sqsRequest = new CreateQueueRequest { QueueName = "MyQueue" };
                    var createQueueResponse = sqs.CreateQueue(sqsRequest);
                    myQueueUrl = createQueueResponse.QueueUrl;
                }

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                var sendMessageRequest = new SendMessageRequest
                    {
                        QueueUrl = myQueueUrl, //URL from initial queue creation
                        MessageBody = string.Format("ATL MEETUP - This is my message text from server - {0}",System.Environment.MachineName)
                    };
                sqs.SendMessage(sendMessageRequest);

                ////Receiving a message
                //var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = myQueueUrl };
                //var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
                //if (receiveMessageResponse.Messages != null)
                //{
                //    Console.WriteLine("Printing received message.\n");
                //    foreach (var message in receiveMessageResponse.Messages)
                //    {
                //        Console.WriteLine("  Message");
                //        if (!string.IsNullOrEmpty(message.MessageId))
                //        {
                //            Console.WriteLine("    MessageId: {0}", message.MessageId);
                //        }
                //        if (!string.IsNullOrEmpty(message.ReceiptHandle))
                //        {
                //            Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                //        }
                //        if (!string.IsNullOrEmpty(message.MD5OfBody))
                //        {
                //            Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                //        }
                //        if (!string.IsNullOrEmpty(message.Body))
                //        {
                //            Console.WriteLine("    Body: {0}", message.Body);
                //        }

                //        foreach (string attributeKey in message.Attributes.Keys)
                //        {
                //            Console.WriteLine("  Attribute");
                //            Console.WriteLine("    Name: {0}", attributeKey);
                //            var value = message.Attributes[attributeKey];
                //            Console.WriteLine("    Value: {0}", string.IsNullOrEmpty(value) ? "(no value)" : value);
                //        }
                //    }

                //    var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;

                //    //Deleting a message
                //    Console.WriteLine("Deleting the message.\n");
                //    var deleteRequest = new DeleteMessageRequest { QueueUrl = myQueueUrl, ReceiptHandle = messageRecieptHandle };
                //    sqs.DeleteMessage(deleteRequest);
                //}

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
        public DataTable GetSQSQ(string aprofile, string Region2Scan)
        {
            DataTable ToReturn = new DataTable();

            string accountid = GetAccountID(aprofile);

            RegionEndpoint Endpoint2scan = RegionEndpoint.USEast1;
            //Convert the Region2Scan to an AWS Endpoint.
            foreach (var aregion in RegionEndpoint.EnumerableAllRegions)
            {
                if (aregion.DisplayName.Equals(Region2Scan))
                {
                    Endpoint2scan = aregion;
                    continue;
                }
            }
            Amazon.Runtime.AWSCredentials credential;

            try
            {
                credential = new Amazon.Runtime.StoredProfileAWSCredentials(aprofile);
                var sqsq = new Amazon.SQS.AmazonSQSClient(credential, Endpoint2scan);
                var daqs = sqsq.ListQueues("").QueueUrls;

            }
            catch
            {

            }




            return ToReturn;

        }
Beispiel #8
0
    public static void SQSListQueues()
    {
      #region SQSListQueues
      var client = new AmazonSQSClient();

      // List all queues that start with "My".
      var request = new ListQueuesRequest
      {
        QueueNamePrefix = "My"
      };

      var response = client.ListQueues(request);

      if (response.QueueUrls.Count > 0)
      {
        Console.WriteLine("Queue URLs:");

        foreach (var url in response.QueueUrls)
        {
          Console.WriteLine("  " + url);
        }
      }
      else
      {
        Console.WriteLine("No matching queues.");
      }
      #endregion

      Console.ReadLine();
    }
        public static IEnumerable<string> FindQueueUrls()
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var response = client.ListQueues(new ListQueuesRequest());

                foreach (var queueUrl in response.QueueUrls)
                {
                    yield return queueUrl;
                }
            }
        }
        public static string FindQueueUrlByQueueName(string name)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                ListQueuesResponse response = client.ListQueues(new ListQueuesRequest(name));

                foreach (string queueUrl in response.QueueUrls)
                {
                    return queueUrl;
                }
            }

            return null;
        }