Skip to content

Revise tutorials to use Aspire Starter App in VS (to match VSCode directions) #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b792636
VS Code toolings bits (#886)
IEvangelist May 14, 2024
eea93ab
Drop (Preview), let's go!
IEvangelist May 14, 2024
1e0ec80
Bump to GA versions, and drop --prerelease (#899)
IEvangelist May 14, 2024
43a24c0
Disabiguate hosting and components. Fixes #801
IEvangelist May 15, 2024
bde3f01
Merge branch 'main' into ga-build
IEvangelist May 15, 2024
2f4758a
Fix issue #820
IEvangelist May 15, 2024
c1e76aa
Fix issue #844
IEvangelist May 15, 2024
bd8b495
Fix issue #924
IEvangelist May 15, 2024
3f35abf
Fix issue #834
IEvangelist May 15, 2024
4398543
Fix issue #814
IEvangelist May 15, 2024
0b12bbc
Wording clean up
IEvangelist May 15, 2024
431ba28
Troubleshooting bits (#900)
IEvangelist May 15, 2024
afb5645
Fix issue #821
IEvangelist May 16, 2024
5bbb9df
Drop preview for VS
IEvangelist May 16, 2024
0f47015
Update some images
IEvangelist May 16, 2024
a8f2cbc
Update login URL with v8
IEvangelist May 16, 2024
87950e8
Update theme images
IEvangelist May 16, 2024
1135771
Update theme images correctly
IEvangelist May 16, 2024
1a42344
Update dashboard screen captures
IEvangelist May 16, 2024
50965a0
Update hub page
IEvangelist May 16, 2024
7637a7d
remove more preview content, set vs version
IEvangelist May 16, 2024
407acd4
Correct vs screen capture version
IEvangelist May 16, 2024
6d8c473
Several more updates
IEvangelist May 16, 2024
917302c
Added training links
IEvangelist May 16, 2024
3728b84
Fix issue #721
IEvangelist May 17, 2024
b21d1d3
Updated init steps and up workflow (#930)
alexwolfmsft May 17, 2024
5b55c14
Rework TOC (#928)
IEvangelist May 17, 2024
efb4132
GA logo (#931)
IEvangelist May 17, 2024
eef29ae
[DRAFT] Dapr content (#894)
IEvangelist May 17, 2024
fa16a20
Let's try a few updates for the TOC (#932)
IEvangelist May 17, 2024
85ab237
Add description of web project
CamSoper May 17, 2024
1a8df22
Merge remote-tracking branch 'origin/ga-build' into camsoper/889
CamSoper May 17, 2024
ff5834f
wip
CamSoper May 22, 2024
f10f2a4
Merge remote-tracking branch 'origin/main' into camsoper/889
CamSoper May 22, 2024
5e19ebd
revert broken file
CamSoper May 22, 2024
7425b31
rename file
CamSoper May 22, 2024
6dee02b
lint fixes
CamSoper May 22, 2024
1e8121c
fix spacing hopefully
CamSoper May 22, 2024
be52b3d
troubleshooting includes in lists
CamSoper May 22, 2024
bc4d207
I give up
CamSoper May 22, 2024
e2072a8
Update snippets app
CamSoper May 22, 2024
8d2f89c
doc updates
CamSoper May 22, 2024
696f3c4
Missed a snippet
CamSoper May 22, 2024
b17e3a3
Fixed per request
CamSoper May 23, 2024
96480fb
Caught typo
CamSoper May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/media/messaging-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 24 additions & 44 deletions docs/messaging/messaging-components.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Use .NET Aspire messaging components in ASP.NET Core
description: Learn how to connect an ASP.NET Core app to messaging services using .NET Aspire components.
ms.date: 05/14/2024
ms.date: 05/22/2024
ms.topic: tutorial
---

Expand All @@ -28,10 +28,10 @@ Alternatively:
- **Azure CLI**: Run the following commands in the Azure CLI or CloudShell to set up the required Azure Service Bus resources:

```azurecli-interactive
az group create -n <your-resource-group-name> -location eastus
az group create -n <your-resource-group-name> --location eastus
az servicebus namespace create -g <your-resource-group-name> --name <your-namespace-name> --location eastus
az servicebus topic create --g <your-resource-group-name> --namespace-name <your-namespace-name> --name notifications
az servicebus topic subscription create --g <your-resource-group-name> --namespace-name <your-namespace-name> --topic-name notifications --name mobile
az servicebus topic create -g <your-resource-group-name> --namespace-name <your-namespace-name> --name notifications
az servicebus topic subscription create -g <your-resource-group-name> --namespace-name <your-namespace-name> --topic-name notifications --name mobile
```

> [!NOTE]
Expand Down Expand Up @@ -67,19 +67,13 @@ Create a .NET Aspire app using either Visual Studio or the .NET CLI.
Visual Studio provides app templates to get started with .NET Aspire that handle some of the initial setup configurations for you.

1. At the top of Visual Studio, navigate to **File** > **New** > **Project**.
1. In the dialog window, search for *ASP.NET Core* and select **ASP.NET Core Web API**. Choose **Next**.
1. In the dialog window, search for *Aspire* and select **.NET Aspire Starter Application**. Choose **Next**.
1. On the **Configure your new project** screen:
- Enter a **Project Name** of **AspireMessaging**.
- Enter a **Solution Name** of **AspireMessaging**.
- Leave the rest of the values at their defaults and select **Next**.
1. On the **Additional information** screen:
- Make sure **.NET 8.0** is selected.
- Ensure that **Enlist in Aspire orchestration** is checked and select **Next**.

Visual Studio creates a new ASP.NET Core solution that is structured to use .NET Aspire. The solution consists of the following projects:

- **AspireMessaging** - An API project with default .NET Aspire service configurations.
- **AspireMessaging.AppHost** - An orchestrator project designed to connect and configure the different projects and services of your app. The orchestrator should be set as the startup project.
- **AspireMessaging.ServiceDefaults** - A shared class library to hold code that can be reused across the projects in your solution.
- Uncheck **Use Redis for caching** (not required for this tutorial).
- Select **Create**.

## [.NET CLI](#tab/dotnet-cli)

Expand All @@ -89,13 +83,14 @@ Use the [`dotnet new`](/dotnet/core/tools/dotnet-new) command to create a new .N
dotnet new aspire-starter --name AspireMessaging
```

---

The solution consists of the following projects:

- **AspireMessaging** - An API project with default .NET Aspire service configurations.
- **AspireMessaging.ApiService** - An API project with default .NET Aspire service configurations.
- **AspireMessaging.AppHost** - An orchestrator project designed to connect and configure the different projects and services of your app. The orchestrator should be set as the startup project.
- **AspireMessaging.ServiceDefaults** - A shared class library to hold code that can be reused across the projects in your solution.

---
- **AspireMessaging.Web** - A Blazor Server project that serves as the front end for the app.

### Add the Worker Service project

Expand Down Expand Up @@ -152,7 +147,7 @@ The completed solution structure should resemble the following:

## Add the .NET Aspire component to the API

Add the [.NET Aspire Azure Service Bus](azure-service-bus-component.md) component to your `AspireMessaging` app:
Add the [.NET Aspire Azure Service Bus](azure-service-bus-component.md) component to your `AspireMessaging.ApiService` app:

```dotnetcli
dotnet add package Aspire.Azure.Messaging.ServiceBus
Expand Down Expand Up @@ -201,7 +196,7 @@ In the _:::no-loc text="appsettings.json":::_ file of the `AspireMessaging` proj

## Create the API endpoint

The API must provide an endpoint to receive data and publish it to the Service Bus topic and broadcast to subscribers. Add the following endpoint to the `AspireMessaging` project to send a message to the topic:
The API must provide an endpoint to receive data and publish it to the Service Bus topic and broadcast to subscribers. Add the following endpoint to the `AspireMessaging.ApiService` project to send a message to the Service Bus topic. Place this code in _Program.cs_ before the `app.MapDefaultEndpoints()` call:

```csharp
app.MapPost("/notify", static async (ServiceBusClient client, string message) =>
Expand All @@ -225,7 +220,7 @@ app.MapPost("/notify", static async (ServiceBusClient client, string message) =>
await sender.SendMessagesAsync(messageBatch);

Console.WriteLine($"A message has been published to the topic.");
})
});
```

## Add the .NET Aspire component to the Worker Service
Expand All @@ -239,7 +234,7 @@ dotnet add package Aspire.Azure.Messaging.ServiceBus
In the _:::no-loc text="Program.cs":::_ file of the `AspireMessaging.WorkerService` Razor Pages project, add a call to the `AddAzureServiceBus` extension methods:

```csharp
builder.AddAzureServiceBus("serviceBusConnection");
builder.AddAzureServiceBusClient("serviceBusConnection");
```

This method accomplishes the following tasks:
Expand Down Expand Up @@ -335,32 +330,17 @@ public class Worker(

The sample app is now ready for testing. Verify that the data submitted to the API is sent to the Azure Service Bus topic and consumed by the subscriber worker service:

## [Visual Studio](#tab/visual-studio)

1. Press the run button at the top of Visual Studio to launch your Aspire app. The .NET Aspire dashboard app should open in the browser.
1. On the resources page, in the **aspireweb** row, click the link in the **Endpoints** column to open the Swagger UI page of your API.
1. On the .NET Aspire dashboard, navigate to the logs for the **AspireWorkerService** project.
1. Back on the Swagger UI page, expand the **/notify** endpoint and select **Try it out**.
1. Enter a test message in the **message** input box.
1. Select **Execute** to send a test request.
1. Switch back to the **AspireWorkerService** logs. You should see the test message printed in the output logs.

## [.NET CLI](#tab/dotnet-cli)
1. Launch the Aspire app by selecting the run button (Visual Studio) or running `dotnet run --project AspireMessaging.AppHost`. The .NET Aspire dashboard app should open in the browser.
1. On the resources page, in the **apiservice** row, find the link in the **Endpoints** that opens the `weatherforecast` endpoint. Note the HTTPS port number.
1. On the .NET Aspire dashboard, navigate to the logs for the **aspiremessaging-workerservice** project.
1. In a terminal window, use the `curl` command to send a test message to the API:

1. In a terminal window at the root of your project, use the `dotnet run` command to start the app:

```csharp
dotnet run --project AspireMessaging.AppHost
```bash
curl -X POST -H "Content-Type: application/json" https://localhost:{port}/notify?message=hello%20aspire
```

1. On the resources page, in the **aspireweb** row, click the link in the **Endpoints** column to open the Swagger UI page of your API.
1. On the .NET Aspire dashboard, navigate to the logs for the **AspireWorkerService** project.
1. Back on the Swagger UI page, expand the **/notify** endpoint and select **Try it out**.
1. Enter a test message in the **message** input box.
1. Select **Execute** to send a test request.
1. Switch back to the **AspireWorkerService** logs. You should see the test message printed in the output logs.

---
Be sure to replace **{port}** with the port number from earlier.
1. Switch back to the **aspiremessaging-workerservice** logs. You should see the test message printed in the output logs.

Congratulations! You created and configured an ASP.NET Core API that connects to Azure Service Bus using Aspire components.

Expand Down
Loading
Loading