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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

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
/// Converts the current instance to a provisioning entity.
/// </summary>
/// <returns>A <see cref="global::Azure.Provisioning.ServiceBus.ServiceBusTopic"/> instance.</returns>
public global::Azure.Provisioning.ServiceBus.ServiceBusTopic ToProvisioningEntity()
Copy link
Member

Choose a reason for hiding this comment

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

It's unfortunate that we have conflicting type names with Azure.Provisioning. I imagine we will have a lot of users who will reference both and need to disambiguate.

Copy link
Member Author

Choose a reason for hiding this comment

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

we can add a suffix to these types. However looking at the app host we shouldn't need to add usings at all, unless we call ConfigureInfrastructure to get the CDK types.

;

serviceBus
.AddQueue("myQueue", queue =>
Copy link
Member

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?

Copy link

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?

Copy link
Member

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.

var serviceBus = builder.AddAzureServiceBus("sbemulator");

var queue1 = serviceBus.AddQueue("queue1");
// set properties on queue1

var queue2 = serviceBus.AddQueue("queue2");
// set properties on queue2

Copy link
Member Author

Choose a reason for hiding this comment

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

Why doesn't .AddQueue return the Queue, and then you can modify it as you want?

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")

Copy link
Member

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?

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?

public class AzureServiceBusEmulatorResource(AzureServiceBusResource innerResource) : ContainerResource(innerResource.Name), IResource
{
// The path to the emulator configuration file in the container.
internal const string EmulatorConfigJsonPath = "/ServiceBus_Emulator/ConfigFiles/Config.json";
Copy link
Member

Choose a reason for hiding this comment

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

assume this is still WIP as would need a way to supply config.json based ont he docs as well?

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 the internal path for the emulator, this won't change. We do bind your own files to this internal path. Use the WithConfigJson(yourpath) for that. And internally it will bind to this path.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will add another method to configure a JsonObject representing the document in case we want to alter either the generated one of the bound one.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the internal path for the emulator, this won't change. We do bind your own files to this internal path. Use the WithConfigJson(yourpath) for that. And internally it will bind to this path.

Oh, that would be nice to get in for Event Hubs emulator to unblock a few things while the API evolves to match this app model idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, added ConfigureJson in the RunEmulator's lambda.

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
6 participants