private static async Task <List <string> > GetQiStreamsAsync() { string qiNamespaceName = ConfigurationManager.AppSettings["QiNamespace"]; string qiQuery = ConfigurationManager.AppSettings["QiStreamFilter"]; QiClientSlim qiClient = new QiClientSlim(); return(await qiClient.GetQiStreamsAsync(qiNamespaceName, qiQuery)); }
private static async Task <Task> GetAndSendAsync(QiClientSlim qiClient, string namespaceId, string streamId, SimplePublisher busWriter, TraceWriter log = null) { string snapshotJson = await qiClient.GetLatestValueJsonAsync(namespaceId, streamId).ConfigureAwait(false); if (snapshotJson == null) { return(Task.CompletedTask); } string identifiedSnapshotJson = $"{{ streamId: \"{streamId}\", values: {snapshotJson} }}"; return(busWriter.PublishAsync(identifiedSnapshotJson)); }
public static async Task Run([ServiceBusTrigger("qillion", AccessRights.Manage, Connection = "QillionTriggerBus")] BatchEntity batchEntity, TraceWriter log, Microsoft.Azure.WebJobs.ExecutionContext context) { log.Info($"Qi stream batch worker processing batch {batchEntity.id}"); BindingRedirector.RedirectAssembly("Google.Apis.Auth", new Version("1.28.0.0"), "4b01fa6e34db77ab"); BindingRedirector.RedirectAssembly("Google.Apis.Auth.PlatformServices", new Version("1.28.0.0"), "4b01fa6e34db77ab"); QiStreamBatchRepository repository = new QiStreamBatchRepository(); List <string> streamIds = await repository.GetStreamsInBatch(batchEntity.id); string qiNamespace = ConfigurationManager.AppSettings["QiNamespace"]; QiClientSlim qiClient = new QiClientSlim(); await GetAndSendSnapshotsAsync(qiNamespace, streamIds, qiClient, context, log); }
private static async Task GetAndSendSnapshotsAsync(string namespaceId, List <string> streamIds, QiClientSlim qiClient, Microsoft.Azure.WebJobs.ExecutionContext context, TraceWriter log = null) { SimplePublisher busWriter = GetGoogleBusWriter(context); List <Task <Task> > snapshotTasks = new List <Task <Task> >(streamIds.Count); foreach (string streamId in streamIds) { string streamIdCopy = streamId; Task <Task> snapshotTask = GetAndSendAsync(qiClient, namespaceId, streamIdCopy, busWriter, log); snapshotTasks.Add(snapshotTask); } await Task.WhenAll(snapshotTasks); //Wait until messages are flushed from the bus await busWriter.ShutdownAsync(CancellationToken.None); var publishingTasks = snapshotTasks.Select(outerTask => outerTask.Result); await Task.WhenAll(publishingTasks); }