Skip to content

Commit 4edc4cf

Browse files
authored
Merge pull request #278734 from spelluru/egridpullqs0619
Updated the code to latest, images, text
2 parents 6547214 + 9e41430 commit 4edc4cf

File tree

13 files changed

+75
-51
lines changed

13 files changed

+75
-51
lines changed

articles/event-grid/event-grid-dotnet-get-started-pull-delivery.md

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.custom:
88
- references_regions
99
- devx-track-dotnet
1010
- ignite-2023
11-
ms.date: 11/15/2023
11+
ms.date: 06/19/2024
1212
---
1313

1414

@@ -31,7 +31,7 @@ In this quickstart, you do the following steps:
3131
If you're new to the service, see [Event Grid overview](overview.md) before you do this quickstart.
3232

3333
- **Azure subscription**. To use Azure services, including Azure Event Grid, you need a subscription. If you don't have an existing Azure account, you can sign up for a [free trial](https://azure.microsoft.com/free/dotnet).
34-
- **Visual Studio 2022**. The sample application makes use of new features that were introduced in C# 10. To use the latest syntax, we recommend that you install .NET 6.0, or higher and set the language version to `latest`. If you're using Visual Studio, versions before Visual Studio 2022 aren't compatible with the tools needed to build C# 10 projects.
34+
- **Visual Studio 2022**. The sample application makes use of new features that were introduced in C# 10. To use the latest syntax, we recommend that you install .NET 6.0, or higher and set the language version to `latest`. If you're using Visual Studio, versions before Visual Studio 2022 aren't compatible with the tools needed to build C# 10 projects.
3535

3636
[!INCLUDE [event-grid-create-namespace-portal](./includes/event-grid-create-namespace-portal.md)]
3737

@@ -43,8 +43,6 @@ If you're new to the service, see [Event Grid overview](overview.md) before you
4343

4444
## Launch Visual Studio
4545

46-
You can authorize access to the Event Grid namespace using the following steps:
47-
4846
Launch Visual Studio. If you see the **Get started** window, select the **Continue without code** link in the right pane.
4947

5048

@@ -73,7 +71,7 @@ This section shows you how to create a .NET console application to send messages
7371
2. Run the following command to install the **Azure.Messaging.EventGrid** NuGet package:
7472

