Skip to content

Commit 140360a

Browse files
committed
art2-2
1 parent f60782c commit 140360a

1 file changed

Lines changed: 36 additions & 31 deletions

File tree

articles/app-service/webjobs-sdk-get-started.md

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ ms.custom:
1818

1919
Get started with the Azure WebJobs SDK for Azure App Service to enable your web apps to run background tasks, scheduled tasks, and respond to events.
2020

21-
Use Visual Studio 2022 to create a .NET 8 console app that uses the WebJobs SDK to respond to Azure Storage Queue messages, run the project locally, and finally deploy it to Azure.
21+
In this tutorial, you use Visual Studio 2022 to create a .NET 8 console app that uses the WebJobs SDK to respond to Azure Storage Queue messages. Then, you run the project locally, and finally deploy it to Azure.
2222

23-
In this tutorial, you'll learn how to:
23+
You learn how to:
2424

2525
> [!div class="checklist"]
2626
> * Create a console app
@@ -60,7 +60,7 @@ Install the latest WebJobs NuGet package. This package includes Microsoft.Azure.
6060

6161
1. In Visual Studio, go to **Tools** > **NuGet Package Manager**.
6262

63-
1. Select **Package Manager Console**. You'll see a list of NuGet cmdlets, a link to documentation, and a `PM>` entry point.
63+
1. Select **Package Manager Console**. On the console, you see a list of NuGet cmdlets, a link to documentation, and a `PM>` entry point.
6464

6565
1. In the following command, replace `<4_X_VERSION>` with the current version number you found in step 1.
6666

