Files
knightcrawler/src/producer/Services/TorrentPublisher.cs
iPromKnight 68edaba308 Introduce max batch size, and configurable publish window
Still need to implement queue size limit
Also fixes env var consistency between addon and consumer
2024-02-02 13:49:54 +00:00

22 lines
861 B
C#

namespace Producer.Services;
public class TorrentPublisher(ISendEndpointProvider sendEndpointProvider, RabbitMqConfiguration configuration) : IMessagePublisher
{
public async Task PublishAsync(IEnumerable<Torrent> torrents, CancellationToken cancellationToken = default)
{
var queueAddress = ConstructQueue();
var sendEndpoint = await sendEndpointProvider.GetSendEndpoint(new(queueAddress));
await sendEndpoint.SendBatch(torrents, cancellationToken: cancellationToken);
}
private string ConstructQueue()
{
var queueBuilder = new StringBuilder();
queueBuilder.Append("queue:");
queueBuilder.Append(configuration.QueueName);
queueBuilder.Append("?durable=");
queueBuilder.Append(configuration.Durable ? "true" : "false");
return queueBuilder.ToString();
}
}