-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
EventHubClientBuilderExtensions.cs
executable file
·95 lines (86 loc) · 5.81 KB
/
EventHubClientBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Azure.Core.Extensions;
using Azure.Messaging.EventHubs.Consumer;
using Azure.Messaging.EventHubs.Producer;
namespace Microsoft.Extensions.Azure
{
/// <summary>
/// The set of extensions to add the Event Hub client types to the clients builder
/// </summary>
public static class EventHubClientBuilderExtensions
{
/// <summary>
/// Registers a <see cref="EventHubProducerClient"/> instance with the provided <paramref name="connectionString"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubProducerClient, EventHubProducerClientOptions> AddEventHubProducerClient<TBuilder>(this TBuilder builder, string connectionString)
where TBuilder : IAzureClientFactoryBuilder
{
return builder.RegisterClientFactory<EventHubProducerClient, EventHubProducerClientOptions>(options => new EventHubProducerClient(connectionString, options));
}
/// <summary>
/// Registers a <see cref="EventHubProducerClient"/> instance with the provided <paramref name="connectionString"/> and <paramref name="eventHubName"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubProducerClient, EventHubProducerClientOptions> AddEventHubProducerClient<TBuilder>(this TBuilder builder, string connectionString, string eventHubName)
where TBuilder : IAzureClientFactoryBuilder
{
return builder.RegisterClientFactory<EventHubProducerClient, EventHubProducerClientOptions>(options => new EventHubProducerClient(connectionString, eventHubName, options));
}
/// <summary>
/// Registers a <see cref="EventHubProducerClient"/> instance with the provided <paramref name="fullyQualifiedNamespace"/> and <paramref name="eventHubName"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubProducerClient, EventHubProducerClientOptions> AddEventHubProducerClientWithNamespace<TBuilder>(this TBuilder builder, string fullyQualifiedNamespace, string eventHubName)
where TBuilder : IAzureClientFactoryBuilderWithCredential
{
return builder.RegisterClientFactory<EventHubProducerClient, EventHubProducerClientOptions>((options, token) => new EventHubProducerClient(fullyQualifiedNamespace, eventHubName, token, options));
}
/// <summary>
/// Registers a <see cref="EventHubProducerClient"/> instance with connection options loaded from the provided <paramref name="configuration"/> instance.
/// </summary>
///
public static IAzureClientBuilder<EventHubProducerClient, EventHubProducerClientOptions> AddEventHubProducerClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
{
return builder.RegisterClientFactory<EventHubProducerClient, EventHubProducerClientOptions>(configuration);
}
/// <summary>
/// Registers a <see cref="EventHubConsumerClientOptions"/> instance with the provided <paramref name="connectionString"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubConsumerClient, EventHubConsumerClientOptions> AddEventHubConsumerClient<TBuilder>(this TBuilder builder, string consumerGroup, string connectionString)
where TBuilder : IAzureClientFactoryBuilder
{
return builder.RegisterClientFactory<EventHubConsumerClient, EventHubConsumerClientOptions>(options => new EventHubConsumerClient(consumerGroup, connectionString, options));
}
/// <summary>
/// Registers a <see cref="EventHubConsumerClient"/> instance with the provided <paramref name="connectionString"/> and <paramref name="eventHubName"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubConsumerClient, EventHubConsumerClientOptions> AddEventHubConsumerClient<TBuilder>(this TBuilder builder, string consumerGroup, string connectionString, string eventHubName)
where TBuilder : IAzureClientFactoryBuilder
{
return builder.RegisterClientFactory<EventHubConsumerClient, EventHubConsumerClientOptions>(options => new EventHubConsumerClient(consumerGroup, connectionString, eventHubName, options));
}
/// <summary>
/// Registers a <see cref="EventHubConsumerClient"/> instance with the provided <paramref name="fullyQualifiedNamespace"/> and <paramref name="eventHubName"/>
/// </summary>
///
public static IAzureClientBuilder<EventHubConsumerClient, EventHubConsumerClientOptions> AddEventHubConsumerClientWithNamespace<TBuilder>(this TBuilder builder, string consumerGroup, string fullyQualifiedNamespace, string eventHubName)
where TBuilder : IAzureClientFactoryBuilderWithCredential
{
return builder.RegisterClientFactory<EventHubConsumerClient, EventHubConsumerClientOptions>((options, token) => new EventHubConsumerClient(consumerGroup, fullyQualifiedNamespace, eventHubName, token, options));
}
/// <summary>
/// Registers a <see cref="EventHubConsumerClient"/> instance with connection options loaded from the provided <paramref name="configuration"/> instance.
/// </summary>
///
public static IAzureClientBuilder<EventHubConsumerClient, EventHubConsumerClientOptions> AddEventHubConsumerClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
{
return builder.RegisterClientFactory<EventHubConsumerClient, EventHubConsumerClientOptions>(configuration);
}
}
}