mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 16:18:57 +00:00
35 lines
865 B
C#
35 lines
865 B
C#
|
|
using System.Text.Json;
|
||
|
|
using Amazon.SQS;
|
||
|
|
using Amazon.SQS.Model;
|
||
|
|
using ProposalSystem.Application.Interfaces;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Infrastructure.Services;
|
||
|
|
|
||
|
|
public class SqsJobPublisher : IJobPublisher
|
||
|
|
{
|
||
|
|
private readonly IAmazonSQS _sqsClient;
|
||
|
|
private readonly string _queueUrl;
|
||
|
|
|
||
|
|
public SqsJobPublisher(IAmazonSQS sqsClient, string queueUrl)
|
||
|
|
{
|
||
|
|
_sqsClient = sqsClient;
|
||
|
|
_queueUrl = queueUrl;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task PublishAsync(string jobType, object payload, CancellationToken ct = default)
|
||
|
|
{
|
||
|
|
var message = new
|
||
|
|
{
|
||
|
|
jobType,
|
||
|
|
payload,
|
||
|
|
timestamp = DateTime.UtcNow,
|
||
|
|
};
|
||
|
|
|
||
|
|
await _sqsClient.SendMessageAsync(new SendMessageRequest
|
||
|
|
{
|
||
|
|
QueueUrl = _queueUrl,
|
||
|
|
MessageBody = JsonSerializer.Serialize(message),
|
||
|
|
}, ct);
|
||
|
|
}
|
||
|
|
}
|