I'm setting up bounce, complaint, and delivery notifications for Amazon SES using their SQS Queue Service.
The documentation recommends that when polling multiple SQS queues, to do it on multiple threads. This is especially true when using long-polling since long-polling multiple queues on one thread could cause the queue being polled to delay new messages from different queues.
So if I want to poll 3 SQS queues in my ASP.NET MVC application, should I just spawn barebones threads like this:
Thread bouncesThread = new Thread(() =>
{
IAmazonSQS sqsClient = AWSClientFactory.CreateAmazonSQSClient(RegionEndpoint.USWest2);
while(true)
{
//this will long-poll
ReceiveMessageResponse receiveMessageResponse = sqsClient.ReceiveMessage(bouncesQueueRequest);
ProcessQueuedBounce(receiveMessageResponse);
}
});
bouncesThread.SetApartmentState(ApartmentState.STA);
bouncesThread.Start();
Or is there a better way to do this, since this is a long running process and should run for the length of the application? Should I use IRegisteredObject
?
Whats the recommended way to do this?