Exemple #1
0
        public static bool CreateSQSQueue(string queueName)
        {
            try
            {
                if (sqsClient == null)
                {
                    InitializeSQSClient();
                }

                CreateQueueRequest createQueueRequest =
                    new CreateQueueRequest();

                createQueueRequest.QueueName = queueName;

                CreateQueueResponse createQueueResponse =
                    sqsClient.CreateQueue(createQueueRequest);

                if (createQueueResponse.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(true);
                }
            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine(ex);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(false);
        }
Exemple #2
0
        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();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                sqsClient = new AmazonSQSClient("AKIAQKS6V3RVOBQR3XJC", "/rqjkje3pZ5vyXNfyuZXxNQyFlkYO8ywQamljYCX");

                if (!checkQueueExist())
                {
                    Dictionary <String, String> attributes = new Dictionary <string, string>();
                    attributes.Add("FifoQueue", "true");
                    attributes.Add("ContentBasedDeduplication", "true");
                    sqsRequest = new CreateQueueRequest()
                    {
                        QueueName  = queue,
                        Attributes = attributes
                    };
                    var result = sqsClient.CreateQueue(sqsRequest);
                    url = result.QueueUrl;
                }
                else
                {
                    url = url + queue;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
        public void When_sending_a_message_it_can_be_received()
        {
            // Arrange
            var message = new TestMessage {
                Identifier = Guid.NewGuid().ToString(), Description = "something", SentAt = DateTime.Now
            };

            var receivedMessages = new List <TestMessage>();

            var client   = new AmazonSQSClient("access key", "secret key");
            var response = client.CreateQueue(new CreateQueueRequest().WithQueueName("testQueue"));
            var uri      = response.CreateQueueResult.QueueUrl;

            var receiver = new AmazonSqsMessageSubscriber <TestMessage>(client, uri, new JsonMessageFormatter());

            receiver.Subscribe(s =>
            {
                receivedMessages.Add(s.Message);
                s.Accept();
            });

            var sender = new AmazonSqsMessenger(client, uri, new JsonMessageFormatter());

            // Act
            sender.Send(message);

            Thread.Sleep(5000);

            // Assert
            Assert.That(receivedMessages, Is.Not.Empty);
        }
        public void create_queue()
        {
            var request  = new CreateQueueRequest().WithQueueName("Test_for_blog");
            var response = _client.CreateQueue(request);

            Console.WriteLine(response.CreateQueueResult.QueueUrl);
        }
Exemple #6
0
        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));
        }
        private static void CreateSqsQueue(AmazonSQSClient sqsClient)
        {
            var createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = SingleQueue;
            var attrs = new Dictionary <string, string>();

            attrs.Add(QueueAttributeName.VisibilityTimeout, "0");
            createQueueRequest.Attributes = attrs;
            var response1 = sqsClient.CreateQueue(createQueueRequest);

            Console.WriteLine($"CreateQueue(CreateQueueRequest) HTTP status code: {response1.HttpStatusCode}");

            var response2 = sqsClient.CreateQueue(BatchedQueue);

            Console.WriteLine($"CreateQueue(string) HTTP status code: {response2.HttpStatusCode}");
        }
