// Receiving endpoint all message public DateTime ReceviveEndpointAllQueueMessage(string endpoint, string[] queueCollection) { AmazonSQSConfig amazonSqsConfig = new AmazonSQSConfig { ServiceURL = endpoint }; AmazonSQSClient sqs = new AmazonSQSClient(amazonSqsConfig); foreach (var queuename in queueCollection) { var receiveMessageRequest = new ReceiveMessageRequest { AttributeNames = new List <string>() { "All" }, MaxNumberOfMessages = 10, QueueUrl = endpoint + Program.MyAccountNumber + queuename, VisibilityTimeout = (int)TimeSpan.FromMinutes(2).TotalSeconds, WaitTimeSeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds }; // var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = USwest2Url }; var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count > 0) { foreach (var message in receiveMessageResponse.Messages) { if (message.Body.Count() > 5) { //Console.WriteLine("Setting up DynamoDB client"); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig(); config.ServiceURL = Program.DynamoDbUSwestEndpoint; var client = new AmazonDynamoDBClient(config); TableOperations.PutItem(client, s, endpoint, message.MessageId); // TableOperations.PutItem2(5,client, s, endpoint); //s[0]++; } else { Console.WriteLine("nothing sent "); } // var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle; var messageRecieptHandle = message.ReceiptHandle; //Deleting a message DateTime t = DateTime.Now; Console.WriteLine("Deleting the message from queue.\n" + t); var deleteRequest = new DeleteMessageRequest { QueueUrl = endpoint + Program.MyAccountNumber + queuename, ReceiptHandle = messageRecieptHandle }; sqs.DeleteMessage(deleteRequest); } } else { Console.WriteLine("No messages received."); } Console.WriteLine(queuename + "is finished"); } return(DateTime.Now); }
// Receiving a message public DateTime ReceviveMessage(string endpoint, string queuename) { //var sqs = AWSClientFactory.CreateAmazonSQSClient(); AmazonSQSConfig amazonSqsConfig = new AmazonSQSConfig { ServiceURL = endpoint }; AmazonSQSClient sqs = new AmazonSQSClient(amazonSqsConfig); var receiveMessageRequest = new ReceiveMessageRequest { AttributeNames = new List <string>() { "All" }, MaxNumberOfMessages = 10, QueueUrl = endpoint + Program.MyAccountNumber + Program.Queuename, VisibilityTimeout = (int)TimeSpan.FromMinutes(2).TotalSeconds, WaitTimeSeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds }; // var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = USwest2Url }; var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count > 0) { // Console.WriteLine("Printing received message from \n" + endpoint + Program.MyAccountNumber + Program.Queuename); foreach (var message in receiveMessageResponse.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); // } if (message.Body.Count() > 5) { //Console.WriteLine("Setting up DynamoDB client"); AmazonDynamoDBConfig config = new AmazonDynamoDBConfig(); config.ServiceURL = Program.DynamoDbUSwest2Endpoint; var client = new AmazonDynamoDBClient(config); TableOperations.PutItem(client, s, endpoint, message.MessageId); // TableOperations.PutItem2(5,client, s, endpoint); s[0]++; } else { Console.WriteLine("nothing sent "); } // // 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; // var messageRecieptHandle = message.ReceiptHandle; // // //Deleting a message // DateTime t = DateTime.Now; // Console.WriteLine("Deleting the message from queue.\n"+t); // var deleteRequest = new DeleteMessageRequest // { // QueueUrl = endpoint +Program.MyAccountNumber+ Program.Queuename, // ReceiptHandle = messageRecieptHandle // }; // sqs.DeleteMessage(deleteRequest); } } else { Console.WriteLine("No messages received."); } // Console.WriteLine(DateTime.Now); return(DateTime.Now); }