Ejemplo n.º 1
0
        public string[] ListQueuename(string endpoint)
        {
            AmazonSQSConfig amazonSqsConfig = new AmazonSQSConfig {
                ServiceURL = endpoint
            };
            AmazonSQSClient sqs = new AmazonSQSClient(amazonSqsConfig);
            int             s   = endpoint.Length + Program.MyAccountNumber.Length;

            int l = 0;
            //Confirming the queue exists
            var listQueuesRequest  = new ListQueuesRequest();
            var listQueuesResponse = sqs.ListQueues(listQueuesRequest);
            int size = listQueuesResponse.QueueUrls.Count;

            string[] queueCollection = new string[size];
            //Console.WriteLine("Printing list of Amazon SQS queues.\n");
            if (listQueuesResponse.QueueUrls != null)
            {
                int i = 0;
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    l = queueUrl.Length;
                    queueCollection[i] = queueUrl.Substring(s, l - s);
                    i++;
                }
            }

            return(queueCollection);
        }
        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));
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            var             appSettings = ConfigurationManager.AppSettings;
            AmazonSQSClient sqsClient   = new AmazonSQSClient(appSettings["AWSKeyID"], appSettings["AWSAccessKey"], RegionEndpoint.USEast1);
            var             queueUrl    = sqsClient.ListQueues("Queue-For-SES-Notifications").QueueUrls[0];

            while (true)
            {
                var response = sqsClient.ReceiveMessage(queueUrl);
                // Check our response
                if (response.Messages.Count > 0)
                {
                    foreach (var message in response.Messages)
                    {
                        // Send an email
                        var body = (JObject)JsonConvert.DeserializeObject(message.Body, typeof(JObject));
                        MessageBox.Show(body["Message"].ToString());

                        // Delete our message so that it doesn't get handled again
                        sqsClient.DeleteMessage(queueUrl, message.ReceiptHandle);
                    }
                }
                else
                {
                    MessageBox.Show("No more SQS message in queue");
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private bool checkQueueExist()
        {
            try
            {
                bool exist = false;
                listQueues = new ListQueuesRequest();
                var lista = sqsClient.ListQueues(listQueues);

                List <String> colas = new List <String>();
                foreach (var urls in lista.QueueUrls)
                {
                    String[] array  = urls.Split('/');
                    String   nombre = array[array.Length - 1];
                    if (nombre == queue)
                    {
                        url   = urls.Replace(array[array.Length - 1], "");
                        exist = true;
                    }
                }

                return(exist);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public MessageQueueDetail Build <T>(string uri)
        {
            var listResponse = _client.ListQueues(new ListQueuesRequest().WithQueueNamePrefix(uri));
            var exists       = listResponse.ListQueuesResult.QueueUrl.Any();

            if (exists)
            {
                var queue    = _client.GetQueueUrl(new GetQueueUrlRequest().WithQueueName(uri));
                var request  = new GetQueueAttributesRequest().WithQueueUrl(queue.GetQueueUrlResult.QueueUrl);
                var response = _client.GetQueueAttributes(request);

                return(new MessageQueueDetail
                {
                    MessageCount = response.GetQueueAttributesResult.ApproximateNumberOfMessages,
                    Uri = queue.GetQueueUrlResult.QueueUrl,
                    Exists = true
                });
            }
            else
            {
                return(new MessageQueueDetail
                {
                    MessageCount = null,
                    Uri = uri,
                    Exists = false
                });
            }
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonSQSConfig config = new AmazonSQSConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonSQSClient client = new AmazonSQSClient(creds, config);

            ListQueuesResponse resp = new ListQueuesResponse();

            do
            {
                ListQueuesRequest req = new ListQueuesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListQueues(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.QueueUrls)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private void readMessages()
        {
            while (!exit)
            {
                var request = new ListQueuesRequest
                {
                    QueueNamePrefix = QueueName
                };
                var client   = new AmazonSQSClient();
                var response = client.ListQueues(request);
                var url      = response.ListQueuesResult.QueueUrl;

                var receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.MaxNumberOfMessages = 5;
                receiveMessageRequest.QueueUrl            = url[0];

                var receiveMessageResponse = client.ReceiveMessage(receiveMessageRequest);

                foreach (var message in receiveMessageResponse.ReceiveMessageResult.Message)
                {
                    //If we want to prevent dispay the same message again.
                    //if(!messages.Contains(message.MessageId))
                    //{
                    MessageBox.Show(message.Body);
                    //Addin the message to the list
                    //    this.messages.Add(message.MessageId);
                    //}
                }
                //Sleeping time
                System.Threading.Thread.Sleep(5000);
            }
        }
Ejemplo n.º 9
0
        private static string FindBidQueueUrl(string auctionCode, AmazonSQSClient sqs)
        {
            var listQueuesRequest  = new ListQueuesRequest();
            var listQueuesResponse = sqs.ListQueues(listQueuesRequest);

            return(listQueuesResponse.QueueUrls?.FirstOrDefault(queueUrl => queueUrl.EndsWith(auctionCode + "_Bid")));
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            try
            {
                var client = new AmazonSQSClient();

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

                var response = client.ListQueues(request);
                var urls     = response.QueueUrls;

                if (urls.Any())
                {
                    Console.WriteLine("Queue URLs:");

                    foreach (var url in urls)
                    {
                        Console.WriteLine("  " + url);
                    }
                }
                else
                {
                    Console.WriteLine("No queues.");
                }

                //this is the interface to SQS Service
                AmazonSQSClient SQSClient = new AmazonSQSClient();

                //create the message object
                SendMessageRequest MessageRequest = new SendMessageRequest();

                //read this URL from the AWS SQS console
                MessageRequest.QueueUrl = "your queue URL";

                //set the message text
                MessageRequest.MessageBody = "This is a test";

                //send the message
                SQSClient.SendMessage(MessageRequest);

                //prevent the console window from closing
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                //display exception
                Console.WriteLine(ex.Message);
                //prevent the console window from closing
                Console.ReadLine();
            }
        }
Ejemplo n.º 12
0
        public void ListQueueExample()
        {
            AmazonSQSClient client = new AmazonSQSClient();

            ListQueuesResponse response = client.ListQueues(new ListQueuesRequest());

            foreach (var queueUrl in response.QueueUrls)
            {
                Console.WriteLine(queueUrl);
            }
        }
Ejemplo n.º 13
0
        //
        //====================================================================================================
        //
        public static List <string> getQueueList(CoreController core, AmazonSQSClient sqsClient)
        {
            var result             = new List <string>();
            var listQueuesResponse = sqsClient.ListQueues(core.appConfig.name.ToLowerInvariant() + "_");
            int nameStartPos       = core.appConfig.name.Length;

            foreach (var queueUrl in listQueuesResponse.QueueUrls)
            {
                result.Add(queueUrl.Substring(nameStartPos));
            }
            return(result);
        }
Ejemplo n.º 14
0
        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);
                }
            }
        }
Ejemplo n.º 15
0
 virtual public bool AppMode_TestSqsAccess(RegionEndpoint regionEndpoint, SessionAWSCredentials credentials)
 {
     try
     {
         var sqsClient = new AmazonSQSClient(credentials, regionEndpoint);
         sqsClient.ListQueues(new ListQueuesRequest());
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// This method displays the Queue
        /// </summary>
        private void DisplayQueues()
        {
            ListQueuesResponse objqueuesResponseList = new ListQueuesResponse();

            objqueuesResponseList = objClient.ListQueues(new ListQueuesRequest());


            ListQueuesResult Result = objqueuesResponseList.ListQueuesResult;

            this.QueuesList.Visible    = true;
            this.QueuesList.DataSource = Result.QueueUrl;
            this.QueuesList.DataBind();
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        public void ListQueues()
        {
            ListQueuesRequest request = new ListQueuesRequest {
            };
            var respone = client.ListQueues(request);

            if (respone.HttpStatusCode.IsSuccess())
            {
                foreach (var queue in respone.QueueUrls)
                {
                    Console.WriteLine(queue);
                }
            }
        }
Ejemplo n.º 19
0
        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);
                }
            }
        }
Ejemplo n.º 20
0
        public void ListQueues()
        {
            ListQueuesRequest request = new ListQueuesRequest();

            var response = client.ListQueues(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                foreach (var item in response.QueueUrls)
                {
                    Console.WriteLine($"{item}");
                }
            }
            //Console.ReadLine();
        }
Ejemplo n.º 21
0
        public bool Exists()
        {
            var exists      = false;
            var queues      = _sqsClient.ListQueues(QueueName);
            var matchString = string.Format("/{0}", QueueName);
            var matches     = queues.QueueUrls.Where(x => x.EndsWith(QueueName));

            if (matches.Count() == 1)
            {
                exists   = true;
                QueueUrl = matches.ElementAt(0);
                PopulateArn();
            }
            return(exists);
        }
Ejemplo n.º 22
0
        public void list_queues()
        {
            var response = _client.ListQueues(new ListQueuesRequest());

            foreach (var result in response.ListQueuesResult.QueueUrl)
            {
                Console.WriteLine(result);
            }
            var attribute = _client.GetQueueAttributes(
                new GetQueueAttributesRequest().WithQueueUrl(_queueUrl).WithAttributeName("QueueArn"));

            foreach (var att in attribute.GetQueueAttributesResult.Attribute)
            {
                Console.WriteLine(att.Value);
            }
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                throw new Exception("'Queue prefix or name' 1");
            }

            var isRead = false;

            if (args[1] == "1")
            {
                isRead = true;
            }

            var queuePrefix = args[0];

            var sqsClient = new AmazonSQSClient();

            var queuesResult = sqsClient.ListQueues(new ListQueuesRequest {
                QueueNamePrefix = queuePrefix
            });

            if (queuesResult.QueueUrls.Count > 1)
            {
                throw new Exception("More then one queue found with prefix:" + queuePrefix);
            }
            if (queuesResult.QueueUrls.Count == 0)
            {
                throw new Exception("No queue found with prefix:" + queuePrefix);
            }

            var queueUrl = queuesResult.QueueUrls.First();

            var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sqs-messages", DateTime.Now.ToString("yyyyMMddhhmmss"));


            if (isRead)
            {
                Read(sqsClient, dir, queueUrl);
            }
        }