Exemple #9
0
            void SetupTopicAndQueue()
            {
                long ticks = DateTime.Now.Ticks;

                // Setup SNS topic.
                snsClient = new AmazonSimpleNotificationServiceClient(
                    settings.AWSAccessKeyID,
                    settings.AWSSecretAccessKey,
                    RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

                sqsClient = new AmazonSQSClient(
                    settings.AWSAccessKeyID,
                    settings.AWSSecretAccessKey,
                    RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName));

                topicArn = snsClient.CreateTopic(new CreateTopicRequest {
                    Name = "GlacierDownload-" + ticks
                }).TopicArn;
                Debug.WriteLine($"topicArn: {topicArn}");

                var createQueueRequest = new CreateQueueRequest {
                    QueueName = "GlacierDownload-" + ticks
                };
                var createQueueResponse = sqsClient.CreateQueue(createQueueRequest);

                this.queueUrl = createQueueResponse.QueueUrl;
                Debug.WriteLine($"QueueURL: {this.queueUrl}");

                var getQueueAttributesRequest = new GetQueueAttributesRequest {
                    AttributeNames = new List <string> {
                        "QueueArn"
                    },
                    QueueUrl = this.queueUrl
                };
                var response = sqsClient.GetQueueAttributes(getQueueAttributesRequest);

                queueArn = response.QueueARN;
                Debug.WriteLine($"QueueArn: {queueArn}");

                // Setup the Amazon SNS topic to publish to the SQS queue.
                snsClient.Subscribe(new SubscribeRequest()
                {
                    Protocol = "sqs",
                    Endpoint = queueArn,
                    TopicArn = topicArn
                });

                // Add the policy to the queue so SNS can send messages to the queue.
                var policy = SQS_POLICY.Replace("{TopicArn}", topicArn).Replace("{QuernArn}", queueArn);

                sqsClient.SetQueueAttributes(new SetQueueAttributesRequest {
                    QueueUrl   = this.queueUrl,
                    Attributes = new Dictionary <string, string>
                    {
                        { QueueAttributeName.Policy, policy }
                    }
                });
            }
        protected override string CreateResponseQueue()
        {
            var createRequest = new CreateQueueRequest();

            createRequest.QueueName = Guid.NewGuid().ToString().Substring(0, 6);
            var createResponse = _sqsClient.CreateQueue(createRequest);

            return(createResponse.QueueUrl);
        }
        static void SetupTopicAndQueue(Amazon.RegionEndpoint region)
        {
            long ticks = DateTime.Now.Ticks;

            // Setup SNS topic.
            s_snsClient = new AmazonSimpleNotificationServiceClient(region);
            s_sqsClient = new AmazonSQSClient(region);

            s_topicArn = s_snsClient.CreateTopic(new CreateTopicRequest
            {
                Name = "GlacierDownload-" + ticks
            }).TopicArn;

            WriteLogConsole("topicArn: " + s_topicArn);

            CreateQueueRequest createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = "GlacierDownload-" + ticks;
            CreateQueueResponse createQueueResponse = s_sqsClient.CreateQueue(createQueueRequest);

            s_queueUrl = createQueueResponse.QueueUrl;

            WriteLogConsole("QueueURL: " + s_queueUrl);

            GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest();

            getQueueAttributesRequest.AttributeNames = new List <string> {
                "QueueArn"
            };
            getQueueAttributesRequest.QueueUrl = s_queueUrl;

            GetQueueAttributesResponse response = s_sqsClient.GetQueueAttributes(getQueueAttributesRequest);

            s_queueArn = response.QueueARN;
            WriteLogConsole("QueueArn: " + s_queueArn);

            // Setup the Amazon SNS topic to publish to the SQS queue.
            s_snsClient.Subscribe(new SubscribeRequest()
            {
                Protocol = "sqs",
                Endpoint = s_queueArn,
                TopicArn = s_topicArn
            });

            // Add the policy to the queue so SNS can send messages to the queue.
            var policy = SQS_POLICY.Replace("{TopicArn}", s_topicArn).Replace("{QuernArn}", s_queueArn);

            s_sqsClient.SetQueueAttributes(new SetQueueAttributesRequest()
            {
                QueueUrl   = s_queueUrl,
                Attributes = new Dictionary <string, string>
                {
                    { QueueAttributeName.Policy, policy }
                }
            });
        }
Exemple #12
0
        public void TestMultipleQueueSubscription()
        {
            var topicArns = new List <string>();

            var topicName1 = "dotnetsdkTopic" + DateTime.Now.Ticks;

            topicArns.Add(Client.CreateTopic(topicName1).TopicArn);

            var topicName2 = "dotnetsdkTopic" + DateTime.Now.Ticks;

            topicArns.Add(Client.CreateTopic(topicName2).TopicArn);

            var queueName = "dotnetsdkQueue-" + DateTime.Now.Ticks;
            var queueUrl  = sqsClient.CreateQueue(queueName).QueueUrl;

            try
            {
                var subscriptionArns = Client.SubscribeQueueToTopics(topicArns, sqsClient, queueUrl).Values;

                Assert.AreEqual(2, subscriptionArns.Count);

                Thread.Sleep(TimeSpan.FromSeconds(5));

                var attributes = sqsClient.GetQueueAttributes(queueUrl, new List <string> {
                    "All"
                }).Attributes;
                var policy = Policy.FromJson(attributes["Policy"]);

                Assert.AreEqual(2, policy.Statements.Count);
            }
            finally
            {
                foreach (var topicArn in topicArns)
                {
                    Client.DeleteTopic(new DeleteTopicRequest {
                        TopicArn = topicArn
                    });
                }
                sqsClient.DeleteQueue(new DeleteQueueRequest {
                    QueueUrl = queueUrl
                });
            }
        }
