private async Task ProcessMessageAsync(RestoreMessage restoreMessage) { var currentDate = restoreMessage.FromDate.ToUniversalTime(); var to = restoreMessage.ToDate.ToUniversalTime(); var bindings = await _rabbitService.GetAllBindingsAsync(); var exchangeBindings = bindings[restoreMessage.ExchangeName] .Where(x => x.DestinationType == "queue") .ToList(); while (currentDate.Date <= to.Date) { string continuationToken = null; do { var result = await _rabbitService.RestoreMessageAsync(restoreMessage.ExchangeName, currentDate, 100, continuationToken); var factory = new ConnectionFactory() { Uri = _connectionString, }; foreach (var binding in exchangeBindings) { using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { foreach (var message in result.Messages) { //channel.QueueDeclare(queue: "hello", // durable: false, // exclusive: false, // autoDelete: false, // arguments: null); var body = _messageSerializer.Serialize(message.Payload); channel.BasicPublish(exchange: "", routingKey: binding.Destination, basicProperties: null, body: body); } } continuationToken = result.ContinuationToken; } currentDate = currentDate.AddDays(1.0); } while (!string.IsNullOrEmpty(continuationToken)); } }