-
Notifications
You must be signed in to change notification settings - Fork 480
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
Add Service Bus emulator support #6737
Open
sebastienros
wants to merge
19
commits into
main
Choose a base branch
from
sebros/sbemunewmodel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,214
−45
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f956d0d
wip
sebastienros 000b32f
It's alive
sebastienros c6fdaca
Add healthchecks
sebastienros 1561028
Merge remote-tracking branch 'origin/main' into sebros/sbemu
sebastienros 8ecc4fd
React to breaking changes
sebastienros 698faae
Create common model for emulator and cdk
sebastienros e22e309
Merge branch 'main' into sebros/sbemunewmodel
sebastienros 63dae9e
Remove unnecessary !
sebastienros 9e3ae51
Update src/Aspire.Hosting.Azure.ServiceBus/ApplicationModel/OptionalV…
sebastienros 0a971eb
Remove OptionalValue<T>
sebastienros 8f8281d
PR feedback
sebastienros fd1a4b2
Revert API breaking changes
sebastienros 12c6214
Ad callback to update json configuration
sebastienros af5ff57
Add tests
sebastienros 781c595
Fix breaking changes
sebastienros 340b389
Add comments for CDK and Emulator discrepancies
sebastienros 4725b38
Fix API descriptions
sebastienros 59b6ea4
Fix breaking change
sebastienros cf46faf
Clean delta
sebastienros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Text.Json.Nodes; | ||
|
||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var serviceBus = builder.AddAzureServiceBus("sbemulator"); | ||
|
||
serviceBus | ||
.AddQueue("myQueue", queue => | ||
{ | ||
queue.Name = "queue.1"; | ||
queue.DeadLetteringOnMessageExpiration = false; | ||
queue.DefaultMessageTimeToLive = TimeSpan.FromHours(1); | ||
queue.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromSeconds(20); | ||
queue.ForwardDeadLetteredMessagesTo = ""; | ||
queue.LockDuration = TimeSpan.FromMinutes(1); | ||
queue.MaxDeliveryCount = 10; | ||
queue.RequiresDuplicateDetection = false; | ||
queue.RequiresSession = false; | ||
}) | ||
//.AddTopic("myTopic", topic => | ||
//{ | ||
// topic.Name = "topic.1"; | ||
// topic.DefaultMessageTimeToLive = TimeSpan.FromHours(1); | ||
// topic.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromSeconds(20); | ||
// topic.RequiresDuplicateDetection = false; | ||
//}) | ||
//.AddSubscription("myTopic", "mySubscription", sub => | ||
//{ | ||
// sub.Name = "subscription.1"; | ||
// sub.DeadLetteringOnMessageExpiration = false; | ||
// sub.DefaultMessageTimeToLive = TimeSpan.FromHours(1); | ||
// sub.LockDuration = TimeSpan.FromMinutes(1); | ||
// sub.MaxDeliveryCount = 10; | ||
// sub.ForwardDeadLetteredMessagesTo = ""; | ||
// sub.RequiresSession = false; | ||
//}) | ||
//.AddRule("myTopic", "mySubscription", "myRule", rule => | ||
//{ | ||
// rule.Name = "app-prop-filter-1"; | ||
// rule.CorrelationFilter = new() | ||
// { | ||
// ContentType = "application/text", | ||
// CorrelationId = "id1", | ||
// Subject = "subject1", | ||
// MessageId = "msgid1", | ||
// ReplyTo = "someQueue", | ||
// ReplyToSessionId = "sessionId", | ||
// SessionId = "session1", | ||
// SendTo = "xyz" | ||
// }; | ||
//}) | ||
; | ||
|
||
serviceBus.RunAsEmulator(configure => configure.ConfigureJson(document => | ||
{ | ||
document["UserConfig"]!["Logging"] = new JsonObject { ["Type"] = "Console" }; | ||
})); | ||
|
||
builder.AddProject<Projects.ServiceBusWorker>("worker") | ||
.WithReference(serviceBus).WaitFor(serviceBus); | ||
|
||
builder.Build().Run(); |
45 changes: 45 additions & 0 deletions
45
playground/AzureServiceBus/ServiceBus.AppHost/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
|
||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:15887;http://localhost:15888", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16175", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17037", | ||
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15888", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17038", | ||
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true", | ||
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true" | ||
} | ||
}, | ||
"generate-manifest": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"dotnetRunMessages": true, | ||
"commandLineArgs": "--publisher manifest --output-path aspire-manifest.json", | ||
"applicationUrl": "http://localhost:15888", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175" | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
playground/AzureServiceBus/ServiceBus.AppHost/ServiceBus.AppHost.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
sebastienros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>c12f723f-2545-4f8f-8c3b-fb7bdeadbd55</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" /> | ||
<AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.ServiceBus" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ServiceBusWorker\ServiceBusWorker.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
playground/AzureServiceBus/ServiceBus.AppHost/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
playground/AzureServiceBus/ServiceBus.AppHost/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Aspire.Hosting.Dcp": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text; | ||
using Azure.Messaging.ServiceBus; | ||
|
||
namespace ServiceBusWorker; | ||
|
||
internal sealed class Consumer(ServiceBusClient client, ILogger<Consumer> logger) : BackgroundService | ||
{ | ||
protected override async Task ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
var processor = client.CreateProcessor("queue.1", new ServiceBusProcessorOptions | ||
{ | ||
AutoCompleteMessages = true, | ||
MaxConcurrentCalls = 1, // Process one message at a time | ||
}); | ||
|
||
// Whenever a message is available on the queue | ||
processor.ProcessMessageAsync += MessageHandler; | ||
|
||
processor.ProcessErrorAsync += ErrorHandler; | ||
|
||
await processor.StartProcessingAsync(cancellationToken); | ||
} | ||
|
||
private static Task MessageHandler(ProcessMessageEventArgs args) | ||
{ | ||
// Process the message | ||
Console.WriteLine($"Received message: {Encoding.UTF8.GetString(args.Message.Body)}"); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private Task ErrorHandler(ProcessErrorEventArgs args) | ||
{ | ||
logger.LogError(args.Exception, "Error processing message"); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public override Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Stopping consumer..."); | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using Azure.Messaging.ServiceBus; | ||
|
||
namespace ServiceBusWorker; | ||
|
||
internal sealed class Producer(ServiceBusClient client, ILogger<Producer> logger) : BackgroundService | ||
{ | ||
protected override async Task ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Starting producer..."); | ||
|
||
await using var sender = client.CreateSender("queue.1"); | ||
|
||
var periodicTimer = new PeriodicTimer(TimeSpan.FromSeconds(5)); | ||
|
||
while (!cancellationToken.IsCancellationRequested) | ||
{ | ||
await periodicTimer.WaitForNextTickAsync(cancellationToken); | ||
|
||
await sender.SendMessageAsync(new ServiceBusMessage($"Hello, World! It's {DateTime.Now} here."), cancellationToken); | ||
} | ||
} | ||
|
||
public override Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Stopping producer..."); | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using ServiceBusWorker; | ||
|
||
var builder = Host.CreateApplicationBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
builder.AddAzureServiceBusClient("sbemulator"); | ||
|
||
Console.WriteLine("ServiceBus producer/consumer test"); | ||
|
||
builder.Services.AddHostedService<Consumer>(); | ||
Console.WriteLine("Starting Service Bus consumer..."); | ||
|
||
builder.Services.AddHostedService<Producer>(); | ||
Console.WriteLine("Starting Service Bus producer..."); | ||
|
||
var host = builder.Build(); | ||
|
||
await host.RunAsync(); |
12 changes: 12 additions & 0 deletions
12
playground/AzureServiceBus/ServiceBusWorker/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"WorkerService1": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
playground/AzureServiceBus/ServiceBusWorker/ServiceBusWorker.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>9c946452-f682-49a4-9209-29ed63174447</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AspireProjectOrPackageReference Include="Aspire.Azure.Messaging.ServiceBus" /> | ||
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
playground/AzureServiceBus/ServiceBusWorker/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use a callback API pattern here? Why doesn't
.AddQueue
return the Queue, and then you can modify it as you want?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eerhardt In this case we would need to return an object that combines behavior of
IResourceBuilder<AzureServiceBusResource>
with what you are describing so that we could either modify the specified queue or start to specify a different queue or topic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(full disclosure, I'm not a super fan of fluent APIs)
If you want to start to specify a different queue, you would start a new code line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change. Is that something we'd want? But we could then reference the resources when building the model, or do
topic.AddSubscription("sub.1")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way we could make it without a breaking change? A new method name?
AddServiceBusQueue
?cc @mitchdenny @davidfowl - thoughts on using callbacks in the API this way?