CreateQueue() public method

Creates a new standard or FIFO queue or returns the URL of an existing queue. You can pass one or more attributes in the request. Keep the following caveats in mind:
  • If you don't specify the FifoQueue attribute, Amazon SQS creates a standard queue.

    You can't change the queue type after you create it and you can't convert an existing standard queue into a FIFO queue. You must either create a new FIFO queue for your application or delete your existing standard queue and recreate it as a FIFO queue. For more information, see Moving From a Standard Queue to a FIFO Queue in the Amazon SQS Developer Guide.

  • If you don't provide a value for an attribute, the queue is created with the default value for the attribute.

  • If you delete a queue, you must wait at least 60 seconds before creating a queue with the same name.

To successfully create a new queue, you must provide a queue name that adheres to the limits related to queues and is unique within the scope of your queues.

To get the queue URL, use the GetQueueUrl action. GetQueueUrl requires only the QueueName parameter. be aware of existing queue names:

  • If you provide the name of an existing queue along with the exact names and values of all the queue's attributes, CreateQueue returns the queue URL for the existing queue.

  • If the queue name, attribute names, or attribute values don't match an existing queue, CreateQueue returns an error.

Some actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers starting from 1. For example, a parameter list with two elements looks like this:

&Attribute.1=this

&Attribute.2=that

/// You must wait 60 seconds after deleting a queue before you can create another one /// with the same name. /// /// A queue already exists with this name. Amazon SQS returns this error only if the request /// includes attributes whose values differ from those of the existing queue. ///
public CreateQueue ( CreateQueueRequest request ) : CreateQueueResponse
request Amazon.SQS.Model.CreateQueueRequest Container for the necessary parameters to execute the CreateQueue service method.
return Amazon.SQS.Model.CreateQueueResponse
Ejemplo n.º 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;
        }
Ejemplo n.º 2
1
        public AmazonConnection(TypeOfMsg requestMsgType)
        {
            pollingMsg = requestMsgType;

            objClient = new AmazonSQSClient(AccessKeyId, SecretAccessKey);

            CreateQueueResponse queueResponse = new CreateQueueResponse();

            //Request existing queues
            ListQueuesResult allQueues = requestListOfQueuesInSQS();

            bool eventSparkzQueueListExists = false;

            foreach (string queueURL in allQueues.QueueUrl)
            {
                if (queueURL.Equals(QueueURLString))
                {
                    eventSparkzQueueListExists = true;
                }
            }

            if (!eventSparkzQueueListExists)
            {
                queueResponse = objClient.CreateQueue(new CreateQueueRequest()
                {
                    QueueName
                        = EventSparkzQueueName
                });
            }
        }
Ejemplo n.º 3
1
    public static void SQSCreateQueue()
    {
      #region SQSCreateQueue
      var client = new AmazonSQSClient();

      var attrs = new Dictionary<string, string>();

      // Maximum message size of 256 KiB (1,024 bytes * 256 KiB = 262,144 bytes).
      int maxMessage = 256 * 1024;

      attrs.Add(QueueAttributeName.DelaySeconds,
        TimeSpan.FromSeconds(5).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.MaximumMessageSize, maxMessage.ToString());
      attrs.Add(QueueAttributeName.MessageRetentionPeriod,
        TimeSpan.FromDays(4).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.ReceiveMessageWaitTimeSeconds,
        TimeSpan.FromSeconds(5).TotalSeconds.ToString());
      attrs.Add(QueueAttributeName.VisibilityTimeout,
        TimeSpan.FromHours(12).TotalSeconds.ToString());

      var request = new CreateQueueRequest
      {
        Attributes = attrs,
        QueueName = "MyTestQueue"
      };

      var response = client.CreateQueue(request);

      Console.WriteLine("Queue URL: " + response.QueueUrl);
      #endregion

      Console.ReadLine();
    }
        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 override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			CreateQueue.TouchUpInside += delegate(object sender, EventArgs e) {			
				var sqsClient = new Amazon.SQS.AmazonSQSClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.EUWest1);
				var request = new Amazon.SQS.Model.CreateQueueRequest ();
				request.QueueName = "newQueue";
				var response = sqsClient.CreateQueue (request);
				CreateQueueResults.Text = String.Format("Queue created at {0}.", response.QueueUrl);
			};
		}
Ejemplo n.º 6
0
        public virtual string CreateQueue(AmazonSQSClient sqsClient, string queueName)
        {
            string queueUrl;

            // Create the request
            var createQueueRequest = new CreateQueueRequest {QueueName = queueName};

            // Submit the request
            CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(createQueueRequest);

            // Return the URL for the newly created queue
            queueUrl = createQueueResponse.QueueUrl;
            return queueUrl;
        }
Ejemplo n.º 7
0
        public static string CreateQueue(string name)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new CreateQueueRequest
                {
                    QueueName = name
                };

                var response = client.CreateQueue(request);

                return response.QueueUrl;
            }
        }
