1
0
mirror of synced 2024-11-05 02:59:16 +00:00
Tapeti/Tapeti.Cmd/Commands/ImportCommand.cs
Mark van Renswoude 34da354fc2 Start of Tapeti.Cmd [ci skip]
Support for basic queue to/from disk operations
2019-10-16 13:54:43 +02:00

43 lines
1.1 KiB
C#

using RabbitMQ.Client;
using Tapeti.Cmd.Serialization;
namespace Tapeti.Cmd.Commands
{
public class ImportCommand
{
public ConnectionFactory ConnectionFactory { get; set; }
public IMessageSerializer MessageSerializer { get; set; }
public bool DirectToQueue { get; set; }
public int Execute()
{
using (var connection = ConnectionFactory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
return PublishMessages(channel);
}
}
}
private int PublishMessages(IModel channel)
{
var messageCount = 0;
foreach (var message in MessageSerializer.Deserialize())
{
var exchange = DirectToQueue ? "" : message.Exchange;
var routingKey = DirectToQueue ? message.Queue : message.RoutingKey;
channel.BasicPublish(exchange, routingKey, message.Properties, message.Body);
messageCount++;
}
return messageCount;
}
}
}