@@ -111,7 +111,7 @@ In ASP.NET Core, host configurations are set by calling methods on the [`HostBui
111111
112112
### Enable console logging
113113
114-
Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/core/fundamentals/logging). This framework, Microsoft.Extensions.Logging, includes an API that works with various built-in and third-party logging providers.
114+
Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/core/fundamentals/logging). This framework, Microsoft.Extensions.Logging, includes an API that works with various built-in and non-Microsoft logging providers.
115115
116116
1. Get the latest stable version of the [`Microsoft.Extensions.Logging.Console` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/), which includes `Microsoft.Extensions.Logging`.
117117
@@ -139,7 +139,7 @@ Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/co
139139
});
140140
```
141141

142-
This adds logging that captures log output for function executions at the `Information` level, the host at the `Debug` level, and the `error` level for all other components. The `Main` method now looks like this:
142+
This method adds logging that captures log output for function executions at the `Information` level, the host at the `Debug` level, and the `error` level for all other components. The `Main` method now looks like this:
143143

144144
```cs
145145
static async Task Main()
@@ -169,11 +169,11 @@ Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/co
169169
- Disables [dashboard logging](https://github.com/Azure/azure-webjobs-sdk/wiki/Queues#logs). The dashboard is a legacy monitoring tool, and dashboard logging isn't recommended for high-throughput production scenarios.
170170
- Adds the console provider with default [filtering](webjobs-sdk-how-to.md#log-filtering).
171171

172-
Now, you can add a function that is triggered by messages arriving in an Azure Storage queue.
172+
Now, you can add a function triggered by messages arriving in an Azure Storage queue.
173173

174174
## Add a function
175175

176-
A function is unit of code that runs on a schedule, is triggered based on events, or is run on demand. A trigger listens to a service event. In the context of the WebJobs SDK, triggered doesn't refer to the deployment mode. Event-driven or scheduled WebJobs created using the SDK should always be deployed as continuous WebJobs with "Always on" enabled.
176+
A function is a unit of code that runs on a schedule, is triggered based on events, or is run on demand. A trigger listens to a service event. In the context of the WebJobs SDK, triggered doesn't refer to the deployment mode. Event-driven or scheduled WebJobs created using the SDK should always be deployed as continuous WebJobs with *Always on* enabled.
177177

178178
In this section, you create a function triggered by messages in an Azure Storage queue. First, you need to add a binding extension to connect to Azure Storage.
179179

@@ -182,7 +182,7 @@ In this section, you create a function triggered by messages in an Azure Storage
182182
Starting with version 3 of the WebJobs SDK, to connect to Azure Storage services you must install a separate Storage binding extension package.
183183

184184
> [!NOTE]
185-
> Beginning with 5.x, Microsoft.Azure.WebJobs.Extensions.Storage has been [split by storage service](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage/CHANGELOG.md#major-changes-and-features) and has migrated the `AddAzureStorage()` extension method by service type. This version also requires you to update the version of the `Microsoft.Azure.WebJobs.Host.Storage` assembly used by the SDK.
185+
> Beginning with 5.x, `Microsoft.Azure.WebJobs.Host.Storage` is [split according to storage service](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage/CHANGELOG.md#major-changes-and-features), with the `AddAzureStorage()` extension method migrated per service type. This version also requires you to update the version of the `Microsoft.Azure.WebJobs.Host.Storage` assembly used by the SDK.
186186
187187
1. Get the latest stable version of the [Microsoft.Azure.WebJobs.Extensions.Storage](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage) NuGet package, version 5.x.
188188
@@ -215,7 +215,7 @@ Starting with version 3 of the WebJobs SDK, to connect to Azure Storage services
215215
builder.UseEnvironment(EnvironmentName.Development);
216216
```
217217

218-
Running in [development mode](webjobs-sdk-how-to.md#host-development-settings) reduces the [queue polling exponential backoff](../azure-functions/functions-bindings-storage-queue-trigger.md?tabs=csharp#polling-algorithm) that can significantly delay the amount of time it takes for the runtime to find the message and invoke the function. You should remove this line of code or switch to `Production` when you're done with development and testing.
218+
Running in [development mode](webjobs-sdk-how-to.md#host-development-settings) reduces the [queue polling exponential backoff](../azure-functions/functions-bindings-storage-queue-trigger.md?tabs=csharp#polling-algorithm). This polling algorithm can significantly delay the amount of time it takes for the runtime to find the message and invoke the function. You should remove this line of code or switch to `Production` when you're done with development and testing.
219219

220220
The `Main` method should now look like the following example:
221221

@@ -270,25 +270,25 @@ The `QueueTrigger` attribute tells the runtime to call this function when a new
270270
}
271271
```
272272

273-
You should mark the *Functions* class as `public static` in order for the runtime to access and execute the method. In the above code sample, when a message is added to a queue named `queue`, the function executes and the `message` string is written to the logs. The queue being monitored is in the default Azure Storage account, which you create next.
273+
You should mark the *Functions* class as `public static` in order for the runtime to access and execute the method. In the preceding code sample, when a message is added to a queue named `queue`, the function executes and the `message` string is written to the logs. The queue being monitored is in the default Azure Storage account, which you create next.
274274

275275
The `message` parameter doesn't have to be a string. You can also bind to a JSON object, a byte array, or a [CloudQueueMessage](/dotnet/api/microsoft.azure.storage.queue.cloudqueuemessage) object. [See Queue trigger usage](../azure-functions/functions-bindings-storage-queue-trigger.md?tabs=csharp#usage). Each binding type (such as queues, blobs, or tables) has a different set of parameter types that you can bind to.
276276

277277
### Create an Azure storage account
278278

279-
The Azure Storage Emulator that runs locally doesn't have all of the features that the WebJobs SDK needs. You'll create a storage account in Azure and configure the project to use it.
279+
The Azure Storage Emulator that runs locally doesn't have all of the features that the WebJobs SDK needs. You need to create a storage account in Azure and configure the project to use it.
280280

281281
To learn how to create a general-purpose v2 storage account, see [Create an Azure Storage account](../storage/common/storage-account-create.md?tabs=azure-portal).
282282

283283
### Locate and copy your connection string
284+
284285
A connection string is required to configure storage. Keep this connection string for the next steps.
285286

286287
1. In the [Azure portal](https://portal.azure.com), navigate to your storage account and select **Settings**.
287288
1. In **Settings**, select **Access keys**.
288289
1. For the **Connection string** under **key1**, select the **Copy to clipboard** icon.
289290

290-
![key](./media/webjobs-sdk-get-started/connection-key.png)
291-
:::image type="content" source="./media/webjobs-sdk-get-started/connection-key.png" alt-text="Key":::0601
291+
:::image type="content" source="./media/webjobs-sdk-get-started/connection-key.png" alt-text="Screenshot of the Access keys dialog showing how to locate and copy the connection string.":::
292292

293293
### Configure storage to run locally
294294

@@ -312,25 +312,30 @@ Because this file contains a connection string secret, you shouldn't store the f
312312

313313
## Test locally
314314

315-
Build and run the project locally and create a message queue to trigger the function.
315+
To trigger the function, build and run the project locally and create a message queue.
316+
317+
1. In the Azure portal, navigate to your storage account and complete the following steps.
316318

317-
1. In the Azure portal, navigate to your storage account and select the **Queues** tab (1). Select **+ Queue** (2) and enter **queue** as the Queue name (3). Then, select **OK** (4).
319+
- Select the **Queues** tab (1).
320+
- Select **+ Queue** (2).
321+
- Enter **queue** as the **Queue name** (3).
322+
- Select **OK** (4).
318323

319-
:::image type="content" source="./media/webjobs-sdk-get-started/create-queue-azure-storage.png" alt-text="This image shows how to create a new Azure Storage Queue.":::
324+
:::image type="content" source="./media/webjobs-sdk-get-started/create-queue-azure-storage.png" alt-text="Screenshoit that calls out the four steps for creating a new Azure Storage Queue.":::
320325

321326
1. Select the new queue and select **Add message**.
322327

323-
1. In the **Add Message** dialog, enter *Hello World!* as the **Message text**, and then select **OK**. There is now a message in the queue.
328+
1. In the **Add message to queue** dialog, enter *Hello World!* as the **Message text**, and then select **OK**. Now, there's a message in the queue.
324329

325-
:::image type="content" source="./media/webjobs-sdk-get-started/hello-world-text.png" alt-text="Create queue.":::
330+
:::image type="content" source="./media/webjobs-sdk-get-started/hello-world-text.png" alt-text="Screenshot of the Add message to queue dialog showing the text 'Hello World!' added as message text.":::
326331

327332
1. Press **Ctrl+F5** to run the project.
328333

329334
The console shows that the runtime found your function. Because you used the `QueueTrigger` attribute in the `ProcessQueueMessage` function, the WebJobs runtime listens for messages in the queue named `queue`. When it finds a new message in this queue, the runtime calls the function, passing in the message string value.
330335

331-
1. Go back to the **Queue** window and refresh it. The message is gone, since it has been processed by your function running locally.
336+
1. Go back to the **Queue** window and refresh it. The message is gone. Your function running locally, successfully processed the message.
332337

333-
1. Close the console window or type Ctrl+C.
338+
1. Close the console window or type **Ctrl+C**.
334339

335340
It's now time to publish your WebJobs SDK project to Azure.
336341

@@ -354,15 +359,15 @@ For a continuous WebJob, you should enable the Always on setting in the site so
354359

355360
With the web app created in Azure, it's time to publish the WebJobs project.
356361

357-
1. In the **Publish** page under **Hosting**, select the edit button and change the **WebJob Type** to `Continuous` and select **Save**. This makes sure that the WebJob is running when messages are added to the queue. Triggered WebJobs are typically used only for manual webhooks.
362+
1. In the **Publish** page under **Hosting**, select the edit button and change the **WebJob Type** to `Continuous` and select **Save**. This setting makes sure that the WebJob is running when messages are added to the queue. Triggered WebJobs are typically used only for manual webhooks.
358363

359-
:::image type="content" source="./media/webjobs-sdk-get-started/change-webjob-type.png" alt-text="Change WebJob type from the Visual Studio 2022 Publish window.":::
364+
:::image type="content" source="./media/webjobs-sdk-get-started/change-webjob-type.png" alt-text="Screenshoit showing how to change the WebJob type from the Visual Studio 2022 Publish window.":::
360365

361366
1. Select the **Publish** button at the top right corner of the **Publish** page. When the operation completes, your WebJob is running on Azure.
362367

363368
### Create a storage connection app setting
364369

365-
You need to create the same storage connection string setting in Azure that you used locally in your appsettings.json config file. This lets you more securely store the connection string and
370+
You need to create the same storage connection string setting in Azure that you used locally in your appsettings.json config file. This setting lets you store the connection string more securely.
366371

367372
1. In your **Publish** profile page, select the three dots above **Hosting** to show **Hosting profile section actions** and choose **Manage Azure App Service settings**.
368373

@@ -380,7 +385,7 @@ The connection string is now set in your app in Azure.
380385

381386
1. In the **Queue** page in Visual Studio, add a message to the queue as before.
382387

383-
1. Refresh the **Queue** page, and the new message disappears because it has been processed by the function running in Azure.
388+
1. Refresh the **Queue** page, and the new message disappears because it was processed by the function running in Azure.
384389

385390
## Enable Application Insights logging
386391

@@ -457,7 +462,7 @@ static async Task Main()
457462
}
458463
```
459464

460-
This initializes the Application Insights logging provider with default [filtering](webjobs-sdk-how-to.md#log-filtering). When running locally, all Information and higher-level logs are written to both the console and Application Insights. When running locally, Application Insights logging is only supported after you also add the `APPINSIGHTS_INSTRUMENTATIONKEY` to the `appsetting.json` file in the project.
465+
This code initializes the Application Insights logging provider with default [filtering](webjobs-sdk-how-to.md#log-filtering). When the code runs locally, all Information and higher-level logs are written to both the console and Application Insights. Also, when the code runs locally, Application Insights logging is only supported after you also add the `APPINSIGHTS_INSTRUMENTATIONKEY` to the `appsetting.json` file in the project.
461466

462467
### Republish the project and trigger the function again
463468

@@ -471,19 +476,19 @@ This initializes the Application Insights logging provider with default [filteri
471476

472477
1. Select **Search** and then select **See all data in the last 24 hours**.
473478

474-
:::image type="content" source="./media/webjobs-sdk-get-started/select-search.png" alt-text="Select Search":::
479+
:::image type="content" source="./media/webjobs-sdk-get-started/select-search.png" alt-text="Screenshot showing how to search and display Application Insights data.":::
475480

476481
1. If you don't see the *Hello App Insights!* message, select **Refresh** periodically for several minutes. Logs don't appear immediately, because it takes a while for the Application Insights client to flush the logs it processes.
477482

478-
:::image type="content" source="./media/webjobs-sdk-get-started/logs-in-ai.png" alt-text="Logs in Application Insights.":::
483+
:::image type="content" source="./media/webjobs-sdk-get-started/logs-in-ai.png" alt-text="Screenshot showing how to display and refresh your logs in Application Insights.":::
479484

480485
## Add input/output bindings
481486

482487
Bindings simplify code that reads and writes data. Input bindings simplify code that reads data. Output bindings simplify code that writes data.
483488

484489
### Add bindings
485490

486-
Input bindings simplify code that reads data. For this example, the queue message is the name of a blob, which you'll use to find and read a blob in Azure Storage. You will then use output bindings to write a copy of the file to the same container.
491+
Input bindings simplify code that reads data. For this example, the queue message is the name of a blob, which you use to find and read a blob in Azure Storage. You then use output bindings to write a copy of the file to the same container.
487492

488493
1. In **Functions.cs**, add a `using`:
489494

@@ -532,7 +537,7 @@ Input bindings simplify code that reads data. For this example, the queue messag
532537

533538
1. Select the **Upload** button.
534539

535-
:::image type="content" source="./media/webjobs-sdk-get-started/blob-upload-button.png" alt-text="Screenshot of the Blob upload button.":::
540+
:::image type="content" source="./media/webjobs-sdk-get-started/blob-upload-button.png" alt-text="Screenshot highlighting the Upload button on the blob container screen.":::
536541

537542
1. Find and select *Program.cs*, and then select **OK**.
538543

@@ -544,9 +549,9 @@ Input bindings simplify code that reads data. For this example, the queue messag
544549

545550
1. Create a queue message in the queue you created earlier, with *Program.cs* as the text of the message.
546551

547-
:::image type="content" source="./media/webjobs-sdk-get-started/queue-msg-program-cs.png" alt-text="Queue message Program.cs":::
552+
:::image type="content" source="./media/webjobs-sdk-get-started/queue-msg-program-cs.png" alt-text="Screenshot of the Add message to queue dialog showing the text 'Program.cs' added as message text.":::
548553

549-
1. A copy of the file, *copy-Program.cs*, will appear in the blob container.
554+
1. A copy of the file, *copy-Program.cs*, appears in the blob container.
550555

551556
## Next steps
552557

0 commit comments

Comments
 (0)