I have a .Net Lambda function which sends messages to an SQS queue.
I’d like to be able to “fire and forget” those messages ... i.e. I don't want to "await" a response. However, AWS’ SQS client only provides Async methods (e.g. SendMessageAsync). And if I don’t “await” this call, then the messages never arrive in the queue.
I’ve not been able to find much on this topic. I see plenty of SQS examples online which use “SendMessage” but my assumption is that code was written using version 2.5 (or earlier) of the AWS SDK (several actually await SendMessage). The newer versions don’t have the non-Async versions of the methods.
I did find a similar StackOverflow question (QqsClient.SendMessageAsync without await doesn't work) but its asking how to await the sending of multiple messages whereas I’m looking to avoid awaiting at all.
This code will send a message:
using Amazon.SQS;
public class SQSHelper
{
private AmazonSQSClient client = new AmazonSQSClient(Amazon.RegionEndpoint.USEast2);
public async Task<string> SendMessage(string queue, string message)
{
var response = await client.SendMessageAsync(queue, message);
}
}
But this code will not
using Amazon.SQS;
public class SQSHelper
{
private AmazonSQSClient client = new AmazonSQSClient(Amazon.RegionEndpoint.USEast2);
public void SendMessage(string queue, string message)
{
client.SendMessageAsync(queue, message);
}
}
Is it possible to send SQS messages without waiting for the response?
Is it possible to send SQS messages without waiting for the response?
Whenever you execute a web service call, you should know the result (success, exception) and handle that result appropriately. Why would you want to just ignore the result? – vasek