Skip to content

Commit 6011385

Browse files
authored
[Event Hubs] Protected Idempotent Surface (Azure#27914)
The focus of these changes is to remove the Experimental shims for exposing the idempotent retries feature on the `EventHubConsumerClient` and shift to a protected and non-browsable API on the client itself. The API of the Experimental package was left unchanged for now to allow partners the opportunity to change over to the new approach. Once that changeover is confirmed, the Experimental package will be retired.
1 parent 516daf0 commit 6011385

33 files changed

+360
-804
lines changed

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/api/Azure.Messaging.EventHubs.Experimental.netstandard2.0.cs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,12 @@ public IdempotentProducer(string fullyQualifiedNamespace, string eventHubName, A
1111
public IdempotentProducer(string fullyQualifiedNamespace, string eventHubName, Azure.AzureSasCredential credential, Azure.Messaging.EventHubs.Producer.IdempotentProducerOptions clientOptions = null) { }
1212
public IdempotentProducer(string fullyQualifiedNamespace, string eventHubName, Azure.Core.TokenCredential credential, Azure.Messaging.EventHubs.Producer.IdempotentProducerOptions clientOptions = null) { }
1313
public IdempotentProducer(string connectionString, string eventHubName, Azure.Messaging.EventHubs.Producer.IdempotentProducerOptions clientOptions) { }
14-
public virtual System.Threading.Tasks.Task<Azure.Messaging.EventHubs.Producer.PartitionPublishingProperties> GetPartitionPublishingPropertiesAsync(string partitionId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
14+
public virtual new System.Threading.Tasks.Task<Azure.Messaging.EventHubs.Producer.PartitionPublishingProperties> GetPartitionPublishingPropertiesAsync(string partitionId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1515
}
16-
public partial class IdempotentProducerOptions
16+
public partial class IdempotentProducerOptions : Azure.Messaging.EventHubs.Producer.EventHubProducerClientOptions
1717
{
1818
public IdempotentProducerOptions() { }
19-
public Azure.Messaging.EventHubs.EventHubConnectionOptions ConnectionOptions { get { throw null; } set { } }
20-
public bool EnableIdempotentPartitions { get { throw null; } set { } }
21-
public string Identifier { get { throw null; } set { } }
22-
public System.Collections.Generic.Dictionary<string, Azure.Messaging.EventHubs.Producer.PartitionPublishingOptions> PartitionOptions { get { throw null; } }
23-
public Azure.Messaging.EventHubs.EventHubsRetryOptions RetryOptions { get { throw null; } set { } }
24-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
25-
public override bool Equals(object obj) { throw null; }
26-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
27-
public override int GetHashCode() { throw null; }
28-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
29-
public override string ToString() { throw null; }
30-
}
31-
public partial class PartitionPublishingOptions
32-
{
33-
public PartitionPublishingOptions() { }
34-
public short? OwnerLevel { get { throw null; } set { } }
35-
public long? ProducerGroupId { get { throw null; } set { } }
36-
public int? StartingSequenceNumber { get { throw null; } set { } }
37-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
38-
public override bool Equals(object obj) { throw null; }
39-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
40-
public override int GetHashCode() { throw null; }
41-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
42-
public override string ToString() { throw null; }
43-
}
44-
public partial class PartitionPublishingProperties
45-
{
46-
public PartitionPublishingProperties(bool isIdempotentPublishingEnabled, long? producerGroupId, short? ownerLevel, int? lastPublishedSequenceNumber) { }
47-
public bool IsIdempotentPublishingEnabled { get { throw null; } }
48-
public int? LastPublishedSequenceNumber { get { throw null; } }
49-
public short? OwnerLevel { get { throw null; } }
50-
public long? ProducerGroupId { get { throw null; } }
51-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
52-
public override bool Equals(object obj) { throw null; }
53-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
54-
public override int GetHashCode() { throw null; }
55-
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
56-
public override string ToString() { throw null; }
19+
public new bool EnableIdempotentPartitions { get { throw null; } set { } }
20+
public new System.Collections.Generic.Dictionary<string, Azure.Messaging.EventHubs.Producer.PartitionPublishingOptions> PartitionOptions { get { throw null; } }
5721
}
5822
}

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/src/Azure.Messaging.EventHubs.Experimental.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<!--
16+
TEMP:
17+
Return to a package reference after 5.7.0-beta.6 is released.
18+
1519
<PackageReference Include="Azure.Messaging.EventHubs" />
20+
-->
21+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs\src\Azure.Messaging.EventHubs.csproj" />
22+
<!-- END TEMP -->
1623
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
1724
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
1825
<PackageReference Include="System.Reflection.TypeExtensions" />

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/src/Producer/IdempotentProducer.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public IdempotentProducer(string connectionString,
118118
///
119119
public IdempotentProducer(string connectionString,
120120
string eventHubName,
121-
IdempotentProducerOptions clientOptions) : base(connectionString, eventHubName, clientOptions.ToCoreOptions())
121+
IdempotentProducerOptions clientOptions) : base(connectionString, eventHubName, clientOptions)
122122
{
123123
}
124124

@@ -134,7 +134,7 @@ public IdempotentProducer(string connectionString,
134134
public IdempotentProducer(string fullyQualifiedNamespace,
135135
string eventHubName,
136136
AzureNamedKeyCredential credential,
137-
IdempotentProducerOptions clientOptions = default) : base(fullyQualifiedNamespace, eventHubName, credential, clientOptions.ToCoreOptions())
137+
IdempotentProducerOptions clientOptions = default) : base(fullyQualifiedNamespace, eventHubName, credential, clientOptions)
138138
{
139139
}
140140

@@ -150,7 +150,7 @@ public IdempotentProducer(string fullyQualifiedNamespace,
150150
public IdempotentProducer(string fullyQualifiedNamespace,
151151
string eventHubName,
152152
AzureSasCredential credential,
153-
IdempotentProducerOptions clientOptions = default) : base(fullyQualifiedNamespace, eventHubName, credential, clientOptions.ToCoreOptions())
153+
IdempotentProducerOptions clientOptions = default) : base(fullyQualifiedNamespace, eventHubName, credential, clientOptions)
154154
{
155155
}
156156

@@ -166,7 +166,7 @@ public IdempotentProducer(string fullyQualifiedNamespace,
166166
public IdempotentProducer(string fullyQualifiedNamespace,
167167
string eventHubName,
168168
TokenCredential credential,
169-
IdempotentProducerOptions clientOptions = default): base(fullyQualifiedNamespace, eventHubName, credential, clientOptions.ToCoreOptions())
169+
IdempotentProducerOptions clientOptions = default): base(fullyQualifiedNamespace, eventHubName, credential, clientOptions)
170170
{
171171
}
172172

@@ -178,7 +178,7 @@ public IdempotentProducer(string fullyQualifiedNamespace,
178178
/// <param name="clientOptions">A set of options to apply when configuring the producer.</param>
179179
///
180180
public IdempotentProducer(EventHubConnection connection,
181-
IdempotentProducerOptions clientOptions = default) : base(connection, clientOptions.ToCoreOptions())
181+
IdempotentProducerOptions clientOptions = default) : base(connection, clientOptions)
182182
{
183183
}
184184

@@ -206,10 +206,7 @@ protected IdempotentProducer() : base()
206206
/// </remarks>
207207
///
208208
public virtual new async Task<PartitionPublishingProperties> GetPartitionPublishingPropertiesAsync(string partitionId,
209-
CancellationToken cancellationToken = default)
210-
{
211-
var coreProperties = await base.GetPartitionPublishingPropertiesAsync(partitionId, cancellationToken).ConfigureAwait(false);
212-
return new PartitionPublishingProperties(coreProperties.IsIdempotentPublishingEnabled, coreProperties.ProducerGroupId, coreProperties.OwnerLevel, coreProperties.LastPublishedSequenceNumber);
213-
}
209+
CancellationToken cancellationToken = default) =>
210+
await base.GetPartitionPublishingPropertiesAsync(partitionId, cancellationToken).ConfigureAwait(false);
214211
}
215212
}

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/src/Producer/IdempotentProducerOptions.cs

