Skip to content

Commit b1d561f

Browse files
Merge pull request #225273 from cebundy/wps-howto-eventhandler
[Web PubSub] Freshness review of howto-develop-eventhandler.md
2 parents a282b05 + cf2dcda commit b1d561f

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

articles/azure-web-pubsub/howto-develop-eventhandler.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,85 @@ author: JialinXin
55
ms.author: jixin
66
ms.service: azure-web-pubsub
77
ms.topic: how-to
8-
ms.date: 10/31/2021
8+
ms.date: 01/27/2023
99
---
1010

1111
# Event handler in Azure Web PubSub service
1212

13-
The event handler handles the incoming client events. Event handlers are registered and configured in the service through portal or Azure CLI beforehand so that when a client event is triggered, the service can identify if the event is expected to be handled or not. We now support the event handler as the server side, which exposes public accessible endpoint for the service to invoke when the event is triggered. In other words, it acts as a **webhook**.
13+
The event handler handles the incoming client events. Event handlers are registered and configured in the service through the Azure portal or Azure CLI. When a client event is triggered, the service can send the event to the appropriate event handler. The Web PubSub service now supports the event handler as the server-side, which exposes the publicly accessible endpoint for the service to invoke when the event is triggered. In other words, it acts as a **webhook**.
1414