Ejemplo n.º 8
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.createQueue);
			EditText createQueueResult = FindViewById<EditText> (Resource.Id.createQueueResult);

			button.Click += delegate {
				var sqsClient = new Amazon.SQS.AmazonSQSClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.EUWest1);
				var request = new Amazon.SQS.Model.CreateQueueRequest ();
				request.QueueName = "newQueue";
				var response = sqsClient.CreateQueue (request);
				createQueueResult.Text = String.Format("Queue created at {0}.", response.QueueUrl);
			};
		}
Ejemplo n.º 9
0
        public void CreateQueue(string address)
        {
            if (_inputQueueAddress == null) return;

            _log.Info("Creating a new sqs queue:  with name: {0} on region: {1}", address, _regionEndpoint);

            using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, _regionEndpoint))
            {
                var queueName = GetQueueNameFromAddress(address);
                var response = client.CreateQueue(new CreateQueueRequest(queueName));

                if (response.HttpStatusCode != HttpStatusCode.OK)
                {

                    _log.Error("Did not create queue with address: {0} - there was an error: ErrorCode: {1}", address, response.HttpStatusCode);
                    //Not really sure when status code != ok - because sqlclient always throwsexceptions...
                }
                _queueUrl = response.QueueUrl;
            }
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        public void CreateQueue(string address)
        {
            if (Address == null) return;

            _log.Info("Creating a new sqs queue:  with name: {0} on region: {1}", address, _amazonSqsConfig.RegionEndpoint);

            using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, _amazonSqsConfig))
            {
                var queueName = GetQueueNameFromAddress(address);
                var response = client.CreateQueue(new CreateQueueRequest(queueName));

                if (response.HttpStatusCode != HttpStatusCode.OK)
                {
                    throw new Exception($"Could not create queue '{queueName}' - got HTTP {response.HttpStatusCode}");
                }

                _queueUrl = response.QueueUrl;
            }
        }
Ejemplo n.º 12
0
        public void SetQueueConfigurationTests()
        {
            var filterRule = new FilterRule("Prefix", "test/");
            var s3Config = new AmazonS3Config();
            using (var s3Client = new AmazonS3Client(s3Config))
            using (var sqsClient = new AmazonSQSClient())
            {
                var createResponse = sqsClient.CreateQueue("events-test-" + DateTime.Now.Ticks);
                var bucketName = S3TestUtils.CreateBucket(s3Client);
                try
                {
                    var queueArn = sqsClient.AuthorizeS3ToSendMessage(createResponse.QueueUrl, bucketName);

                    PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest
                    {
                        BucketName = bucketName,
                        QueueConfigurations = new List<QueueConfiguration>
                        {
                            new QueueConfiguration
                            {
                                Id = "the-queue-test",
                                Queue = queueArn,
                                Events = {EventType.ObjectCreatedPut},
                                Filter = new Filter
                                {
                                    S3KeyFilter = new S3KeyFilter
                                    {
                                        FilterRules = new List<FilterRule> 
                                        {
                                            filterRule
                                        }
                                    }
                                }
                            }
                        }
                    };

                    s3Client.PutBucketNotification(putRequest);

                    var getResponse = s3Client.GetBucketNotification(bucketName);

                    Assert.AreEqual(1, getResponse.QueueConfigurations.Count);
                    Assert.AreEqual(1, getResponse.QueueConfigurations[0].Events.Count);
                    Assert.AreEqual(EventType.ObjectCreatedPut, getResponse.QueueConfigurations[0].Events[0]);

                    Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter);
                    Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter);
                    Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules);
                    Assert.AreEqual(1, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules.Count);
                    Assert.AreEqual(filterRule.Name, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Name);
                    Assert.AreEqual(filterRule.Value, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Value);

                    Assert.AreEqual("the-queue-test", getResponse.QueueConfigurations[0].Id);
                    Assert.AreEqual(queueArn, getResponse.QueueConfigurations[0].Queue);

                    // Purge queue to remove test message sent configuration was setup.
                    sqsClient.PurgeQueue(createResponse.QueueUrl);
                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    var putObjectRequest = new PutObjectRequest
                    {
                        BucketName = bucketName,
                        Key = "test/data.txt",
                        ContentBody = "Important Data"
                    };

                    s3Client.PutObject(putObjectRequest);

                    string messageBody = null;
                    for (int i = 0; i < 5 && messageBody == null; i++)
                    {
                        var receiveResponse = sqsClient.ReceiveMessage(new ReceiveMessageRequest { QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20 });
                        if (receiveResponse.Messages.Count != 0)
                        {
                            messageBody = receiveResponse.Messages[0].Body;
                        }
                    }


                    var evnt = S3EventNotification.ParseJson(messageBody);

                    Assert.AreEqual(1, evnt.Records.Count);
                    Assert.AreEqual(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name);
                    Assert.AreEqual(putObjectRequest.Key, evnt.Records[0].S3.Object.Key);
                    Assert.AreEqual(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size);
                }
                finally
                {
                    sqsClient.DeleteQueue(createResponse.QueueUrl);
                    AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                }
            }
        }
Ejemplo n.º 13
0
        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();
        }