Skip to content
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

Merged
merged 49 commits into from
Jan 6, 2025
Merged

Add Service Bus emulator support #6737

merged 49 commits into from
Jan 6, 2025

Conversation

sebastienros
Copy link
Member

@sebastienros sebastienros commented Nov 20, 2024

Description

Add support for the Service Bus emulator https://techcommunity.microsoft.com/blog/messagingonazureblog/introducing-local-emulator-for-azure-service-bus/4304457

This PR introduces a custom model to configure the emulator and the cloud service. There is another branch that was based on the CDK directly (and use it for the emulator JSON too) but some discussions led to create a custom, simplified one (not really simplified here for the sake of understanding limits), that is then converted to JSON for the emulator, and to CDK resources for provisioning. If the model is not sufficient (can be on purpose to limit it to what users use in most cases) then the emulator configuration can be defined in JSON directly via WithConfigJson(path), customized with RunAsEmulator(c => c.ConfigJson(JsonNode)), and the CDK resources can be enhanced with the existing ConfigureInfrastructure().

Fixes #6605

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

@sebastienros sebastienros changed the title Sebros/sbemunewmodel Add Service Bus emulator support Nov 20, 2024
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! Nice work here. This is going to be a very useful feature that our customers will enjoy. Let's get it merged.

@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl
Copy link
Member

The functions test is failing

@captainsafia
Copy link
Member

@sebastienros I believe the test failure is related to the key format that we use to inject the connection string for the client integrations:

// Injected to support Aspire client integration for Service Bus in Azure Functions projects.
- target[$"Aspire__Azure__Messaging__ServiceBus__{connectionName}"] = ConnectionStringExpression;
+ target[$"Aspire__Azure__Messaging__ServiceBus__{connectionName}__ConnectionString"] = ConnectionStringExpression;

public bool? RequiresDuplicateDetection { get; set; }

/// <summary>
/// A value that indicates whether the queue supports the concept of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it weird that this property is named "RequiresSession", but the docs say "whether the queue supports the concept of sessions"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming from the CDK ... but independently of it being the correct description or not I wonder if instead of copying the value we could use the <inheritdoc />.

@sebastienros
Copy link
Member Author

Thanks @captainsafia for spotting the issue with the AF functional tests.

@sebastienros sebastienros merged commit 4494825 into main Jan 6, 2025
9 checks passed
@sebastienros sebastienros deleted the sebros/sbemunewmodel branch January 6, 2025 18:24
@huberttrueselftrueme
Copy link

What is a status of this ?

When we can install package ?

@sebastienros
Copy link
Member Author

@huberttrueselftrueme you can follow these instructions to use the nightly builds https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md

@sebastienros
Copy link
Member Author

@londospark the page could be updated but the important data is the nuget feed url: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json

Add this to your sources and you should see the updated versions, example:

https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet9/NuGet/Aspire.Hosting.Azure.ServiceBus/overview/9.1.0-preview.1.25103.7

@kyurkchyan
Copy link

@sebastienros I've pulled the latest nighly version of Aspire, I've created a very basic sample repo with aspire starter template and used the new RunAsEmulator extension method

var serviceBus = builder.AddAzureServiceBus("ServiceBus")
    .RunAsEmulator()
    .ConfigureInfrastructure(infra =>
    {
        var resources = infra.GetProvisionableResources();
        var serviceBus = resources.OfType<ServiceBusNamespace>().Single();
        serviceBus.Name = GetResourceName("asb", infra);
    })
    .WithTopic("aspire",
        topic => { topic.Subscriptions.AddRange([new ServiceBusSubscription("TestSubscription")]); });

When I run the project both on Mac and Windows, I receive the following exception

Unhandled exception. System.ArgumentException: Bind mounts must specify an absolute path. (Parameter 'source')
   at Aspire.Hosting.ApplicationModel.ContainerMountAnnotation..ctor(String source, String target, ContainerMountType type, Boolean isReadOnly) in /_/src/Aspire.Hosting/ApplicationModel/ContainerMountAnnotation.cs:line 33
   at Aspire.Hosting.AzureServiceBusExtensions.<>c__DisplayClass7_0.<RunAsEmulator>b__2(BeforeStartEvent event, CancellationToken ct) in /_/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs:line 351
   at Aspire.Hosting.Eventing.DistributedApplicationEventing.<>c__DisplayClass4_0`1.<<Subscribe>b__0>d.MoveNext() in /_/src/Aspire.Hosting/Eventing/DistributedApplicationEventing.cs:line 82
--- End of stack trace from previous location ---
   at Aspire.Hosting.Eventing.DistributedApplicationEventing.PublishAsync[T](T event, EventDispatchBehavior dispatchBehavior, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Eventing/DistributedApplicationEventing.cs:line 69
   at Aspire.Hosting.DistributedApplication.ExecuteBeforeStartHooksAsync(CancellationToken cancellationToken) in /_/src/Aspire.Hosting/DistributedApplication.cs:line 351
   at Aspire.Hosting.DistributedApplication.RunAsync(CancellationToken cancellationToken) in /_/src/Aspire.Hosting/DistributedApplication.cs:line 310
   at Program.<Main>$(String[] args) in /Users/gagik/Documents/Projects/Learning/Aspire/AspireSample/AspireSample.AppHost/Program.cs:line 37
   at Program.<Main>(String[] args)

Is there any extra configuration that should be done to integrate the emulator support?

@kyurkchyan
Copy link

For anybody that is developing .NET Aspire on mac and will need to use Service Bus Emulator.

Service Bus Emulator is using azure-sql-edge docker image as a dependency. If you are using docker version 4.33.0 you will receive a very strange error and the azure sql edge will crash. Take a look at this comment for more details.

As the comment suggested, I downgraded to docker version 4.33.0, and the issue was resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Service Bus emulator
10 participants