示例#1
0
        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;
        }
示例#2
0
        private async Task StreamToConsole(CancellationToken token)
        {
            var linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            var eventSource = new KSpiceUaSource(GetPlantCode(), GetSourceConnectionString());
            var eventTarget = new ConsoleTarget();

            eventSource.LinkTo(eventTarget, linkOptions);
            eventSource.StartListening();

            while (!token.IsCancellationRequested)
            {
                await Task.Delay(3000, token);
            }

            eventSource.StopListening();
            eventSource.Complete();

            await eventTarget.Completion;
        }