Lines changed: 7 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System.Collections.Generic;
5-
using System.ComponentModel;
6-
using Azure.Core;
75

86
namespace Azure.Messaging.EventHubs.Producer
97
{
@@ -12,21 +10,8 @@ namespace Azure.Messaging.EventHubs.Producer
1210
/// to configure its behavior.
1311
/// </summary>
1412
///
15-
public class IdempotentProducerOptions
13+
public class IdempotentProducerOptions : EventHubProducerClientOptions
1614
{
17-
/// <summary>The set of options to use for configuring the connection to the Event Hubs service.</summary>
18-
private EventHubConnectionOptions _connectionOptions = new EventHubConnectionOptions();
19-
20-
/// <summary>The set of options to govern retry behavior and try timeouts.</summary>
21-
private EventHubsRetryOptions _retryOptions = new EventHubsRetryOptions();
22-
23-
/// <summary>
24-
/// A unique name used to identify the consumer. If <c>null</c> or empty, a GUID will be used as the
25-
/// identifier.
26-
/// </summary>
27-
///
28-
public string Identifier { get; set; }
29-
3015
/// <summary>
3116
/// Indicates whether or not the producer should enable idempotent publishing to the Event Hub partitions. If
3217
/// enabled, the producer will only be able to publish directly to partitions; it will not be able to publish to
@@ -35,7 +20,11 @@ public class IdempotentProducerOptions
3520
///
3621
/// <value><c>true</c> if the producer should enable idempotent partition publishing; otherwise, <c>false</c>.</value>
3722
///
38-
public bool EnableIdempotentPartitions { get; set; }
23+
public new bool EnableIdempotentPartitions
24+
{
25+
get => base.EnableIdempotentPartitions;
26+
set => base.EnableIdempotentPartitions = value;
27+
}
3928

4029
/// <summary>
4130
/// The set of options that can be specified to influence publishing behavior specific to the configured Event Hub partition. These
@@ -50,89 +39,6 @@ public class IdempotentProducerOptions
5039
/// These options are ignored when publishing to the Event Hubs gateway for automatic routing or when using a partition key.
5140
/// </remarks>
5241
///
53-
public Dictionary<string, PartitionPublishingOptions> PartitionOptions { get; } = new Dictionary<string, PartitionPublishingOptions>();
54-
55-
/// <summary>
56-
/// The options used for configuring the connection to the Event Hubs service.
57-
/// </summary>
58-
///
59-
public EventHubConnectionOptions ConnectionOptions
60-
{
61-
get => _connectionOptions;
62-
set
63-
{
64-
Argument.AssertNotNull(value, nameof(ConnectionOptions));
65-
_connectionOptions = value;
66-
}
67-
}
68-
69-
/// <summary>
70-
/// The set of options to use for determining whether a failed operation should be retried and,
71-
/// if so, the amount of time to wait between retry attempts. These options also control the
72-
/// amount of time allowed for publishing events and other interactions with the Event Hubs service.
73-
/// </summary>
74-
///
75-
public EventHubsRetryOptions RetryOptions
76-
{
77-
get => _retryOptions;
78-
set
79-
{
80-
Argument.AssertNotNull(value, nameof(RetryOptions));
81-
_retryOptions = value;
82-
}
83-
}
84-
85-
/// <summary>
86-
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
87-
/// </summary>
88-
///
89-
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
90-
///
91-
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
92-
///
93-
[EditorBrowsable(EditorBrowsableState.Never)]
94-
public override bool Equals(object obj) => base.Equals(obj);
95-
96-
/// <summary>
97-
/// Returns a hash code for this instance.
98-
/// </summary>
99-
///
100-
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
101-
///
102-
[EditorBrowsable(EditorBrowsableState.Never)]
103-
public override int GetHashCode() => base.GetHashCode();
104-
105-
/// <summary>
106-
/// Converts the instance to string representation.
107-
/// </summary>
108-
///
109-
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
110-
///
111-
[EditorBrowsable(EditorBrowsableState.Never)]
112-
public override string ToString() => base.ToString();
113-
114-
/// <summary>
115-
/// Creates a new copy of the current <see cref="EventHubProducerClientOptions" />, cloning its attributes into a new instance.
116-
/// </summary>
117-
///
118-
/// <returns>A new copy of <see cref="EventHubProducerClientOptions" />.</returns>
119-
///
120-
internal EventHubProducerClientOptions ToCoreOptions()
121-
{
122-
var copiedOptions = new EventHubProducerClientOptions
123-
{
124-
Identifier = Identifier,
125-
EnableIdempotentPartitions = EnableIdempotentPartitions,
126-
ConnectionOptions = ConnectionOptions,
127-
RetryOptions = RetryOptions,
128-
};
129-
130-
foreach (var pair in PartitionOptions)
131-
{
132-
copiedOptions.PartitionOptions.Add(pair.Key, pair.Value.ToCoreOptions());
133-
}
134-
135-
return copiedOptions;
136-
}
42+
public new Dictionary<string, PartitionPublishingOptions> PartitionOptions => base.PartitionOptions;
13743
}
13844
}

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/src/Resources.Local.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/tests/Azure.Messaging.EventHubs.Experimental.Tests.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
<PackageReference Include="Polly" />
1919
<PackageReference Include="System.Threading.Tasks.Extensions" />
2020
<PackageReference Include="System.ValueTuple" />
21-
22-
<!--
23-
TEMP:
24-
Project reference is needed until the CheckpointStore is included in a release. Revert when
25-
the 5.7.x line is released for GA; allow the dependency to flow in transitively.
26-
-->
27-
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs\src\Azure.Messaging.EventHubs.csproj" />
28-
<!-- END TEMP -->
2921
</ItemGroup>
3022

3123
<ItemGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/tests/Producer/IdempotentProducerLiveTests.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
64
using System.Linq;
7-
using System.Net;
8-
using System.Net.WebSockets;
9-
using System.Text;
105
using System.Threading;
116
using System.Threading.Tasks;
12-
using Azure.Core.Amqp;
13-
using Azure.Messaging.EventHubs.Authorization;
14-
using Azure.Messaging.EventHubs.Consumer;
15-
using Azure.Messaging.EventHubs.Core;
167
using Azure.Messaging.EventHubs.Producer;
178
using Azure.Messaging.EventHubs.Tests;
189
using NUnit.Framework;

sdk/eventhub/Azure.Messaging.EventHubs.Experimental/tests/Producer/IdempotentProducerOptionsTests.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)