示例#1
0
        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));
            }
        }
示例#2
0
        //throws InterruptedException
        public void processRestoreMessage(RestoreMessage msg)
        {
            if (msg is RestoreIncentive
                || msg is RestoreTableList
                || msg is RestoreTable)
            {
                Logger.getInstance().log(
                        "Dispatching to restore cohort: " + msg.toString(),
                        LOGGING_NAME,
                        Logger.Level.INFO);

                restoreCohort.putMessage(msg);
            }
            else
            {
                IPEndPoint node = msg.getSender();
                RestoreCoordinator coordinator = null;
                if (restoreCoordinators.ContainsKey(node))
                {
                    coordinator = restoreCoordinators[node];
                }
                if (coordinator != null)
                {
                    Logger.getInstance().log(
                            "Dispatching to restore coordinator for node - " + node.ToString() + " : " + msg.ToString(),
                            LOGGING_NAME,
                            Logger.Level.INFO);

                    coordinator.putMessage(msg);
                }
                else
                {
                    Logger.getInstance().log(
                            "No restore coordinator for node " + node.ToString(),
                            LOGGING_NAME,
                            Logger.Level.WARNING);
                }
            }
        }
示例#3
0
 public async Task PublishAsync(RestoreMessage message)
 {
     await _publisher.ProduceAsync(message);
 }
示例#4
0
 public void Handle(RestoreMessage message)
 {
     LoadCommand.Execute(null);
 }