Ejemplo n.º 24
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonSQSConfig config = new AmazonSQSConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonSQSClient client = new AmazonSQSClient(creds, config);

            ListQueuesResponse resp = new ListQueuesResponse();
            ListQueuesRequest  req  = new ListQueuesRequest
            {
            };

            resp = client.ListQueues(req);
            CheckError(resp.HttpStatusCode, "200");

            foreach (var obj in resp.QueueUrls)
            {
                AddObject(obj);
            }
        }
Ejemplo n.º 25
0
        //check exist queue

        public void ListQueue(string endpoint)
        {
            AmazonSQSConfig amazonSqsConfig = new AmazonSQSConfig {
                ServiceURL = endpoint
            };
            AmazonSQSClient sqs = new AmazonSQSClient(amazonSqsConfig);

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


            Console.WriteLine("Printing list of Amazon SQS queues.\n");
            if (listQueuesResponse.QueueUrls != null)
            {
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    Console.WriteLine("  QueueUrl: {0}", queueUrl);
                }
            }
        }
Ejemplo n.º 26
0
        //check exist queue

        public string ListQueue(string endpoint)
        {
            AmazonSQSConfig amazonSqsConfig = new AmazonSQSConfig {
                ServiceURL = endpoint
            };
            AmazonSQSClient sqs = new AmazonSQSClient(amazonSqsConfig);

            string res = "";

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

            res = res + "Printing list of Amazon SQS queues.  : ";
            if (listQueuesResponse.QueueUrls != null)
            {
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    res = res + queueUrl + ".  ";
                }
            }
            return(res);
        }
