You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide outlines the steps to subscribe to Job Router events from your Azure Communication Services Event Grid subscription. Receiving events is a critical capability your custom applications will need to perform. The actions Job Router will perform on Jobs you submit happen asynchronously and while the SDK provides endpoints to query the status and state of objects in the system, building a reactive event-driven custom application has significant benefits.
16
+
This guide outlines the steps to setup a subscription for Job Router events and how to receive them.
17
+
18
+
For more details on Event Grid, please see the [Event Grid documentation][event-grid-overview].
@@ -22,169 +24,96 @@ This guide outlines the steps to subscribe to Job Router events from your Azure
22
24
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
23
25
- A deployed Communication Services resource. [Create a Communication Services resource](../../quickstarts/create-communication-resource.md).
24
26
- Optional: Complete the quickstart to [get started with Job Router](../../quickstarts/router/get-started-router.md)
25
-
- Install the [Azure Resource Manager (ARM) client](https://github.com/projectkudu/ARMClient)
26
-
- Review the [GitHub sample project using a customized version of the Event Grid Viewer for Job Router](https://github.com/Azure/communication-preview/tree/master/samples/Job-Router/Event-Grid-Viewer)
27
27
28
28
## Create an Event Grid subscription
29
29
30
30
> [!NOTE]
31
-
> The following scripts are being executed using PowerShell
32
-
33
-
**Log into your Azure account**
31
+
> Since Job Router is still in preview, the events are not included in the portal UI. You have to use an Azure Resource Manager (ARM) template to create a subscription that references them.
34
32
35
-
```powershell
36
-
armclient azlogin
37
-
```
33
+
This template deploys an EventGrid subscription on a Storage Queue for Job Router events.
34
+
If the storage account, queue or system topic do not exist, they will be created as well.
[](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fcommunication-services%2Fhow-tos%2Frouter-sdk%2Fmedia%2Fdeploy-subscription.json)
44
37
45
-
**List all ACS resources in subscription**
46
-
```powershell
47
-
armclient get "/$env:SUB/$env:RG/providers/Microsoft.Communication/communicationservices?api-version=2020-08-20"
48
-
```
49
-
**Output**
38
+
### Parameters
50
39
51
-
:::image type="content" source="media/create-subscription-output.png" alt-text="Output of PowerShell command":::
40
+
-**Azure Communication Services Resource Name**: The name of your Azure Communication Services resource. For example, if the endpoint to your resource is https://contoso.communication.azure.net, then set to `contoso`.
41
+
-**Storage Name**: The name of your Azure Storage Account. If it does not exist, it will be created.
42
+
-**Event Sub Name**: The name of the event subscription to create.
43
+
-**System Topic Name**: If you have existing event subscriptions on your ACS resource, find the `System Topic` name in the `Events` tab of your ACS resource. Otherwise, specify a unique name such as the ACS resource name itself.
44
+
-**Queue Name**: The name of your Queue within your Storage Account. If it does not exist, it will be created.
52
45
53
-
As we can see, there is currently only one Azure Communication Services resource under the given subscription and resource group.
46
+
### Deployed resources
54
47
55
-
**Set PowerShell variables**
48
+
The following resources are deployed as part of the solution
56
49
57
-
Set the name of your Azure Communication Services resource. For example, if the endpoint to your resource is `https://contoso.communication.azure.net`, then set `ACS_RESOURCE_NAME` to the prefix of the DNS name; `contoso`.
50
+
-**Storage Account**: If the storage account name does not exist.
51
+
-**Storage Queue**: If the queue does not exist within the storage account.
52
+
-**Event Grid System Topic**: If the topic does not exist.
53
+
-**Event Grid Subscription**: A subscription for all Job Router events on the storage queue.
## Quick-start: Receive EventGrid events via an Azure Storage Queue
66
56
67
-
**Create a new event subscription for Router events**
57
+
### Create a new C# application
68
58
69
-
Copy and paste the following json payload in a text file named `test.json`.
59
+
In a console window (such as cmd, PowerShell, or Bash), use the `dotnet new` command to create a new console app with the name `EventReceiver`. This command creates a simple "Hello World" C# project with a single source file: **Program.cs**.
As we can see, the event subscription is being created and is currently in a state of `Creating`. It generally takes a few seconds to create.
74
+
Install the Azure Storage Queues and EventGrid packages.
115
75
116
-
**Verify the event subscription was successfully created**
117
-
```powershell
118
-
armclient get "$env:ACS_RESOURCE_ARM_ID/$env:EVENT_SUBSCRIPTIONS_PATH/$env:API_VERSION"
76
+
```console
77
+
dotnet add package Azure.Storage.Queues
78
+
dotnet add package Azure.Messaging.EventGrid
119
79
```
120
80
121
-
**Output**
122
-
123
-
:::image type="content" source="media/verify-subscription-created.png" alt-text="Verify subscription was created":::
81
+
### Receive messages from the queue
124
82
125
-
As we can see the event subscription has been successfully created now for all Router events.
83
+
Copy the following code snippet and paste into source file: **Program.cs**
126
84
127
-
## Creating a subscription with filters
85
+
```csharp
86
+
usingAzure.Storage.Queues;
87
+
usingAzure.Messaging.EventGrid;
128
88
129
-
While setting up event subscriptions, you can also use advanced filters controlling the exact events that needs to sent to a particular subscription. For example, given the sample below, only `RouterJobCancelled` events are subscribed to and sent to the webhook under the following conditions:
89
+
// For more detailed tutorials on storage queues, see: https://docs.microsoft.com/azure/storage/queues/storage-tutorial-queues
130
90
131
-
- The job **priority** is greater than `5`
132
-
- The job was assigned to an escalation queue
133
-
- The job was canceled due to inactivity
134
-
- The disposition code for canceled Jobs ends with `_JobCancelledDueToInactivity`
135
-
- The Queue ID ends with the name `EscalationQueue`
Run the application from your application directory with the `dotnet run` command.
185
113
186
-
> [!NOTE]
187
-
> For a complete list of operators that can be used while creating subscriptions, refer to [Event Grid | Event Filtering - Operators](../../../event-grid/event-filtering.md)
114
+
```console
115
+
dotnet run
116
+
```
188
117
189
118
## Events Catalog
190
119
@@ -874,3 +803,7 @@ armclient put "$env:ACS_RESOURCE_ARM_ID/$env:EVENT_SUBSCRIPTIONS_PATH/$env:EVENT
874
803
| Attribute | Type | Nullable |Description | Notes |
0 commit comments