< Summary

Class:Azure.Messaging.EventHubs.Processor.Samples.Sample02_ProcessorWithCustomOptions
Assembly:Azure.Messaging.EventHubs.Processor.Samples
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Processor\samples\Sample02_ProcessorWithCustomOptions.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:110
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Name()-0%100%
get_Description()-0%100%
RunAsync()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Processor\samples\Sample02_ProcessorWithCustomOptions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Net;
 6using System.Threading.Tasks;
 7using Azure.Messaging.EventHubs.Consumer;
 8using Azure.Messaging.EventHubs.Processor.Samples.Infrastructure;
 9using Azure.Storage.Blobs;
 10
 11namespace Azure.Messaging.EventHubs.Processor.Samples
 12{
 13    /// <summary>
 14    ///   An introduction to the Event Processor client, exploring additional options for creating the
 15    ///   processor.
 16    /// </summary>
 17    ///
 18    public class Sample02_ProcessorWithCustomOptions : IEventHubsBlobCheckpointSample
 19    {
 20        /// <summary>
 21        ///   The name of the sample.
 22        /// </summary>
 23        ///
 024        public string Name => nameof(Sample02_ProcessorWithCustomOptions);
 25
 26        /// <summary>
 27        ///   A short description of the sample.
 28        /// </summary>
 29        ///
 030        public string Description => "An introduction to the Event Processor client, exploring additional options for cr
 31
 32        /// <summary>
 33        ///   Runs the sample using the specified Event Hubs and Azure storage connection information.
 34        /// </summary>
 35        ///
 36        /// <param name="eventHubsConnectionString">The connection string for the Event Hubs namespace that the sample s
 37        /// <param name="eventHubName">The name of the Event Hub, sometimes known as its path, that the sample should ru
 38        /// <param name="blobStorageConnectionString">The connection string for the storage account where checkpoints an
 39        /// <param name="blobContainerName">The name of the blob storage container where checkpoints and state should be
 40        ///
 41        public async Task RunAsync(string eventHubsConnectionString,
 42                                   string eventHubName,
 43                                   string blobStorageConnectionString,
 44                                   string blobContainerName)
 45        {
 46            // The Event Processor client offers additional options on creation, allowing you to control different aspec
 47            // should your scenario have needs that differ from the common defaults.  If you choose not to provide these
 48            // suitable to most scenarios are used.
 49            //
 50            // The processor allows you to customize how it interacts with the Event Hubs service, such as by influencin
 51            // to the service by specifying the transport that communication should use and whether a proxy should be us
 52            // note that a proxy is only supported when using WebSockets as a transport; it isn't compatible with raw TC
 53            //
 54            // This sample will customize the transport for the connection, using WebSockets and will adjust some of the
 55            // illustration.
 56
 057            string consumerGroup = EventHubConsumerClient.DefaultConsumerGroupName;
 058            BlobContainerClient storageClient = new BlobContainerClient(blobStorageConnectionString, blobContainerName);
 59
 060            var processorOptions = new EventProcessorClientOptions
 061            {
 062                ConnectionOptions = new EventHubConnectionOptions
 063                {
 064                    TransportType = EventHubsTransportType.AmqpWebSockets,
 065                    Proxy = (IWebProxy)null
 066                },
 067
 068                RetryOptions = new EventHubsRetryOptions
 069                {
 070                    MaximumRetries = 5,
 071                    TryTimeout = TimeSpan.FromMinutes(1)
 072                }
 073            };
 74
 075            EventProcessorClient processor = new EventProcessorClient(storageClient, consumerGroup, eventHubsConnectionS
 76
 77            // Once the client has been created, it may be used normally.  For completeness, we'll
 78            // mirror the minimal skeleton from our first sample, starting and stopping the processor
 79            // without performing any processing.
 80
 081            Task processEventHandler(ProcessEventArgs eventArgs) => Task.CompletedTask;
 082            Task processErrorHandler(ProcessErrorEventArgs eventArgs) => Task.CompletedTask;
 83
 084            processor.ProcessEventAsync += processEventHandler;
 085            processor.ProcessErrorAsync += processErrorHandler;
 86
 87            try
 88            {
 089                await processor.StartProcessingAsync();
 090                await Task.Delay(TimeSpan.FromSeconds(1));
 091                await processor.StopProcessingAsync();
 092            }
 93            finally
 94            {
 95                // It is encouraged that you unregister your handlers when you have finished
 96                // using the Event Processor to ensure proper cleanup.  This is especially
 97                // important when using lambda expressions or handlers in any form that may
 98                // contain closure scopes or hold other references.
 99
 0100                processor.ProcessEventAsync -= processEventHandler;
 0101                processor.ProcessErrorAsync -= processErrorHandler;
 102            }
 103
 104            // The Event Processor client has been stopped and is not explicitly disposable; there
 105            // is nothing further that we need to do for cleanup.
 106
 0107            Console.WriteLine();
 0108        }
 109    }
 110}