Exemple #13
0
 public void Ensure()
 {
     if (!Exists())
     {
         var request = new CreateQueueRequest();
         request.QueueName = QueueName;
         var response = _sqsClient.CreateQueue(request);
         QueueUrl = response.QueueUrl;
         PopulateArn();
     }
 }
        public override IMessageQueue GetResponseQueue()
        {
            var createRequest = new CreateQueueRequest();

            createRequest.QueueName = Guid.NewGuid().ToString().Substring(0, 6);
            var createResponse = _sqsClient.CreateQueue(createRequest);

            var responseQueue = MessageQueueFactory.CreateInbound(createResponse.QueueUrl, MessagePattern.RequestResponse, true);

            return(responseQueue);
        }
Exemple #15
0
 public static string CreateBidQueue()
 {
     using (var sqs = new AmazonSQSClient())
     {
         var sqsRequest = new CreateQueueRequest {
             QueueName = auctionCode + "_Bid"
         };
         var createQueueResponse = sqs.CreateQueue(sqsRequest);
         return(createQueueResponse.QueueUrl);
     }
 }
Exemple #16
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            CreateQueueResponse queueResponse = new CreateQueueResponse();

            queueResponse = objClient.CreateQueue(new CreateQueueRequest()
            {
                QueueName = this.txtQueueName.Text
            });
            Response.Write("<script>alert('Queue Creation Request sent. It may take few seconds to Create Queue.');</script>");
            DisplayQueues();
        }
Exemple #17
0
 //
 //====================================================================================================
 //
 public static string createQueue(CoreController core, AmazonSQSClient sqsClient, string queueName)
 {
     try {
         var queueRequest = new Amazon.SQS.Model.CreateQueueRequest(core.appConfig.name.ToLowerInvariant() + "_" + queueName);
         queueRequest.Attributes.Add("VisibilityTimeout", "600");
         var queueResponse = sqsClient.CreateQueue(queueRequest);
         return(queueResponse.QueueUrl);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         return("");
     }
 }
Exemple #18
0
        /// <summary>
        /// Create a new named queue and gets its URI.
        /// </summary>
        /// <param name="queueName">Queue name.</param>
        /// <returns>True if the named queue was created.</returns>
        public bool CreateQueue(SqsQueueName queueName)
        {
            var response = Invoke(() =>
                                  _client.CreateQueue(new CreateQueueRequest {
                QueueName = queueName.Value
            }),
                                  queueName,
                                  CREATING_QUEUE
                                  );

            return(response.HttpStatusCode == HttpStatusCode.OK);
        }
Exemple #19
0
        static void SetupTopicAndQueue(Amazon.RegionEndpoint awsRegion)
        {
            long ticks = DateTime.Now.Ticks;

            // Setup SNS topic.
            snsClient = new AmazonSimpleNotificationServiceClient(awsRegion);
            sqsClient = new AmazonSQSClient(awsRegion);

            topicArn = snsClient.CreateTopic(new CreateTopicRequest {
                Name = "GlacierInventory-" + ticks
            }).TopicArn;
            Console.WriteLine($"topicArn: {topicArn}");

            CreateQueueRequest createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = "GlacierInventory-" + ticks;
            CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(createQueueRequest);

            queueUrl = createQueueResponse.QueueUrl;
            Console.WriteLine($"QueueURL: {queueUrl}");

            GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest();

            getQueueAttributesRequest.AttributeNames = new List <string> {
                "QueueArn"
            };
            getQueueAttributesRequest.QueueUrl = queueUrl;
            GetQueueAttributesResponse response = sqsClient.GetQueueAttributes(getQueueAttributesRequest);

            queueArn = response.QueueARN;
            Console.WriteLine($"QueueArn: {queueArn}");

            // Setup the Amazon SNS topic to publish to the SQS queue.
            snsClient.Subscribe(new SubscribeRequest()
            {
                Protocol = "sqs",
                Endpoint = queueArn,
                TopicArn = topicArn
            });

            // Add the policy to the queue so SNS can send messages to the queue.
            var policy = SQS_POLICY.Replace("{TopicArn}", topicArn).Replace("{QuernArn}", queueArn).Replace("{AccountArn}", accountArn);

            sqsClient.SetQueueAttributes(new SetQueueAttributesRequest()
            {
                QueueUrl   = queueUrl,
                Attributes = new Dictionary <string, string>
                {
                    { QueueAttributeName.Policy, policy }
                }
            });
        }
