Skip to content

Commit e01b508

Browse files
authored
[Event Hubs] Fix Snippet Syntax (Azure#25684)
* [Event Hubs] Fix Snippet Syntax The focus of these changes is to update the snippet syntax from the legacy comment style (/*@@*/) to the compiler conditional for a few instances that were overlooked in the initial migration. Riding along is a fix for a merge error that snuck into the solution file. * Fix some spacing issues...
1 parent 75f8418 commit e01b508

File tree

6 files changed

+86
-84
lines changed

6 files changed

+86
-84
lines changed

sdk/eventhub/Azure.Messaging.EventHubs.Processor/samples/Sample05_IdentityAndSharedAccessCredentials.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,20 @@ In some scenarios, it may be preferable to supplement token-based authorization
262262
This example illustrates parsing the fully qualified namespace and, optionally, the Event Hub name from the connection string and using it with identity-based authorization.
263263

264264
```C# Snippet:EventHubs_Processor_Sample05_ConnectionStringParse
265-
TokenCredential credential = new DefaultAzureCredential();
266-
267-
var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
268-
var blobContainerName = "<< NAME OF THE BLOB CONTAINER >>";
265+
var credential = new DefaultAzureCredential();
269266

270267
var eventHubsConnectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
271268
var eventHubName = "<< NAME OF THE EVENT HUB >>";
272269
var consumerGroup = "<< NAME OF THE EVENT HUB CONSUMER GROUP >>";
273270

271+
var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
272+
var blobContainerName = "<< NAME OF THE BLOB CONTAINER >>";
274273
var storageEndpoint = new BlobServiceClient(storageConnectionString).Uri;
275-
var blobUriBuilder = new BlobUriBuilder(storageEndpoint);
276-
blobUriBuilder.BlobContainerName = blobContainerName;
274+
275+
var blobUriBuilder = new BlobUriBuilder(storageEndpoint)
276+
{
277+
BlobContainerName = blobContainerName
278+
};
277279

278280
var storageClient = new BlobContainerClient(
279281
blobUriBuilder.ToUri(),

sdk/eventhub/Azure.Messaging.EventHubs.Processor/tests/Snippets/Sample05_IdentityAndSharedAccessCredentialsLiveTests.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,29 @@ public async Task ConnectionStringParse()
309309

310310
#region Snippet:EventHubs_Processor_Sample05_ConnectionStringParse
311311

312-
TokenCredential credential = new DefaultAzureCredential();
313-
314-
var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
315-
var blobContainerName = "<< NAME OF THE BLOB CONTAINER >>";
316-
/*@@*/
317-
/*@@*/ storageConnectionString = StorageTestEnvironment.Instance.StorageConnectionString;
318-
/*@@*/ blobContainerName = storageScope.ContainerName;
312+
#if SNIPPET
313+
var credential = new DefaultAzureCredential();
319314

320315
var eventHubsConnectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
321316
var eventHubName = "<< NAME OF THE EVENT HUB >>";
322317
var consumerGroup = "<< NAME OF THE EVENT HUB CONSUMER GROUP >>";
323-
/*@@*/
324-
/*@@*/ eventHubsConnectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString;
325-
/*@@*/ eventHubName = eventHubScope.EventHubName;
326-
/*@@*/ consumerGroup = eventHubScope.ConsumerGroups.First();
327-
/*@@*/ credential = EventHubsTestEnvironment.Instance.Credential;
328318

319+
var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
320+
var blobContainerName = "<< NAME OF THE BLOB CONTAINER >>";
321+
#else
322+
var credential = EventHubsTestEnvironment.Instance.Credential;
323+
var eventHubsConnectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString;
324+
var eventHubName = eventHubScope.EventHubName;
325+
var consumerGroup = eventHubScope.ConsumerGroups.First();
326+
var storageConnectionString = StorageTestEnvironment.Instance.StorageConnectionString;
327+
var blobContainerName = storageScope.ContainerName;
328+
#endif
329329
var storageEndpoint = new BlobServiceClient(storageConnectionString).Uri;
330-
var blobUriBuilder = new BlobUriBuilder(storageEndpoint);
331-
blobUriBuilder.BlobContainerName = blobContainerName;
330+
331+
var blobUriBuilder = new BlobUriBuilder(storageEndpoint)
332+
{
333+
BlobContainerName = blobContainerName
334+
};
332335

333336
var storageClient = new BlobContainerClient(
334337
blobUriBuilder.ToUri(),

sdk/eventhub/Azure.Messaging.EventHubs/Azure.Messaging.EventHubs.sln

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ Global
8484
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x64.ActiveCfg = Release|Any CPU
8585
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x64.Build.0 = Release|Any CPU
8686
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x86.ActiveCfg = Release|Any CPU
87-
<<<<<<< HEAD
88-
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x86.Build.0 = Release|Any CPU
89-
=======
9087
{FB10A6B3-88DD-4296-9241-53ECDF942842}.Release|x86.Build.0 = Release|Any CPU
9188
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
9289
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -100,19 +97,14 @@ Global
10097
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA}.Release|x64.Build.0 = Release|Any CPU
10198
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA}.Release|x86.ActiveCfg = Release|Any CPU
10299
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA}.Release|x86.Build.0 = Release|Any CPU
103-
>>>>>>> b3d9d8605d ([Event Hubs Client] Idempotent Error Handling)
104100
EndGlobalSection
105101
GlobalSection(SolutionProperties) = preSolution
106102
HideSolutionNode = FALSE
107103
EndGlobalSection
108104
GlobalSection(NestedProjects) = preSolution
109105
{2CFDB3D6-5CFB-428C-9C89-29DD169B5433} = {2DB233D3-E757-423C-8F8D-742B0AFF4713}
110-
<<<<<<< HEAD
111-
{6C67B4C6-0ABF-4E10-8BAF-FCF2AD053DE3} = {2DB233D3-E757-423C-8F8D-742B0AFF4713}
112-
=======
113106
{FB10A6B3-88DD-4296-9241-53ECDF942842} = {2DB233D3-E757-423C-8F8D-742B0AFF4713}
114107
{79B7DF40-239D-4360-A1C3-D4F92A2E75EA} = {2DB233D3-E757-423C-8F8D-742B0AFF4713}
115-
>>>>>>> b3d9d8605d ([Event Hubs Client] Idempotent Error Handling)
116108
EndGlobalSection
117109
GlobalSection(ExtensibilityGlobals) = postSolution
118110
SolutionGuid = {509F2EE0-3348-4506-8AC7-9945B602CB43}

sdk/eventhub/Azure.Messaging.EventHubs/samples/Sample06_IdentityAndSharedAccessCredentials.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var producer = new EventHubProducerClient(fullyQualifiedNamespace, eventHubName,
5454

5555
try
5656
{
57-
using var eventBatch = await producer.CreateBatchAsync();
57+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
5858

5959
for (var index = 0; index < 5; ++index)
6060
{
@@ -87,7 +87,7 @@ var producer = new EventHubProducerClient(fullyQualifiedNamespace, eventHubName,
8787

8888
try
8989
{
90-
using var eventBatch = await producer.CreateBatchAsync();
90+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
9191

9292
for (var index = 0; index < 5; ++index)
9393
{
@@ -120,7 +120,7 @@ var producer = new EventHubProducerClient(fullyQualifiedNamespace, eventHubName,
120120

121121
try
122122
{
123-
using var eventBatch = await producer.CreateBatchAsync();
123+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
124124

125125
for (var index = 0; index < 5; ++index)
126126
{
@@ -148,22 +148,22 @@ In some scenarios, it may be preferable to supplement token-based authorization
148148
This example illustrates parsing the fully qualified namespace and, optionally, the Event Hub name from the connection string and using it with identity-based authorization.
149149

150150
```C# Snippet:EventHubs_Sample06_ConnectionStringParse
151+
var credential = new DefaultAzureCredential();
152+
151153
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
152154
var eventHubName = "<< NAME OF THE EVENT HUB >>";
153155

154156
EventHubsConnectionStringProperties properties =
155157
EventHubsConnectionStringProperties.Parse(connectionString);
156158

157-
TokenCredential credential = new DefaultAzureCredential();
158-
159159
var producer = new EventHubProducerClient(
160160
properties.FullyQualifiedNamespace,
161161
properties.EventHubName ?? eventHubName,
162162
credential);
163163

164164
try
165165
{
166-
using var eventBatch = await producer.CreateBatchAsync();
166+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
167167

168168
for (var index = 0; index < 5; ++index)
169169
{

sdk/eventhub/Azure.Messaging.EventHubs/tests/Snippets/Sample06_IdentityAndSharedAccessCredentialsLiveTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Diagnostics.CodeAnalysis;
66
using System.Threading.Tasks;
7-
using Azure.Core;
87
using Azure.Identity;
98
using Azure.Messaging.EventHubs.Authorization;
109
using Azure.Messaging.EventHubs.Producer;
@@ -49,7 +48,7 @@ public async Task DefaultAzureCredential()
4948

5049
try
5150
{
52-
using var eventBatch = await producer.CreateBatchAsync();
51+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
5352

5453
for (var index = 0; index < 5; ++index)
5554
{
@@ -101,7 +100,7 @@ public async Task SharedAccessSignature()
101100

102101
try
103102
{
104-
using var eventBatch = await producer.CreateBatchAsync();
103+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
105104

106105
for (var index = 0; index < 5; ++index)
107106
{
@@ -150,7 +149,7 @@ public async Task SharedAccessKey()
150149

151150
try
152151
{
153-
using var eventBatch = await producer.CreateBatchAsync();
152+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
154153

155154
for (var index = 0; index < 5; ++index)
156155
{
@@ -185,28 +184,27 @@ public async Task ConnectionStringParse()
185184
#region Snippet:EventHubs_Sample06_ConnectionStringParse
186185

187186
#if SNIPPET
187+
var credential = new DefaultAzureCredential();
188+
188189
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
189190
var eventHubName = "<< NAME OF THE EVENT HUB >>";
190191
#else
191192
var connectionString = EventHubsTestEnvironment.Instance.EventHubsConnectionString;
192193
var eventHubName = scope.EventHubName;
194+
var credential = EventHubsTestEnvironment.Instance.Credential;
193195
#endif
194196

195197
EventHubsConnectionStringProperties properties =
196198
EventHubsConnectionStringProperties.Parse(connectionString);
197199

198-
TokenCredential credential = new DefaultAzureCredential();
199-
/*@@*/
200-
/*@@*/ credential = EventHubsTestEnvironment.Instance.Credential;
201-
202200
var producer = new EventHubProducerClient(
203201
properties.FullyQualifiedNamespace,
204202
properties.EventHubName ?? eventHubName,
205203
credential);
206204

207205
try
208206
{
209-
using var eventBatch = await producer.CreateBatchAsync();
207+
using EventDataBatch eventBatch = await producer.CreateBatchAsync();
210208

211209
for (var index = 0; index < 5; ++index)
212210
{

sdk/eventhub/Microsoft.Azure.EventHubs/tests/Snippets/MigrationGuideSnippets.cs

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ public class MigrationGuideSnippets
3030
public void CreateWithConnectionString()
3131
{
3232
#region Snippet:EventHubs_Migrate_T1_CreateWithConnectionString
33-
33+
#if SNIPPET
3434
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
3535
var eventHubName = "<< NAME OF THE EVENT HUB >>";
36-
/*@@*/
37-
/*@@*/ connectionString = TestUtility.EventHubsConnectionString;
38-
/*@@*/ eventHubName = "fake";
36+
#else
37+
var connectionString = TestUtility.EventHubsConnectionString;
38+
var eventHubName = "fake";
39+
#endif
3940

4041
var builder = new EventHubsConnectionStringBuilder(connectionString);
4142
builder.EntityPath = eventHubName;
@@ -55,20 +56,20 @@ public async Task CreateWithAzureActiveDirectory()
5556
await using var scope = await EventHubScope.CreateAsync(1);
5657

5758
#region Snippet:EventHubs_Migrate_T1_CreateWithAzureActiveDirectory
58-
59+
#if SNIPPET
5960
var fullyQualifiedNamespace = "<< NAMESPACE (likely similar to {your-namespace}.servicebus.windows.net) >>";
6061
var eventHubName = "<< NAME OF THE EVENT HUB >>";
61-
/*@@*/
62-
/*@@*/ fullyQualifiedNamespace = new EventHubsConnectionStringBuilder(TestUtility.EventHubsConnectionString).Endpoint.ToString();
63-
/*@@*/ eventHubName = scope.EventHubName;
6462

6563
var authority = "<< NAME OF THE AUTHORITY TO ASSOCIATE WITH THE TOKEN >>";
6664
var aadAppId = "<< THE AZURE ACTIVE DIRECTORY APPLICATION ID TO REQUEST A TOKEN FOR >>";
6765
var aadAppSecret = "<< THE AZURE ACTIVE DIRECTORY SECRET TO USE FOR THE TOKEN >>";
68-
/*@@*/
69-
/*@@*/ authority = ""; // Needed for manual run
70-
/*@@*/ aadAppId = ""; // Needed for manual run
71-
/*@@*/ aadAppSecret = ""; // Needed for manual run
66+
#else
67+
var fullyQualifiedNamespace = new EventHubsConnectionStringBuilder(TestUtility.EventHubsConnectionString).Endpoint.ToString();
68+
var eventHubName = scope.EventHubName;
69+
var authority = ""; // Needed for manual run
70+
var aadAppId = ""; // Needed for manual run
71+
var aadAppSecret = ""; // Needed for manual run
72+
#endif
7273

7374
AzureActiveDirectoryTokenProvider.AuthenticationCallback authCallback =
7475
async (audience, authority, state) =>
@@ -99,12 +100,13 @@ public async Task CreateWithManagedIdentity()
99100
await using var scope = await EventHubScope.CreateAsync(1);
100101

101102
#region Snippet:EventHubs_Migrate_T1_ManagedIdentity
102-
103+
#if SNIPPET
103104
var fullyQualifiedNamespace = "<< NAMESPACE (likely similar to {your-namespace}.servicebus.windows.net) >>";
104105
var eventHubName = "<< NAME OF THE EVENT HUB >>";
105-
/*@@*/
106-
/*@@*/ fullyQualifiedNamespace = new EventHubsConnectionStringBuilder(TestUtility.EventHubsConnectionString).Endpoint.ToString();
107-
/*@@*/ eventHubName = scope.EventHubName;
106+
#else
107+
var fullyQualifiedNamespace = new EventHubsConnectionStringBuilder(TestUtility.EventHubsConnectionString).Endpoint.ToString();
108+
var eventHubName = scope.EventHubName;
109+
#endif
108110

109111
EventHubClient client = EventHubClient.CreateWithManagedIdentity(
110112
new Uri(fullyQualifiedNamespace),
@@ -123,12 +125,13 @@ public async Task PublishWithAutomaticRouting()
123125
await using var scope = await EventHubScope.CreateAsync(1);
124126

125127
#region Snippet:EventHubs_Migrate_T1_PublishWithAutomaticRouting
126-
128+
#if SNIPPET
127129
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
128130
var eventHubName = "<< NAME OF THE EVENT HUB >>";
129-
/*@@*/
130-
/*@@*/ connectionString = TestUtility.EventHubsConnectionString;
131-
/*@@*/ eventHubName = scope.EventHubName;
131+
#else
132+
var connectionString = TestUtility.EventHubsConnectionString;
133+
var eventHubName = scope.EventHubName;
134+
#endif
132135

133136
var builder = new EventHubsConnectionStringBuilder(connectionString);
134137
builder.EntityPath = eventHubName;
@@ -167,12 +170,13 @@ public async Task PublishWithAPartitionKey()
167170
await using var scope = await EventHubScope.CreateAsync(1);
168171

169172
#region Snippet:EventHubs_Migrate_T1_PublishWithAPartitionKey
170-
173+
#if SNIPPET
171174
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
172175
var eventHubName = "<< NAME OF THE EVENT HUB >>";
173-
/*@@*/
174-
/*@@*/ connectionString = TestUtility.EventHubsConnectionString;
175-
/*@@*/ eventHubName = scope.EventHubName;
176+
#else
177+
var connectionString = TestUtility.EventHubsConnectionString;
178+
var eventHubName = scope.EventHubName;
179+
#endif
176180

177181
var builder = new EventHubsConnectionStringBuilder(connectionString);
178182
builder.EntityPath = eventHubName;
@@ -216,12 +220,13 @@ public async Task PublishToSpecificPartition()
216220
await using var scope = await EventHubScope.CreateAsync(1);
217221

218222
#region Snippet:EventHubs_Migrate_T1_PublishToSpecificPartition
219-
223+
#if SNIPPET
220224
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
221225
var eventHubName = "<< NAME OF THE EVENT HUB >>";
222-
/*@@*/
223-
/*@@*/ connectionString = TestUtility.EventHubsConnectionString;
224-
/*@@*/ eventHubName = scope.EventHubName;
226+
#else
227+
var connectionString = TestUtility.EventHubsConnectionString;
228+
var eventHubName = scope.EventHubName;
229+
#endif
225230

226231
var builder = new EventHubsConnectionStringBuilder(connectionString);
227232
builder.EntityPath = eventHubName;
@@ -265,14 +270,15 @@ public async Task ReadFromSpecificPartition()
265270
await using var scope = await EventHubScope.CreateAsync(1);
266271

267272
#region Snippet:EventHubs_Migrate_T1_ReadFromSpecificPartition
268-
273+
#if SNIPPET
269274
var connectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
270275
var eventHubName = "<< NAME OF THE EVENT HUB >>";
271276
var consumerGroup = "<< NAME OF THE EVENT HUB CONSUMER GROUP >>";
272-
/*@@*/
273-
/*@@*/ connectionString = TestUtility.EventHubsConnectionString;
274-
/*@@*/ eventHubName = scope.EventHubName;
275-
/*@@*/ consumerGroup = PartitionReceiver.DefaultConsumerGroupName;
277+
#else
278+
var connectionString = TestUtility.EventHubsConnectionString;
279+
var eventHubName = scope.EventHubName;
280+
var consumerGroup = PartitionReceiver.DefaultConsumerGroupName;
281+
#endif
276282

277283
var builder = new EventHubsConnectionStringBuilder(connectionString);
278284
builder.EntityPath = eventHubName;
@@ -309,20 +315,21 @@ public async Task BasicEventProcessorHost()
309315
await using var scope = await EventHubScope.CreateAsync(1);
310316

311317
#region Snippet:EventHubs_Migrate_T1_BasicEventProcessorHost
312-
318+
#if SNIPPET
313319
var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
314320
var blobContainerName = "<< NAME OF THE BLOB CONTAINER >>";
315-
/*@@*/
316-
/*@@*/ storageConnectionString = TestUtility.StorageConnectionString;
317-
/*@@*/ blobContainerName = "migragionsample";
318321

319322
var eventHubsConnectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
320323
var eventHubName = "<< NAME OF THE EVENT HUB >>";
321324
var consumerGroup = "<< NAME OF THE EVENT HUB CONSUMER GROUP >>";
322-
/*@@*/
323-
/*@@*/ eventHubsConnectionString = TestUtility.EventHubsConnectionString;
324-
/*@@*/ eventHubName = scope.EventHubName;
325-
/*@@*/ consumerGroup = PartitionReceiver.DefaultConsumerGroupName;
325+
#else
326+
var storageConnectionString = TestUtility.StorageConnectionString;
327+
var blobContainerName = "migragionsample";
328+
329+
var eventHubsConnectionString = TestUtility.EventHubsConnectionString;
330+
var eventHubName = scope.EventHubName;
331+
var consumerGroup = PartitionReceiver.DefaultConsumerGroupName;
332+
#endif
326333

327334
var eventProcessorHost = new EventProcessorHost(
328335
eventHubName,

0 commit comments

Comments
 (0)