2019-10-16 11:54:43 +00:00
|
|
|
|
using RabbitMQ.Client;
|
|
|
|
|
using Tapeti.Cmd.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Cmd.Commands
|
|
|
|
|
{
|
|
|
|
|
public class ImportCommand
|
|
|
|
|
{
|
|
|
|
|
public IMessageSerializer MessageSerializer { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool DirectToQueue { get; set; }
|
|
|
|
|
|
|
|
|
|
|
2019-10-16 12:49:23 +00:00
|
|
|
|
public int Execute(IModel channel)
|
2019-10-16 11:54:43 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|