public int Execute(IModel sourceChannel, IModel targetChannel, IRateLimiter rateLimiter) { var messageCount = 0; while (!MaxCount.HasValue || messageCount < MaxCount.Value) { var result = sourceChannel.BasicGet(QueueName, false); if (result == null) { // No more messages on the queue break; } rateLimiter.Execute(() => { targetChannel.BasicPublish("", TargetQueueName, result.BasicProperties, result.Body); messageCount++; if (RemoveMessages) { sourceChannel.BasicAck(result.DeliveryTag, false); } }); } return(messageCount); }
public int Execute(IModel channel, IRateLimiter rateLimiter) { var messageCount = 0; foreach (var message in MessageSerializer.Deserialize(channel)) { rateLimiter.Execute(() => { var exchange = DirectToQueue ? "" : message.Exchange; var routingKey = DirectToQueue ? message.Queue : message.RoutingKey; channel.BasicPublish(exchange, routingKey, message.Properties, message.Body); messageCount++; }); } return(messageCount); }