15-
Service delivers client events to the upstream webhook using the [CloudEvents HTTP protocol](https://github.com/cloudevents/spec/blob/v1.0.1/http-protocol-binding.md).
15+
The Web PubSub service delivers client events to the upstream webhook using the [CloudEvents HTTP protocol](https://github.com/cloudevents/spec/blob/v1.0.1/http-protocol-binding.md).
1616

17-
For every event, it formulates an HTTP POST request to the registered upstream and expects an HTTP response.
17+
For every event, the service formulates an HTTP POST request to the registered upstream endpoint and expects an HTTP response.
1818

1919
The data sending from the service to the server is always in CloudEvents `binary` format.
2020

2121
:::image type="content" source="media/howto-develop-eventhandler/event-trigger.png" alt-text="Screenshot of Web PubSub service event trigger.":::
2222

2323
## Upstream and Validation
2424

25-
When configuring the webhook endpoint, the URL can use `{event}` parameter to define a URL template. The service calculates the value of the webhook URL dynamically when the client request comes in. For example, when a request `/client/hubs/chat` comes in, with a configured event handler URL pattern `http://host.com/api/{event}` for hub `chat`, when the client connects, it will first POST to this URL: `http://host.com/api/connect`. The parameter can be useful when a PubSub WebSocket client sends custom events, that the event handler helps dispatch different events to different upstream. Note that the `{event}` parameter is not allowed in the URL domain name.
25+
When you configure the webhook endpoint, the URL can include the `{event}` parameter to define a URL template. The service calculates the value of the webhook URL dynamically when the client request comes in. For example, when a request `/client/hubs/chat` comes in, with a configured event handler URL pattern `http://host.com/api/{event}` for hub `chat`, when the client connects, it will first POST to this URL: `http://host.com/api/connect`. The `{event}` parameter can be useful when a PubSub WebSocket client sends custom events, that the event handler helps dispatch different events to different upstream endpoints. The `{event}` parameter isn't allowed in the URL domain name.
2626

27-
When setting up the event handler upstream through Azure portal or CLI, the service follows the [CloudEvents Abuse Protection](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#4-abuse-protection) to validate the upstream webhook. Every registered upstream webhook URL will be validated by this mechanism. The `WebHook-Request-Origin` request header is set to the service domain name `xxx.webpubsub.azure.com`, and it expects the response to have a header `WebHook-Allowed-Origin` to contain this domain name or `*`.
27+
When setting up the event handler webhook through Azure portal or CLI, the service follows the [CloudEvents Abuse Protection](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#4-abuse-protection) to validate the upstream webhook. Every registered upstream webhook URL will be validated by this mechanism. The `WebHook-Request-Origin` request header is set to the service domain name `xxx.webpubsub.azure.com`, and it expects the response to have a header `WebHook-Allowed-Origin` to contain this domain name or `*`.
2828

2929
When doing the validation, the `{event}` parameter is resolved to `validate`. For example, when trying to set the URL to `http://host.com/api/{event}`, the service will try to **OPTIONS** a request to `http://host.com/api/validate`. And only when the response is valid, the configuration can be set successfully.
3030

31-
For now, we do not support [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback).
31+
For now, we don't support [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback).
3232

3333
## Authentication between service and webhook
3434

35+
You can use any of these methods to authenticate between the service and webhook.
36+
3537
- Anonymous mode
3638
- Simple Auth with `?code=<code>` is provided through the configured Webhook URL as query parameter.
37-
- Use Azure Active Directory(Azure AD) authentication, check [here](howto-use-managed-identity.md) for details.
38-
- Step1: Enable Identity for the Web PubSub service
39-
- Step2: Select from existing AAD application that stands for your webhook web app
39+
- Azure Active Directory(Azure AD) authentication. For more information, see [Use a managed identity in client events](howto-use-managed-identity.md#use-a-managed-identity-in-client-events-scenarios).
4040

4141
## Configure event handler
4242

4343
### Configure through Azure portal
4444

45-
Find your Azure Web PubSub service from **Azure portal**. Navigate to **Settings**. Then select **Add** to configure your server-side webhook URL. For an existing hub configuration, select **...** on right side will navigate to the same editing page.
45+
You can add an event handler to a new hub or edit an existing hub.
46+
47+
To configure an event handler in a new hub:
48+
49+
1. Go to your Azure Web PubSub service page in the **Azure portal**.
50+
1. Select **Settings** from the menu.
51+
1. Select **Add** to create a hub and configure your server-side webhook URL. Note: To add an event handler to an existing hub, select the hub and select **Edit**.
52+
53+
:::image type="content" source="media/quickstart-serverless/set-event-handler.png" alt-text="Screenshot of setting the event handler.":::
4654

47-
:::image type="content" source="media/quickstart-serverless/set-event-handler.png" alt-text="Screenshot of setting the event handler.":::
55+
1. Enter your hub name.
56+
1. Select **Add** under **Configure Even Handlers**.
57+
1. In the event handler page, configure the following fields:
58+
1. Enter the server webhook URL in the **URL Template** field.
59+
1. Select the **System events** that you want to subscribe to.
60+
1. Select the **User events** that you want to subscribe to.
61+
1. Select **Authentication** method to authenticate upstream requests.
62+
1. Select **Confirm**.
63+
:::image type="content" source="media/howto-develop-eventhandler/configure-event-handler.png" alt-text="Screenshot of Azure Web PubSub Configure Event Handler.":::
4864

49-
Then in the below editing page, you'd need to configure hub name, server webhook URL, and select `user` and `system` events you'd like to subscribe. Finally select **Save** when everything is done.
65+
1. Select **Save** at the top of the **Configure Hub Settings** page.
5066

51-
:::image type="content" source="media/quickstart-serverless/edit-event-handler.png" alt-text="Screenshot of editing the event handler.":::
67+
:::image type="content" source="media/quickstart-serverless/edit-event-handler.png" alt-text="Screenshot of Azure Web PubSub Configure Hub Settings.":::
5268

5369
### Configure through Azure CLI
5470

5571
Use the Azure CLI [**az webpubsub hub**](/cli/azure/webpubsub/hub) group commands to configure the event handler settings.
5672

5773
Commands | Description
5874
--|--
59-
create | Create hub settings for WebPubSub Service.
60-
delete | Delete hub settings for WebPubSub Service.
61-
list | List all hub settings for WebPubSub Service.
62-
show | Show hub settings for WebPubSub Service.
63-
update | Update hub settings for WebPubSub Service.
75+
`create` | Create hub settings for WebPubSub Service.
76+
`delete` | Delete hub settings for WebPubSub Service.
77+
`list` | List all hub settings for WebPubSub Service.
78+
`show` | Show hub settings for WebPubSub Service.
79+
`update` | Update hub settings for WebPubSub Service.
6480

65-
Below is an example of creating 2 webhook URLs for hub `MyHub` of `MyWebPubSub` resource.
81+
Here's an example of creating two webhook URLs for hub `MyHub` of `MyWebPubSub` resource:
6682

6783
```azurecli-interactive
6884
az webpubsub hub create -n "MyWebPubSub" -g "MyResourceGroup" --hub-name "MyHub" --event-handler url-template="http://host.com" user-event-pattern="*" --event-handler url-template="http://host2.com" system-event="connected" system-event="disconnected" auth-type="ManagedIdentity" auth-resource="uri://myUri"
6985
```
7086

7187
## Next steps
7288

73-
[!INCLUDE [next step](includes/include-next-step.md)]
89+
[!INCLUDE [next step](includes/include-next-step.md)]
40 KB
Loading

0 commit comments

Comments
 (0)