7573
```powershell
76-
Install-Package Azure.Messaging.EventGrid -version 4.22.0-beta.1
74+
Install-Package Azure.Messaging.EventGrid.Namespaces
7775
```
7876
7977
@@ -82,31 +80,36 @@ This section shows you how to create a .NET console application to send messages
8280
1. Replace the contents of `Program.cs` with the following code. The important steps are outlined, with additional information in the code comments.
8381
8482
> [!IMPORTANT]
85-
> Update placeholder values (`<ENDPOINT>` , `<TOPIC-NAME>`, `<TOPIC-ACCESS-KEY>`, `<TOPIC-SUBSCRIPTION-NAME>`) in the code snippet with your topic endpoint, topic name, topic key, topic's subscription name.
83+
> Update placeholder values (`<NAMESPACE-ENDPOINT>` , `<TOPIC-NAME>`, `<TOPIC-ACCESS-KEY>`, `<TOPIC-SUBSCRIPTION-NAME>`) in the code snippet with your namespace endpoint, topic name, and topic key.
8684
8785
```csharp
8886
using Azure.Messaging;
8987
using Azure;
90-
using Azure.Messaging.EventGrid.Namespaces;
88+
using Azure.Messaging.EventGrid.Namespaces;
9189
92-
// TODO: Replace the <ENDPOINT> , <TOPIC-KEY> and <TOPIC-NAME> placeholder
9390
94-
var topicEndpoint = "<TOPIC-ENDPOINT>"; // Should be in the form: https://namespace01.eastus-1.eventgrid.azure.net.
95-
var topicKey = "<TOPIC-ACCESS-KEY>";
91+
// TODO: Replace the following placeholders with appropriate values
92+
93+
// Endpoint of the namespace that you can find on the Overview page for your Event Grid namespace. Prefix it with https://.
94+
// Should be in the form: https://namespace01.eastus-1.eventgrid.azure.net.
95+
var namespaceEndpoint = "<NAMESPACE-ENDPOINT>";
96+
97+
// Name of the topic in the namespace
9698
var topicName = "<TOPIC-NAME>";
97-
var subscription = "<TOPIC-SUBSCRIPTION-NAME>";
98-
99+
100+
// Access key for the topic
101+
var topicKey = "<TOPIC-ACCESS-KEY>";
102+
99103
// Construct the client using an Endpoint for a namespace as well as the access key
100-
var client = new EventGridClient(new Uri(topicEndpoint), new AzureKeyCredential(topicKey));
104+
var client = new EventGridSenderClient(new Uri(namespaceEndpoint), topicName, new AzureKeyCredential(topicKey));
101105
102106
// Publish a single CloudEvent using a custom TestModel for the event data.
103107
var @ev = new CloudEvent("employee_source", "type", new TestModel { Name = "Bob", Age = 18 });
104-
await client.PublishCloudEventAsync(topicName, ev);
108+
await client.SendAsync(ev);
105109
106110
// Publish a batch of CloudEvents.
107111
108-
await client.PublishCloudEventsAsync(
109-
topicName,
112+
await client.SendAsync(
110113
new[] {
111114
new CloudEvent("employee_source", "type", new TestModel { Name = "Tom", Age = 55 }),
112115
new CloudEvent("employee_source", "type", new TestModel { Name = "Alice", Age = 25 })});
@@ -118,7 +121,7 @@ This section shows you how to create a .NET console application to send messages
118121
{
119122
public string Name { get; set; }
120123
public int Age { get; set; }
121-
}
124+
}
122125
123126
```
124127
2. Build the project, and ensure that there are no errors.
@@ -156,7 +159,7 @@ In this section, you create a .NET console application that receives messages fr
156159
1. Run the following command to install the **Azure.Messaging.EventGrid** NuGet package. Select **EventReceiver** for the **Default project** if it's not already set.
157160
158161
```powershell
159-
Install-Package Azure.Messaging.EventGrid -version 4.22.0-beta.1
162+
Install-Package Azure.Messaging.EventGrid.Namespaces
160163
```
161164
162165
:::image type="content" source="./media/event-grid-dotnet-get-started-events/install-event-grid-package.png" alt-text="Screenshot showing EventReceiver project selected in the Package Manager Console.":::
@@ -168,23 +171,36 @@ In this section, you add code to retrieve messages from the queue.
168171
1. Within the `Program` class, add the following code:
169172
170173
> [!IMPORTANT]
171-
> Update placeholder values (`<ENDPOINT>` , `<TOPIC-NAME>`, `<TOPIC-ACCESS-KEY>`, `<TOPIC-SUBSCRIPTION-NAME>`) in the code snippet with your topic endpoint, topic name, topic key, topic's subscription name.
174+
> Update placeholder values (`<NAMESPACE-ENDPOINT>` , `<TOPIC-NAME>`, `<TOPIC-ACCESS-KEY>`, `<TOPIC-SUBSCRIPTION-NAME>`) in the code snippet with your namespace endpoint, topic name, topic key, topic's subscription name.
172175
173176
```csharp
174177
using Azure;
175178
using Azure.Messaging;
176179
using Azure.Messaging.EventGrid.Namespaces;
177180
178-
var topicEndpoint = "<TOPIC-ENDPOINT>"; // Should be in the form: https://namespace01.eastus-1.eventgrid.azure.net.
179-
var topicKey = "<TOPIC-ACCESS-KEY>";
181+
// TODO: Replace the following placeholders with appropriate values
182+
183+
// Endpoint of the namespace that you can find on the Overview page for your Event Grid namespace
184+
// Example: https://namespace01.eastus-1.eventgrid.azure.net.
185+
var namespaceEndpoint = "<NAMESPACE-ENDPOINT>"; // Should be in the form: https://namespace01.eastus-1.eventgrid.azure.net.
186+
187+
// Name of the topic in the namespace
180188
var topicName = "<TOPIC-NAME>";
181-
var subscription = "<TOPIC-SUBSCRIPTION-NAME>";
182-
183-
// Construct the client using an Endpoint for a namespace as well as the access key
184-
var client = new EventGridClient(new Uri(topicEndpoint), new AzureKeyCredential(topicKey));
185189
186-
// Receive the published CloudEvents
187-
ReceiveResult result = await client.ReceiveCloudEventsAsync(topicName, subscription, 3);
190+
// Access key for the topic
191+
var topicKey = "<TOPIC-ACCESS-KEY>";
192+
193+
// Name of the subscription to the topic
194+
var subscriptionName = "<TOPIC-SUBSCRIPTION-NAME>";
195+
196+
// Maximum number of events you want to receive
197+
const short MaxEventCount = 3;
198+
199+
// Construct the client using an Endpoint for a namespace as well as the access key
200+
var client = new EventGridReceiverClient(new Uri(namespaceEndpoint), topicName, subscriptionName, new AzureKeyCredential(topicKey));
201+
202+
// Receive the published CloudEvents.
203+
ReceiveResult result = await client.ReceiveAsync(MaxEventCount);
188204
189205
Console.WriteLine("Received Response");
190206
Console.WriteLine("-----------------");
@@ -195,14 +211,14 @@ In this section, you add code to retrieve messages from the queue.
195211
196212
```csharp
197213
// handle received messages. Define these variables on the top.
198-
214+
199215
var toRelease = new List<string>();
200216
var toAcknowledge = new List<string>();
201217
var toReject = new List<string>();
202218
203219
// Iterate through the results and collect the lock tokens for events we want to release/acknowledge/result
204220
205-
foreach (ReceiveDetails detail in result.Value)
221+
foreach (ReceiveDetails detail in result.Details)
206222
{
207223
CloudEvent @event = detail.Event;
208224
BrokerProperties brokerProperties = detail.BrokerProperties;
@@ -233,7 +249,7 @@ In this section, you add code to retrieve messages from the queue.
233249
234250
if (toRelease.Count > 0)
235251
{
236-
ReleaseResult releaseResult = await client.ReleaseCloudEventsAsync(topicName, subscription, new ReleaseOptions(toRelease));
252+
ReleaseResult releaseResult = await client.ReleaseAsync(toRelease);
237253
238254
// Inspect the Release result
239255
Console.WriteLine($"Failed count for Release: {releaseResult.FailedLockTokens.Count}");
@@ -254,7 +270,7 @@ In this section, you add code to retrieve messages from the queue.
254270
255271
if (toAcknowledge.Count > 0)
256272
{
257-
AcknowledgeResult acknowledgeResult = await client.AcknowledgeCloudEventsAsync(topicName, subscription, new AcknowledgeOptions(toAcknowledge));
273+
AcknowledgeResult acknowledgeResult = await client.AcknowledgeAsync(toAcknowledge);
258274
259275
// Inspect the Acknowledge result
260276
Console.WriteLine($"Failed count for Acknowledge: {acknowledgeResult.FailedLockTokens.Count}");
@@ -275,7 +291,7 @@ In this section, you add code to retrieve messages from the queue.
275291
276292
if (toReject.Count > 0)
277293
{
278-
RejectResult rejectResult = await client.RejectCloudEventsAsync(topicName, subscription, new RejectOptions(toReject));
294+
RejectResult rejectResult = await client.RejectAsync(toReject);
279295
280296
// Inspect the Reject result
281297
Console.WriteLine($"Failed count for Reject: {rejectResult.FailedLockTokens.Count}");
@@ -299,7 +315,13 @@ In this section, you add code to retrieve messages from the queue.
299315
public string Name { get; set; }
300316
public int Age { get; set; }
301317
}
318+
302319
```
320+
1. In the **Solution Explorer** window, right-click **EventReceiver** project, and select **Set as Startup project**.
321+
1. Build the project, and ensure that there are no errors.
322+
1. Run the **EventReceiver** application and confirmation you see the three events in the output window.
323+
324+
:::image type="content" source="./media/event-grid-dotnet-get-started-events/receive-output.png" alt-text="Screenshot showing the output from the Receiver app." lightbox="./media/event-grid-dotnet-get-started-events/receive-output.png":::
303325
304326
## Clean up resources
305327

articles/event-grid/includes/event-grid-create-event-subscriptions-portal.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
---
2-
title: include file
3-
description: include file
2+
title: Create a subscription to an Event Grid namespace topic
3+
description: Include file with steps to create a subscription to an Azure Event Grid namespace topic.
44
services: event-grid
55
author: sonalika-roy
66
ms.service: event-grid
77
ms.topic: include
8-
ms.date: 05/30/20223
8+
ms.date: 06/19/2024
99
ms.author: sonalikaroy
1010
ms.custom: include file
1111
---
1212

1313
## Create an event subscription
1414

1515
1. If you are on the **Topics** page of your Event Grid namespace in the Azure portal, select your topic from the list of topics. If you are on the **Topics** page, follow instructions from [create, view, and manage a namespace topics](../create-view-manage-namespace-topics.md) to identify the topic you want to use to create the event subscription.
16-
2. On the **Event Gird Namespace Topic** page, select **Subscriptions** option in the **Entities** section on the left menu.
17-
3. On the **Subscriptions** page, select "**+ Subscription**" button on the command bar.
1816

19-
:::image type="content" source="../media/create-view-manage-event-subscriptions/event-subscription-create.png" alt-text="Screenshot showing Event Grid event subscription create.":::
20-
4. In the **Basics** tab, type the name of the topic you want to create, and then select **Next: Filters** at the bottom of the page.
17+
:::image type="content" source="../media/create-view-manage-event-subscriptions/select-topic.png" alt-text="Screenshot showing Event Grid topics page with a topic selected." lightbox="../media/create-view-manage-event-subscriptions/select-topic.png":::
18+
1. On the **Event Gird Namespace Topic** page, select **Subscriptions** option in the **Entities** section on the left menu.
19+
1. On the **Subscriptions** page, select "**+ Subscription**" button on the command bar.
2120

22-
:::image type="content" source="../media/create-view-manage-event-subscriptions/event-subscription-create-basics.png" alt-text="Screenshot showing Event Grid event subscription create basics.":::
21+
:::image type="content" source="../media/create-view-manage-event-subscriptions/event-subscription-create.png" alt-text="Screenshot showing Event Grid event subscription create." lightbox="../media/create-view-manage-event-subscriptions/event-subscription-create.png":::
22+
4. In the **Basics** tab, follow these steps:
23+
1. Enter a **name for the subscription** you want to create
24+
1. Confirm that the **delivery schema** is set **Cloud Events v1.0**.
25+
1. Confirm that the **delivery mode** is set to **Queue** (pull mode).
26+
1. Select **Next: Filters** at the bottom of the page.
27+
28+
:::image type="content" source="../media/create-view-manage-event-subscriptions/event-subscription-create-basics.png" alt-text="Screenshot showing Event Grid event subscription create basics.":::
2329
5. In the **Filters** tab, add the names of the event types you want to filter in the subscription and add context attribute filters you want to use in the subscription. Then, select **Next: Additional features** at the bottom of the page.
2430

2531
:::image type="content" source="../media/create-view-manage-event-subscriptions/event-subscription-create-filters.png" alt-text="Screenshot showing Event Grid event subscription create filters.":::

articles/event-grid/includes/event-grid-create-namespace-topic-portal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## Create a namespace topic
1414

15-
1. If you are not on the Event Grid Namespace page, follow the [create, view and manage namespaces](../create-view-manage-namespaces.md) steps to view the namespace you want to use to create the topic.
15+
1. If you aren't on the Event Grid Namespace page, follow the [create, view, and manage namespaces](../create-view-manage-namespaces.md) steps to view the namespace you want to use to create the topic.
1616
2. On the **Event Grid Namespace** page, select **Topics** option in the **Eventing** section on the left menu.
1717
3. On the **Topics** page, select **+ Topic** button on the command bar.
1818

2.66 KB
Loading
-1.59 KB
Loading
-123 Bytes
Loading
54.4 KB
Loading
4.85 KB
Loading
-1.45 KB
Loading
7.49 KB
Loading

0 commit comments

Comments
 (0)