Exemple #20
0
        public void CreateSQSQueue()
        {
            CreateQueueRequest request = new CreateQueueRequest {
                QueueName = QueueName
            };
            var response = client.CreateQueue(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine("SQS Queue Created Successfully");
                Console.WriteLine($"SQS Queue Url: {response.QueueUrl}");
            }
        }
Exemple #21
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);
            }
        }
Exemple #22
0
        //  Creating a queue

        public void CreateQueue(AmazonSQSClient sqs, string queuename)
        {
            // var sqs = AWSClientFactory.CreateAmazonSQSClient();
            var queueName = queuename;

            Console.WriteLine("Create a queue called " + queueName + ".  :");
            var sqsRequest = new CreateQueueRequest {
                QueueName = queuename
            };
            var    createQueueResponse = sqs.CreateQueue(sqsRequest);
            string myQueueUrl          = createQueueResponse.QueueUrl;

            Console.WriteLine("Queue:" + myQueueUrl + ".  ");
        }
Exemple #23
0
        // http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryCreateQueue.html
        private string GetQueueUrl()
        {
            var request = new CreateQueueRequest();

            request.WithQueueName(_queue).WithDefaultVisibilityTimeout(60);

            var response = _client.CreateQueue(request);

            if (!response.IsSetCreateQueueResult())
            {
                throw new InvalidOperationException("Cannot open the queue");
            }
            return(response.CreateQueueResult.QueueUrl);
        }
Exemple #24
0
        public void CreateQueue(string address)
        {
            _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}");
                }
            }
        }
Exemple #25
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);
        }
Exemple #26
0
        public void CreateSQSQueue()
        {
            CreateQueueRequest request = new CreateQueueRequest
            {
                //QueueName = queueName
                QueueName = "myAppQueue2"
            };

            var response = client.CreateQueue(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("SQS Create Successfully");
                Console.WriteLine($"SQS URL:{response.QueueUrl}");
            }
            Console.ReadLine();
        }
        public void OnCreateQueueExample()
        {
            AmazonSQSClient client = new AmazonSQSClient();

            var request = new CreateQueueRequest
            {
                QueueName  = "SQS_QUEUE_NAME",
                Attributes = new Dictionary <string, string>
                {
                    { "ReceiveMessageWaitTimeSeconds", "20" }
                }
            };

            var response = client.CreateQueue(request);

            Console.WriteLine("Created a queue with URL : {0}", response.QueueUrl);
        }
        public void TestCreateMessageQueue()
        {
            AmazonSQSConfig SqsConfig = new AmazonSQSConfig
            {
                ServiceURL = "http://sqs.us-east-2.amazonaws.com"
            };

            AmazonSQSClient SqsClient = new AmazonSQSClient(SqsConfig);

            var createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = "TestingTheQueue";

            var createQueueResponse = SqsClient.CreateQueue(createQueueRequest);

            Assert.IsNotNull(createQueueResponse);
        }
Exemple #29
0
        public void CreateQueue(string address)
        {
            _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;
            }
        }
        public void CreateQueueExample()
        {
            AmazonSQSClient client = new AmazonSQSClient();

            var request = new CreateQueueRequest
            {
                QueueName  = "SQS_QUEUE_NAME",
                Attributes = new Dictionary <string, string>
                {
                    { "DelaySeconds", "60" },
                    { "MessageRetentionPeriod", "86400" }
                }
            };


            var response = client.CreateQueue(request);

            Console.WriteLine("Created a queue with URL : {0}", response.QueueUrl);
        }