I have EventBridge pushing messages to SQS, and also SQS messages being consumed by a background process.
In background process, I am using following piece of code (executed with 1s delay):
var receiveMessageRequest = new ReceiveMessageRequest()
{
QueueUrl = await GetQueueUrl(),
WaitTimeSeconds = 0, // this is problematic line
MaxNumberOfMessages = 1
};
var response = await _sqsClient.ReceiveMessageAsync(receiveMessageRequest);
The scenario is that I'm sending 1 messages to EventBridge and it is routed to SQS.
If I poll the queue with WaitTimeSeconds = 0
sometimes the message is received after 20-40 seconds (which oddly corresponds to SQS's Default visibility timeout = 30
, not sure though).
If however, I am calling this function with WaitTimeSeconds = 1
then it works as expected, meaning message is received fast.
My crazy hypothesis is: it looks like if there is 1 message in a queue, and short polling is used, it is not visible for some reason.