-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueController.cs
50 lines (44 loc) · 1.52 KB
/
QueueController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Amazon.SQS;
using Amazon.SQS.Model;
using ConsumerQueue.DTO;
using Microsoft.AspNetCore.Mvc;
using ProcessQueue.DTO;
using System.Text.Json;
namespace ConsumerQueue.Controllers
{
[ApiController]
[Route("queue")]
public class QueueController : ControllerBase
{
private readonly MessageProcessedDTO _messageProcessedDTO;
private readonly AwsSettingsDTO _awsSettings;
private readonly AmazonSQSClient _sqsClient;
public QueueController(MessageProcessedDTO messageProcessedDTO, AwsSettingsDTO awsSettings)
{
_messageProcessedDTO = messageProcessedDTO;
_awsSettings = awsSettings;
var awsCredentials = new AmazonSQSConfig
{
ServiceURL = _awsSettings.ServerEndpoint
};
_sqsClient = new AmazonSQSClient(awsCredentials);
}
[HttpPost]
public async Task<IActionResult> AddMessage([FromQuery] bool toDeadLetter)
{
var content = new MessageDTO { PublishedAt = DateTime.Now, ToDeadLetter = toDeadLetter };
var messageRequest = new SendMessageRequest()
{
MessageBody = JsonSerializer.Serialize(content),
QueueUrl = $"{_awsSettings.QueueEndpoint}/queue"
};
await _sqsClient.SendMessageAsync(messageRequest);
return Ok();
}
[HttpGet]
public IActionResult GetMessagesProcessed()
{
return Ok(_messageProcessedDTO);
}
}
}