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)); } }
public IList <T> Process() { var sqs = new AmazonSQSClient(_credentails.Key, _credentails.Secret, _credentails.RegionEndpoint); var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = _queueUrl, MaxNumberOfMessages = 10, WaitTimeSeconds = 1 }; var response = sqs.ReceiveMessageAsync(receiveMessageRequest); if (!response.Result.Messages.Any()) { return(_list); } foreach (var message in response.Result.Messages) { var request = JsonConvert.DeserializeObject <T>(message.Body); sqs.DeleteMessage(new DeleteMessageRequest { ReceiptHandle = message.ReceiptHandle, QueueUrl = _queueUrl }); _list.Add(request); } return(_list); }
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); } } } }
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); }
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); }
public void DeleteMessages(AmazonSQSClient client, string Url, ReceiveMessageResponse response) { if (response.Messages.Count > 0) { foreach (var responseMsg in response.Messages) { Console.WriteLine("---Recieved Message ID ---- " + responseMsg.MessageId); Console.WriteLine("---Recieved Message body ---- " + responseMsg.Body); Console.WriteLine("---Recieved receipt handle---- " + responseMsg.ReceiptHandle); Console.WriteLine("---Recieved message attributes---- " + responseMsg.MD5OfMessageAttributes); foreach (var attr in responseMsg.Attributes) { Console.WriteLine(" Attribute " + attr.Key + ": " + attr.Value); } var deleteReg = new DeleteMessageRequest { QueueUrl = Url, ReceiptHandle = responseMsg.ReceiptHandle }; var VerifytDel = client.DeleteMessage(deleteReg); Console.WriteLine("Deleted Message successfully " + VerifytDel.HttpStatusCode.ToString()); } } else { Console.WriteLine("No message recieved"); } }
private bool DeleteMessageFromQueue(string receiptHandle) { var deleteRequest = new DeleteMessageRequest(QueueUrl, receiptHandle); var response = _sqsClient.DeleteMessage(deleteRequest); return(response.HttpStatusCode == HttpStatusCode.OK); }
private bool DeleteMessageFromQueue(string msgReceiptHandle) { DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(); if (useFIFOQueue == true) { deleteMessageRequest.QueueUrl = Configurations.FIFOQueueURL; } else { deleteMessageRequest.QueueUrl = Configurations.QueueURL; } deleteMessageRequest.ReceiptHandle = msgReceiptHandle; DeleteMessageResponse response = sqsClient.DeleteMessage(deleteMessageRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(true); } return(false); }
public static void DeleteMessage(AmazonSQSClient sqsClient, string queueUrl, Message message) { Debug.WriteLine(String.Format("RUNNING SOLUTION CODE: {0}! Follow the steps in the lab guide to replace this method with your own implementation.\n", "DeleteMessage")); string messageReceiptHandle = message.ReceiptHandle; sqsClient.DeleteMessage(queueUrl, messageReceiptHandle); }
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; } } }
/// <summary> /// Rejects the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="requeue">if set to <c>true</c> [requeue].</param> public void Reject(Message message, bool requeue) { if (!message.Header.Bag.ContainsKey("ReceiptHandle")) { return; } var receiptHandle = message.Header.Bag["ReceiptHandle"].ToString(); try { _logger.InfoFormat("SqsMessageConsumer: Rejecting the message {0} with receipt handle {1} on the queue {2} with requeue paramter {3}", message.Id, receiptHandle, _queueUrl, requeue); using (var client = new AmazonSQSClient()) { if (requeue) { client.ChangeMessageVisibility(new ChangeMessageVisibilityRequest(_queueUrl, receiptHandle, 0)); } else { client.DeleteMessage(_queueUrl, receiptHandle); } } _logger.InfoFormat("SqsMessageConsumer: Message {0} with receipt handle {1} on the queue {2} with requeue paramter {3} has been rejected", message.Id, receiptHandle, _queueUrl, requeue); } catch (Exception exception) { _logger.ErrorException("SqsMessageConsumer: Error during rejecting the message {0} with receipt handle {1} on the queue {2}", exception, message.Id, receiptHandle, _queueUrl); throw; } }
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); }); }
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") },
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 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); } }
private DeleteMessageResponse DeleteMessage(string receiptHandle) { var request = new DeleteMessageRequest(); request.QueueUrl = QueueUrl; request.ReceiptHandle = receiptHandle; return(_sqsClient.DeleteMessage(request)); }
void deleteMessage(string receiptHandle) { var deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.QueueUrl = queueUrl; deleteMessageRequest.ReceiptHandle = receiptHandle; client.DeleteMessage(deleteMessageRequest); }
public void Accept() { var request = new DeleteMessageRequest() .WithQueueUrl(_uri) .WithReceiptHandle(_message.ReceiptHandle); _client.DeleteMessage(request); }
static void deleteMessageFromQueue(AmazonSQSClient sqsClient, string queueUrl, string recieptHandle) { var deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.QueueUrl = queueUrl; deleteMessageRequest.ReceiptHandle = recieptHandle; sqsClient.DeleteMessage(deleteMessageRequest); }
/** * Delete the message from the queue * * @param queueUrl URL * @param message Message */ private static void DeleteMessage(string queueUrl, Message message) { // TODO 11: Replace the solution with your own code Debug.WriteLine(String.Format("RUNNING JAYARAJ'S CODE: {0}!\n", "DeleteMessage")); string messageReceiptHandle = message.ReceiptHandle; sqsClient.DeleteMessage(queueUrl, messageReceiptHandle); }
/// <summary> /// Delete a message from the message queue once we have processed it /// </summary> /// <param name="message"></param> private void DeleteMessage(SigfoxMessage message) { var deleteMessageRequest = new DeleteMessageRequest { QueueUrl = _queueUrl, ReceiptHandle = message.RecieptHandle }; var response = _sqsClient.DeleteMessage(deleteMessageRequest); }
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()); }
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 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 void DeleteMessge(Amazon.SQS.Model.Message message) { DeleteMessageResponse objDeleteMessageResponse = new DeleteMessageResponse(); var deleteMessageRequest = new DeleteMessageRequest() { QueueUrl = sellerInfo.QueueUrl, ReceiptHandle = message.ReceiptHandle }; objDeleteMessageResponse = sqsClient.DeleteMessage(deleteMessageRequest); nLogger.Log(LogLevel.Info, string.Format("Message deleted: {0}", message.MessageId)); }
public virtual void RemoveMessage(AmazonSQSClient sqsClient, string queueUrl, string receiptHandle) { // Create the request var deleteMessageRequest = new DeleteMessageRequest { ReceiptHandle = receiptHandle, QueueUrl = queueUrl }; // Submit the request sqsClient.DeleteMessage(deleteMessageRequest); }
private void Handle(sqs.Message sqsMessage, Action <Message> onMessageReceived) { var message = Message.FromJson(sqsMessage.Body); onMessageReceived(message); var deleteRequest = new DeleteMessageRequest(); deleteRequest.QueueUrl = Address; deleteRequest.ReceiptHandle = sqsMessage.ReceiptHandle; _sqsClient.DeleteMessage(deleteRequest); }
private static async Task ReceiveMessage(int state) { //Receiving a message var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = _myQueueUrl }; var receiveMessageResponse = await _sqs.ReceiveMessageAsync(receiveMessageRequest); if (receiveMessageResponse.Messages != null) { Console.WriteLine($"Receiever {state} Printing received message.\n"); foreach (var message in receiveMessageResponse.Messages) { Console.WriteLine($"Receiever {state} Message"); if (!string.IsNullOrEmpty(message.MessageId)) { Console.WriteLine($"Receiever {state} MessageId: {message.MessageId}"); } if (!string.IsNullOrEmpty(message.ReceiptHandle)) { Console.WriteLine($"Receiever {state} ReceiptHandle: {message.ReceiptHandle}"); } if (!string.IsNullOrEmpty(message.MD5OfBody)) { Console.WriteLine($"Receiever {state} MD5OfBody: {message.MD5OfBody}"); } if (!string.IsNullOrEmpty(message.Body)) { Console.WriteLine($"Receiever {state} Body: {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; if (_receieverShouldDeleteMessage) { //Deleting a message Console.WriteLine("Deleting the message.\n"); var deleteRequest = new DeleteMessageRequest { QueueUrl = _myQueueUrl, ReceiptHandle = messageRecieptHandle }; _sqs.DeleteMessage(deleteRequest); } } }
public void DeleteMessage() { DeleteMessageRequest request = new DeleteMessageRequest { QueueUrl = QueueUrl, ReceiptHandle = ReceiptHandle }; var response = client.DeleteMessage(request); if (response.HttpStatusCode.IsSuccess()) { Console.WriteLine("Message Deleted Succsessfully"); } }