private void LoadFromPersistentStorage(CloudTable table) { TableContinuationToken?token = null; var entities = new List <DynamicTableEntity>(); do { var queryResult = table.ExecuteQuerySegmented(new TableQuery(), token); entities.AddRange(queryResult.Results); token = queryResult.ContinuationToken; } while (token != null); foreach (var item in entities) { var vehicleJourneyAssignment = item.ToVehicleJourneyAssignment(); vehicleJourneyAssignmentCache.Put(vehicleJourneyAssignment); } }
protected override async Task Work(CancellationToken cancellationToken) { logger.LogInformation($"Connecting to RabbitMQ: {rabbitConnectionFactory.Uri}"); rabbitConnection = rabbitConnectionFactory.CreateConnection(nameof(VehicleJourneyAssignmentLoaderWorker)); rabbitChannel = rabbitConnection.CreateModel(); // The incomming exchange of ROI events. var roiExchange = config.GetValue <string>("RabbitMQ:RoiExchange", "roi-json"); // The work queue is a per worker queue to distribute vehicle assignments. var workQueue = config.GetValue("RabbitMQ:RoiWorkQueue", "rpsudp2json-roi-json-{machineName}").Replace("{machineName}", Environment.MachineName.ToLower()); var arguments = new Dictionary <string, object> { { "x-message-ttl", 3 * 60 * 60 * 1000 } // 3 hours }; rabbitChannel.QueueDeclare(workQueue, durable: false, exclusive: true, autoDelete: true, arguments); rabbitChannel.QueueBind(workQueue, roiExchange, "vehicleJourneyAssignment.#"); var workerVehicleJourneyAssignmentConsumer = new EventConsumer <VehicleJourneyAssignmentEvent>( action: e => { vehicleJourneyAssignmentCache.Put(e.VehicleJourneyAssignment); ResetWatchdog(); }, eventType: "vehicleJourneyAssignment", logger: logger); // TODO: Wait for initial load to complete in PersistentVehicleJourneyAssignmentWorker logger.LogInformation($"Beginning to consume {workQueue}..."); rabbitChannel.BasicConsume( queue: workQueue, autoAck: true, consumer: workerVehicleJourneyAssignmentConsumer); await cancellationToken.WaitHandle.WaitOneAsync(CancellationToken.None); }