private async Task StreamToEventHub(CancellationToken token) { var linkOptions = new DataflowLinkOptions { PropagateCompletion = true }; var eventSource = new KSpiceUaSource(GetPlantCode(), GetSourceConnectionString()); var batchEvents = Transformations.BatchEvents(); var eventTarget = new EventHubTarget(GetEventHubConnectionString(), GetEventHubPublishParallelism()); eventSource.LinkTo(batchEvents, linkOptions); batchEvents.LinkTo(eventTarget, linkOptions); eventSource.StartListening(); while (!token.IsCancellationRequested) { await Task.Delay(3000, token); } eventSource.StopListening(); eventSource.Complete(); await batchEvents.Completion; await eventTarget.Completion; }