< Summary

Class:Azure.Messaging.EventHubs.Samples.Sample02_ClientWithCustomOptions
Assembly:Azure.Messaging.EventHubs.Samples
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\samples\Sample02_ClientWithCustomOptions.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:95
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs\samples\Sample02_ClientWithCustomOptions.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.Producer;
 8using Azure.Messaging.EventHubs.Samples.Infrastructure;
 9
 10namespace Azure.Messaging.EventHubs.Samples
 11{
 12    /// <summary>
 13    ///   An introduction to Event Hubs, exploring additional options for creating the
 14    ///   different Event Hub clients.
 15    /// </summary>
 16    ///
 17    public class Sample02_ClientWithCustomOptions : IEventHubsSample
 18    {
 19        /// <summary>
 20        ///   The name of the sample.
 21        /// </summary>
 22        ///
 023        public string Name => nameof(Sample02_ClientWithCustomOptions);
 24
 25        /// <summary>
 26        ///   A short description of the sample.
 27        /// </summary>
 28        ///
 029        public string Description => "An introduction to Event Hubs, exploring additional options for creating the diffe
 30
 31        /// <summary>
 32        ///   Runs the sample using the specified Event Hubs connection information.
 33        /// </summary>
 34        ///
 35        /// <param name="connectionString">The connection string for the Event Hubs namespace that the sample should tar
 36        /// <param name="eventHubName">The name of the Event Hub, sometimes known as its path, that she sample should ru
 37        ///
 38        public async Task RunAsync(string connectionString,
 39                                   string eventHubName)
 40        {
 41            // The clients for an Event Hub client each offer additional options on creation, allowing you to control di
 42            // should your scenario have needs that differ from the common defaults.  If you choose not to provide these
 43            // suitable to most scenarios are used.
 44            //
 45            // Each different Event Hub client allows you to customize how it interacts with the Event Hubs service, suc
 46            // to the service by specifying the transport that communication should use and whether a proxy should be us
 47            // note that a proxy is only supported when using WebSockets as a transport; it isn't compatible with raw TC
 48            //
 49            // The Event Hub clients each offer a common set of options, such as specifying the timeout and retry approa
 50            // Event Hubs service.  A specific client will potentially allow you to customize behavior specific to its r
 51            //
 52
 53            // This sample will customize the transport for the connection, using WebSockets and will adjust some of the
 54            // illustration.
 55
 056            var producerOptions = new EventHubProducerClientOptions
 057            {
 058                ConnectionOptions = new EventHubConnectionOptions
 059                {
 060                    TransportType = EventHubsTransportType.AmqpWebSockets,
 061                    Proxy = (IWebProxy)null
 062                },
 063
 064                RetryOptions = new EventHubsRetryOptions
 065                {
 066                    MaximumRetries = 5,
 067                    TryTimeout = TimeSpan.FromMinutes(1)
 068                }
 069            };
 70
 071            await using (var producer = new EventHubProducerClient(connectionString, eventHubName, producerOptions))
 72            {
 73                // Using the client, we will inspect the Event Hub that it is connected to, getting
 74                // access to metadata about it.
 75
 076                EventHubProperties properties = await producer.GetEventHubPropertiesAsync();
 77
 078                Console.WriteLine("The Event Hub has the following properties:");
 079                Console.WriteLine($"\tThe path to the Event Hub from the namespace is: { properties.Name }");
 080                Console.WriteLine($"\tThe Event Hub was created at: { properties.CreatedOn.ToString("yyyy-MM-dd hh:mm:ss
 081                Console.WriteLine("\tThe Event Hub has the following partitions:");
 82
 083                foreach (string partitionId in properties.PartitionIds)
 84                {
 085                    Console.WriteLine($"\t\tPartition Id: { partitionId }");
 86                }
 87            }
 88
 89            // At this point, our client has passed its "using" scope and has safely been disposed of.  We have no
 90            // further obligations.
 91
 092            Console.WriteLine();
 093        }
 94    }
 95}