Ejemplo n.º 27
0
        public static Uri GetQueueUrl(string queueNamePrefix)
        {
            using (var sqsClient = new AmazonSQSClient())
            {
                var request = new ListQueuesRequest
                {
                    QueueNamePrefix = queueNamePrefix
                };

                var response = sqsClient.ListQueues(request);

                if (response != null)
                {
                    var queueUrl = response.QueueUrls.FirstOrDefault();

                    if (queueUrl != null)
                    {
                        return(new Uri(queueUrl));
                    }
                }

                return(null);
            }
        }
Ejemplo n.º 28
0
        private static void ListQueues(AmazonSQSClient sqsClient)
        {
            var listQueuesResponse = sqsClient.ListQueues(new ListQueuesRequest());

            Console.WriteLine($"ListQueues HTTP status code: {listQueuesResponse.HttpStatusCode}");
        }
Ejemplo n.º 29
0
        public static void Main(string[] args)
        {
            var sqs = new AmazonSQSClient();

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

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

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

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

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                var sendMessageRequest = new SendMessageRequest
                {
                    QueueUrl    = myQueueUrl,  //URL from initial queue creation
                    MessageBody = "This is my message text."
                };
                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 static void Main(string[] args)
        {
            var sqs_object = new AmazonSQSClient();

            try
            {
                // Create the SQS queue request and give it a name
                var create_queue_request = new CreateQueueRequest
                {
                    QueueName = "packtpub_queue"
                };
                // create the queue and fetch the response object
                var    create_queue_response = sqs_object.CreateQueue(create_queue_request);
                string queue_url             = create_queue_response.QueueUrl;



                // List queues
                var listQueuesRequest  = new ListQueuesRequest();
                var listQueuesResponse = sqs_object.ListQueues(listQueuesRequest);

                if (listQueuesResponse.QueueUrls != null)
                {
                    foreach (String urls in listQueuesResponse.QueueUrls)
                    {
                        Console.WriteLine(" Queue URL : {0}", urls);
                    }
                }

                //Send a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                var send_message_request = new SendMessageRequest
                {
                    QueueUrl    = queue_url, //URL from initial queue creation
                    MessageBody = "Welcome, hybrid cloud developers !"
                };
                sqs_object.SendMessage(send_message_request);

                // Recieve a message
                var receive_message_request = new ReceiveMessageRequest {
                    QueueUrl = queue_url
                };
                var received_message_response = sqs_object.ReceiveMessage(receive_message_request);
                if (received_message_response.Messages != null)
                {
                    foreach (var message in received_message_response.Messages)
                    {
                        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 key in message.Attributes.Keys)
                        {
                            Console.WriteLine("Attribute");
                            Console.WriteLine("Name: {0}", key);
                            var value = message.Attributes[key];
                            Console.WriteLine("Value: {0}", string.IsNullOrEmpty(value) ? "(no value)" : value);
                        }
                    }
                }

                // Delete message from queue
                //var message_handle = received_message_response.Messages[0].ReceiptHandle;

                //var deleteRequest = new DeleteMessageRequest
                //{
                //    QueueUrl = queue_url,
                //    ReceiptHandle = message_handle
                //};
                //sqs_object.DeleteMessage(deleteRequest);
            }
            catch (AmazonSQSException exception)
            {
                Console.WriteLine("Error !");
                Console.WriteLine(exception.ErrorCode);
            }
        }