public void send_and_recieve_messages() { Console.WriteLine("Sending Message"); var sendMessageRequest = new SendMessageRequest() .WithQueueUrl(_queueUrl) .WithMessageBody("Hello from the cloud"); var sendResult = _client.SendMessage(sendMessageRequest); Console.WriteLine(sendResult.ToXML()); Console.WriteLine("Receiving Message"); var request = new ReceiveMessageRequest(). WithQueueUrl(_queueUrl); var result = _client.ReceiveMessage(request); foreach (var message in result.ReceiveMessageResult.Message) { Console.WriteLine(message.Body); _client.DeleteMessage( new DeleteMessageRequest().WithQueueUrl(_queueUrl).WithReceiptHandle(message.ReceiptHandle)); } }
private void listMessages() { receiveMessageRequest = new ReceiveMessageRequest() { QueueUrl = url, MaxNumberOfMessages = 10 }; var response = sqsClient.ReceiveMessage(receiveMessageRequest); foreach (var item in response.Messages) { VentaBE ventaBE = new JavaScriptSerializer().Deserialize <VentaBE>(item.Body); ventaBE.Id = item.MessageId; int index = lista.FindIndex(f => f.Id == item.MessageId); if (index < 0) { lista.Add(ventaBE); } } if (countList != lista.Count) { BindingSource bs = new BindingSource(); bs.DataSource = lista; dgvVentas.DataSource = bs; bs.ResetBindings(false); countList = lista.Count; } }
//--- Methods --- /// <summary> /// Receive zero or more messages from name queue. /// </summary> /// <param name="queueName">Queue name.</param> /// <param name="waitTimeSeconds">Max amount of time to wait until this method returns.</param> /// <param name="maxNumberOfMessages">Max number of messages to request.</param> /// <returns>Enumeration of received messages.</returns> public IEnumerable <SqsMessage> ReceiveMessages(SqsQueueName queueName, TimeSpan waitTimeSeconds, uint maxNumberOfMessages) { // Check preconditions if (waitTimeSeconds.TotalSeconds > SqsUtils.MAX_LONG_POLL_WAIT_TIME.TotalSeconds) { throw new ArgumentException(string.Format("The argument waitTimeSeconds is larger than '{0}', which is the maximum value allowed", SqsUtils.MAX_LONG_POLL_WAIT_TIME.TotalSeconds)); } if (maxNumberOfMessages > SqsUtils.MAX_NUMBER_OF_MESSAGES_TO_FETCH) { throw new ArgumentException(string.Format("The argument maxNumberOfMessages is larger than '{0}', which is the maximum value allowed", SqsUtils.MAX_NUMBER_OF_MESSAGES_TO_FETCH)); } // Perform request var response = Invoke(() => _client.ReceiveMessage(new ReceiveMessageRequest { QueueUrl = GetQueueUrl(queueName.Value), WaitTimeSeconds = (int)waitTimeSeconds.TotalSeconds, MaxNumberOfMessages = (int)maxNumberOfMessages }), queueName, RECEIVING_MESSAGE ); AssertSuccessfulStatusCode(response.HttpStatusCode, queueName, RECEIVING_MESSAGE); return(response.Messages.Select(msg => new SqsMessage(new SqsMessageId(msg.MessageId), new SqsMessageReceipt(msg.ReceiptHandle), msg.Body)).ToArray()); }
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; } } }
public static ReceiveMessageResponse GetMessageResult(AmazonSQSClient sqsClient, ReceiveMessageRequest request) { Debug.WriteLine(String.Format("RUNNING SOLUTION CODE: {0}! Follow the steps in the lab guide to replace this method with your own implementation.\n", "GetMessageResult")); ReceiveMessageResponse receiveMessageResult = sqsClient.ReceiveMessage(request); return(receiveMessageResult); }
private static void SendMessagesWithInjectedHeaders(AmazonSQSClient sqsClient) { // Send one message, receive it, and parse it for its headers sqsClient.SendMessage(_singleQueueUrl, "SendMessageAsync_SendMessageRequest"); var receiveMessageRequest = new ReceiveMessageRequest() { QueueUrl = _singleQueueUrl, MessageAttributeNames = new List <string>() { ".*" } }; var receiveMessageResponse1 = sqsClient.ReceiveMessage(receiveMessageRequest); sqsClient.DeleteMessage(_singleQueueUrl, receiveMessageResponse1.Messages.First().ReceiptHandle); Common.AssertDistributedTracingHeaders(receiveMessageResponse1.Messages); // Send a batch of messages, receive them, and parse them for headers var sendMessageBatchRequest = new SendMessageBatchRequest { Entries = new List <SendMessageBatchRequestEntry> { new("message1", "SendMessageBatchAsync: FirstMessageContent"), new("message2", "SendMessageBatchAsync: SecondMessageContent"), new("message3", "SendMessageBatchAsync: ThirdMessageContent") },
public void FetchMessages() { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(); if (useFIFOQueue == true) { receiveMessageRequest.QueueUrl = Configurations.FIFOQueueURL; } else { receiveMessageRequest.QueueUrl = Configurations.QueueURL; } receiveMessageRequest.MaxNumberOfMessages = 10; receiveMessageRequest.WaitTimeSeconds = 1; ReceiveMessageResponse receiveMessageResponse = sqsClient.ReceiveMessage(receiveMessageRequest); // This queue doesn't guarantee the order of the messages. if (receiveMessageResponse != null) { foreach (var msg in receiveMessageResponse.Messages) { ReceivedMessageEvent(msg.Body); DeleteMessageFromQueue(msg.ReceiptHandle); } } }
private static void WaitForInputMessage( string listenerQueueName, char delimiter, AmazonSQSClient sqsClient, ReceiveMessageRequest recRequest, out string requestMessageId, out List <Tuple <int, string> > tuples) { logger.Info("Checking messages"); tuples = null; requestMessageId = "0"; ReceiveMessageResponse response = sqsClient.ReceiveMessage(recRequest); if (response.Messages.Count == 0) { return; } requestMessageId = response.Messages[0].MessageId; logger.Info("processing message: " + requestMessageId); // will be used to delete message string messageReceiptHandle = response.Messages[0].ReceiptHandle; string body = response.Messages[0].Body; tuples = ConversionRequestMessage.GetIdAndFileTuples(body, delimiter.ToString()); // delete message and dp the work // delete message DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.QueueUrl = listenerQueueName; deleteMessageRequest.ReceiptHandle = messageReceiptHandle; // success is not tested !!! sqsClient.DeleteMessage(deleteMessageRequest); }
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); } }
public void ReceiveMessage() { var receiveRequest = new ReceiveMessageRequest { QueueUrl = _settings.QueueUrl }; var queue = new AmazonSQSClient(_settings.AccessKey, _settings.SecretKey, _settings.Region); var receiveResponse = queue.ReceiveMessage(receiveRequest); receiveResponse.Messages.ForEach(x => { Console.Write("Received message: {0}", x.Body); var message = JsonConvert.DeserializeObject <PushMessage>(x.Body); if (message == null) { return; } ProcessMessage(message); var deleteMessageRequest = new DeleteMessageRequest { QueueUrl = _settings.QueueUrl, ReceiptHandle = x.ReceiptHandle }; queue.DeleteMessage(deleteMessageRequest); }); }
public List <string> ReceiveMessage() { var receiptHandles = new List <string>(); try { var receiveMessageRequest = new ReceiveMessageRequest(); receiveMessageRequest.QueueUrl = awsSqsConfiguration.QueueURL; var receiveMessageResponse = amazonSQSClient.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count != 0) { for (int i = 0; i < receiveMessageResponse.Messages.Count; i++) { var message = JsonConvert.DeserializeObject <TenantActionMessage>(receiveMessageResponse.Messages[i].Body); receiptHandles.Add(receiveMessageResponse.Messages[i].ReceiptHandle); Console.WriteLine("Receive message successful : " + message.ToString()); } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.ToString()); } return(receiptHandles); }
public void ReceiveAndDeleteMessageExample() { AmazonSQSClient client = new AmazonSQSClient(); string queueUrl = "SQS_QUEUE_URL"; // // Receive a single message // var receiveMessageRequest = new ReceiveMessageRequest { AttributeNames = { "SentTimestamp" }, MaxNumberOfMessages = 1, MessageAttributeNames = { "All" }, QueueUrl = queueUrl, VisibilityTimeout = 0, WaitTimeSeconds = 0 }; var receiveMessageResponse = client.ReceiveMessage(receiveMessageRequest); // // Delete the received single message // var deleteMessageRequest = new DeleteMessageRequest { QueueUrl = queueUrl, ReceiptHandle = receiveMessageResponse.Messages[0].ReceiptHandle }; client.DeleteMessage(deleteMessageRequest); }
protected void btnReceiveMessage_Click(object sender, EventArgs e) { if (QueuesList.SelectedIndex > -1) { string message = string.Empty; string selectedQueue = this.QueuesList.SelectedItem.Value.ToString(); ReceiveMessageResponse queueReceiveMessageResponse = new ReceiveMessageResponse(); queueReceiveMessageResponse = objClient.ReceiveMessage(new ReceiveMessageRequest() { QueueUrl = selectedQueue, MaxNumberOfMessages = 10 }); ReceiveMessageResult objReceiveMessageResult = new ReceiveMessageResult(); objReceiveMessageResult = queueReceiveMessageResponse.ReceiveMessageResult; List <Message> messagesList = new List <Message>(); messagesList = objReceiveMessageResult.Message; foreach (Message objMessage in messagesList) { message += objMessage.Body; receiptHandle = objMessage.ReceiptHandle; } Session["MessageReceiptHandle"] = receiptHandle; txtReceivedMessage.Text = message; } else { Response.Write("<script>alert('Please select Queue from list.');</script>"); } }
public override async Task Receive(Action <Message> onMessageReceived, CancellationToken cancellationToken, int maximumWaitMilliseconds = 0) { var receivedRequest = new ReceiveMessageRequest { QueueUrl = MessageAddress.Address, WaitTimeSeconds = maximumWaitMilliseconds / 1000, MaxNumberOfMessages = 5 }; var receivedReponse = _sqsClient.ReceiveMessage(receivedRequest); if (receivedReponse.Messages.Any()) { receivedReponse.Messages.Where(sqsMessage => sqsMessage != null) .ToList() .ForEach(sqsMessage => { if (cancellationToken != CancellationToken.None) { Task.Factory.StartNew(() => Handle(sqsMessage, onMessageReceived), cancellationToken, TaskCreationOptions.AttachedToParent, TaskScheduler.Default); } else { Handle(sqsMessage, onMessageReceived); } }); } }
private int updateUrgency() { int currentUrgency = 0; var accessKey = "key"; var secretKey = "key"; var sqsConfig = new AmazonSQSConfig(); sqsConfig.ServiceURL = "http://sqs.us-east-1.amazonaws.com"; var sqsClient = new AmazonSQSClient(accessKey, secretKey, sqsConfig); var receiveMessageRequest = new ReceiveMessageRequest(); var queueUrl = "https://sqs.us-east-1.amazonaws.com/275098837840/InnovationShowdownButton5"; receiveMessageRequest.QueueUrl = queueUrl; var receiveMessageResponse = sqsClient.ReceiveMessage(receiveMessageRequest); var result = receiveMessageResponse.Messages; foreach (var message in result) { for (int i = 1; i <= 3; i++) { if (message.Body.Contains("urgency=" + i)) { currentUrgency = i; Console.Write(currentUrgency); } } var deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.QueueUrl = queueUrl; deleteMessageRequest.ReceiptHandle = message.ReceiptHandle; var response = sqsClient.DeleteMessage(deleteMessageRequest); } return(currentUrgency); }
private void GetMessages() { var queueUrlRequest = new GetQueueUrlRequest("Messenger.fifo"); var queueUrl = _sqsClient.GetQueueUrl(queueUrlRequest).QueueUrl; var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = queueUrl }; while () { Task.Delay(TimeSpan.FromSeconds(1)).Wait(); var receiveMessageResponse = _sqsClient.ReceiveMessage(receiveMessageRequest); foreach (var message in receiveMessageResponse.Messages) { var deserializedMessage = JsonConvert.DeserializeObject <MessageModel>(message.Body); if (deserializedMessage.ChatId.Equals(_parentViewModel.ChatId, StringComparison.InvariantCulture) && !deserializedMessage.Author.Equals(_parentViewModel.Author)) { NewMessageReceived?.Invoke(deserializedMessage); var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle; var deleteRequest = new DeleteMessageRequest { QueueUrl = queueUrl, ReceiptHandle = messageRecieptHandle }; _sqsClient.DeleteMessage(deleteRequest); } } } }
private void QueryQueue() { var _client = new AmazonSQSClient( awsAccessKeyId: AccessKeyId, awsSecretAccessKey: SecretKey, region: Amazon.RegionEndpoint.USEast1); var _request = new ReceiveMessageRequest { QueueUrl = SQSUrl, MaxNumberOfMessages = 10 }; var _response = _client.ReceiveMessage(_request); if (_response.Messages.Count > 0) { (new Thread(() => { _relayHelper = MainClass.container.Resolve <IRelayHelper>(); _relayHelper.Alarm(); })).Start(); try { _client.PurgeQueue(new PurgeQueueRequest { QueueUrl = SQSUrl }); } catch { } } }
private static List <Bid> ReadAllBidsFromQueue() { using (var sqs = new AmazonSQSClient()) { List <Bid> bids = new List <Bid>(); var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = bidQueueUrl }; var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages != null && receiveMessageResponse.Messages.Any()) { foreach (var message in receiveMessageResponse.Messages) { try { bids.Add(JsonConvert.DeserializeObject <Bid>(message.Body)); } catch { // ignored } var deleteRequest = new DeleteMessageRequest { QueueUrl = bidQueueUrl, ReceiptHandle = message.ReceiptHandle }; sqs.DeleteMessage(deleteRequest); } } return(bids); } }
static void ReadMessages(AmazonSQSClient client, ReceiveMessageRequest request, DeleteMessageRequest deleteRequest, string dir) { var result = client.ReceiveMessage(request); if (result.Messages.Count != 0) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } result.Messages.ForEach(m => { WriteToFile(m, dir); deleteRequest.ReceiptHandle = m.ReceiptHandle; // client.DeleteMessage(deleteRequest); Console.WriteLine("Processed: " + m.MessageId); } ); } else { Console.WriteLine("No Messages"); } Thread.Sleep(500); }
public ReceiveMessageResponse ReceiveMessages(AmazonSQSClient client, string Url, int visibilityTime, int waittime, int maxofMsg) { var request = new ReceiveMessageRequest() { QueueUrl = Url, VisibilityTimeout = visibilityTime, WaitTimeSeconds = waittime, MaxNumberOfMessages = maxofMsg, AttributeNames = new List <string>() { "All" } }; var response = client.ReceiveMessage(request); if (response.Messages.Count > 0) { Console.WriteLine("Message recieved successfully"); } else { Console.WriteLine("No message recieved"); } return(response); }
/// <summary> /// Deletes all messages from the input queue /// </summary> public void Purge() { if (Address == null) { return; } _log.Info("Purging {0} (by receiving all messages from the queue)", Address); try { using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, _amazonSqsConfig)) { var stopwatch = Stopwatch.StartNew(); while (true) { var response = client.ReceiveMessage(new ReceiveMessageRequest(_queueUrl) { MaxNumberOfMessages = 10 }); if (!response.Messages.Any()) { break; } var deleteResponse = client.DeleteMessageBatch(_queueUrl, response.Messages .Select(m => new DeleteMessageBatchRequestEntry(m.MessageId, m.ReceiptHandle)) .ToList()); if (deleteResponse.Failed.Any()) { var errors = string.Join(Environment.NewLine, deleteResponse.Failed.Select(f => $"{f.Message} ({f.Id})")); throw new RebusApplicationException( $@"Error {deleteResponse.HttpStatusCode} while purging: {errors}"); } } _log.Info($"Purging {Address} took {stopwatch.Elapsed.TotalSeconds:0.0} s"); } } catch (AmazonSQSException exception) when(exception.StatusCode == HttpStatusCode.BadRequest) { if (exception.Message.Contains("queue does not exist")) { return; } throw; } catch (Exception exception) { throw new RebusApplicationException(exception, $"Error while purging {Address}"); } }
/** * Receive messages from the SQS queue by using the ReceiveMessageRequest object * * @param request ReceiveMessageResult object * @return List of messages */ private static ReceiveMessageResponse GetMessageResult(ReceiveMessageRequest request) { // TODO 10: Replace the solution with your own code Debug.WriteLine(String.Format("RUNNING JAYARAJ'S CODE: {0}! \n", "GetMessageResult")); ReceiveMessageResponse receiveMessageResult = sqsClient.ReceiveMessage(request); return(receiveMessageResult); }
public void Subscribe <T>(string sQueueName, Func <T, bool> handler, bool bDeleteMsgOnSuccess = true, int iMaxMessagesAtaTime = 10, int iWaitTimeSeconds = 20) { AmazonSQSClient sqs; string sQueueUrl; if (null == handler) { throw new ArgumentException("required parameter", "handler"); } //Logger.DebugFormat("Subscribing to Queue {0}.", sQueueName); m_bShouldListen = true; Task.Run(() => { bool bHandlerRes; try { sqs = new AmazonSQSClient(); sQueueUrl = GetQueue(sqs, sQueueName); } catch (Exception ex) { Logger.ErrorFormat("Error subscribing to Queue [{0}]: {1}", sQueueName, ex); return; } Logger.DebugFormat("Subscribing to Queue: {0}; Url: {1}", sQueueName, sQueueUrl); while (m_bShouldListen) { ReceiveMessageResponse resp = sqs.ReceiveMessage( new ReceiveMessageRequest(sQueueUrl) { WaitTimeSeconds = iWaitTimeSeconds, MaxNumberOfMessages = iMaxMessagesAtaTime } ); if (HttpStatusCode.OK != resp.HttpStatusCode) { Logger.ErrorFormat("Error Reciving from queue [{0}]: {1}; {2}", sQueueName, resp.HttpStatusCode, resp.ResponseMetadata); Thread.Sleep(1000); continue; } foreach (var msg in resp.Messages) { T obj = JsonConvert.DeserializeObject <T>(msg.Body); bHandlerRes = false; try { bHandlerRes = handler(obj); } catch (Exception ex) { Logger.WarnFormat("Error running handler on queue [{0}]: {1}", sQueueName, ex); } if (bHandlerRes) { if (bDeleteMsgOnSuccess) { sqs.DeleteMessage(sQueueUrl, msg.ReceiptHandle); } } } } }); }
public List <OutboundMessage> consume() { ReceiveMessageResponse r = client.ReceiveMessage(Resources.inboundQueue); return(r.Messages.Select(m => { client.DeleteMessage(Resources.inboundQueue, m.ReceiptHandle); return JsonConvert.DeserializeObject <OutboundMessage>(m.Body); }).ToList()); }
private List <Message> GetMessageFromQueue(int number) { var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = QueueUrl, MaxNumberOfMessages = number }; var response = _sqsClient.ReceiveMessage(receiveMessageRequest); return(response.HttpStatusCode == HttpStatusCode.OK ? response.Messages : new List <Message>()); }
/// <summary> /// Read all the messages from the queue and send them to the MQTT broker /// </summary> /// <param name="state"></param> private void DoData(object state) { try { var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = _queueUrl, MaxNumberOfMessages = 10 }; List <SigfoxMessage> messages = new List <SigfoxMessage>(); int finishedCounter = 0; //Keep reading messages from the queue, until we get not results twice in a row. //https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html while (finishedCounter < 2) { var receiveMessageResponse = _sqsClient.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count == 0) { finishedCounter++; } foreach (var message in receiveMessageResponse.Messages) { try { _log.Debug(message.Body); JObject dmsg = JObject.Parse(message.Body); var smsg = new SigfoxMessage(dmsg) { RecieptHandle = message.ReceiptHandle }; messages.Add(smsg); } catch (Exception ex) { _log.Warn(ex); } } } //order the messages by time so we send the data to the broker in the right order var orderedmessages = messages.OrderBy(x => x.TimeStamp).ToList(); foreach (var message in orderedmessages) { ProcessMessage(message); DeleteMessage(message); } } catch (Exception ex) { _log.Error(ex); } }
public override void Run() { UpdateHealth(); //Amazon.Util.ProfileManager.RegisterProfile("TeamsupportAWS", SystemSettings.ReadString("AWS-Key", ""), SystemSettings.ReadString("AWS-Password", "")); Amazon.Util.ProfileManager.RegisterProfile("TeamsupportAWS", "AKIAJHKO22YGQ6N7MAEA", "aEZUTAv6yp2aQdNN4yxv+PJbE/H++bvt33E9IJvd"); AmazonSQSConfig amazonSQSConfig = new AmazonSQSConfig(); amazonSQSConfig.ServiceURL = "https://sqs.us-east-1.amazonaws.com/"; var sqs = new AmazonSQSClient(amazonSQSConfig); try { var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = "https://sqs.us-east-1.amazonaws.com/168534988511/tsTranscoding-dev" }; var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages != null) { foreach (var message in receiveMessageResponse.Messages) { if (!string.IsNullOrEmpty(message.Body)) { JObject o = JObject.Parse(message.Body); string key = HttpUtility.UrlDecode((string)o["Records"][0]["s3"]["object"]["key"]); string bucket = (string)o["Records"][0]["s3"]["bucket"]["name"]; string path = String.Format("https://s3.amazonaws.com/{0}/{1}", bucket, key); Logs.WriteEvent(path); InitSettings(path); using (_client = new AmazonS3Client()) { DownLoadZip(); ExtractZip($@"{_downloadLocation}/{_s3Path}"); MergeVideoFiles(); UploadHighResVideo(); CleanUpFiles(); } var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle; //Deleting a message Console.WriteLine("Deleting the message.\n"); var deleteRequest = new DeleteMessageRequest { QueueUrl = "https://sqs.us-east-1.amazonaws.com/168534988511/tsTranscoding-dev", ReceiptHandle = messageRecieptHandle }; sqs.DeleteMessage(deleteRequest); UpdateHealth(); } } } } catch (Exception ex) { } }
public static void Main(string[] args) { // SQSClient from AWSSDK var amazonSqsClient = new AmazonSQSClient(); // FIFO quene URL string myQueueUrl = "https://sqs.us-west-2.amazonaws.com/781160412246/ecfe.fifo"; try { // Send 3 messages to FIFO queue for (var i = 0; i < 3; i++) { // Read message from FIFO queue var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = myQueueUrl }; var receiveMessageResponse = amazonSqsClient.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages != null) { var message = receiveMessageResponse.Messages[0]; if (!string.IsNullOrEmpty(message.Body)) { Console.WriteLine("Read message: {0}", message.Body); } // Delete message from FIFO queue var messageRecieptHandle = message.ReceiptHandle; var deleteMessageRequest = new DeleteMessageRequest { QueueUrl = myQueueUrl, ReceiptHandle = messageRecieptHandle }; amazonSqsClient.DeleteMessage(deleteMessageRequest); Console.WriteLine("Delete message: {0}", message.Body); } } } 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(); }
private Message ReadMessageFromQueue() { var request = new ReceiveMessageRequest() .WithQueueUrl(_uri) .WithMaxNumberOfMessages(1); var response = _client.ReceiveMessage(request); var message = response.ReceiveMessageResult.Message.FirstOrDefault(); return(message); }
public Message Listen() { var response = _client.ReceiveMessage(_queueUrl); if (!response.Messages.Any()) { return(null); } return(response.Messages.First()); }