Var attributes = await _sqsClient.GetQueueAttributesAsync(new GetQueueAttributesRequest Get the the ARN of dead letter queue and configure main queue to deliver messages to it Var createDeadLetterQueueResponse = await _sqsClient.CreateQueueAsync(createQueueRequest) Var createQueueResponse = await _sqsClient.CreateQueueAsync(createQueueRequest) ĬreateQueueRequest.QueueName = _appConfig.AwsDeadLetterQueueName Var createQueueRequest = new CreateQueueRequest() Ĭ("FifoQueue", "true") ĬreateQueueRequest.QueueName = _appConfig.AwsQueueName Basically SQS waits until a message is available in a queue before sending a response. The code snippet also enables long polling for the queue, which allows reducing costs while allowing consumers to receive messages as soon as they arrive in the queue. Once the client is in place, then the queue and dead-letter queue is created with the code below. Another option is to create them from the AWS CLI, see more information in AWS examples in C# – deploy with AWS CLI commands post. Queues can be created programmatically, something that will be described in the current post. _queueUrlCache = new ConcurrentDictionary() Private readonly ConcurrentDictionary _queueUrlCache They are injected into the constructor by. This sample code shows what external dependencies the SqsClient class needs. Var configurationBuilder = new ConfigurationBuilder() I use the AwsCredentials class which extends the AWS’ abstract AWSCredentials in order to manage the credentials. The concrete AWS client implementation is AmazonSQSClient and a singleton object is instantiated in SqsClientFactory class, where RegionEndpoint is used to instantiate AmazonSQSConfig. The NuGet package is called AWSSDK.SQS, which in the current example comes as a sub-reference from NuGet package. The SQS client interface is called IAmazonSQS and comes from AWS C# SDK. In order to work with SQS, a client is needed. Its values are injected from the environment variables by. In the current examples, I use a configuration class called AppConfig. In the current post, I will put in practice example basic SQS operations, a more detailed description of their usage is available in AWS examples in C# – create a service working with SQS post. The code used for this series of blog posts is located in GitHub repository. This post is part of AWS examples in C# – working with SQS, DynamoDB, Lambda, ECS series. Post summary: Code examples of how to perform basic SQS queue operations like reading, writing, deleting, creating a queue, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |