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

Support for hierarchical entities #1013

Open
danielmarbach opened this issue Jul 30, 2024 · 0 comments
Open

Support for hierarchical entities #1013

danielmarbach opened this issue Jul 30, 2024 · 0 comments
Labels

Comments

@danielmarbach
Copy link
Contributor

danielmarbach commented Jul 30, 2024

Describe the feature.

Is your feature related to a problem? Please describe.

Azure Service Bus allows entities to be organized in hierarchies on the same namespace. This can be handy to group for example tenant related queues and topics together.

So, for example, you can have a hierarchy like this

tenanta/endpoint1
tenanta/endpoint2
tenantb/endpoint1
tenantb/endpoint2

image

To achieve that, there are a number of "quirks" required on an endpoint configuration level.

The trick is to override the local queue address to contain the hierarchy and make sure the routing table contains the hierarchy too. For separate audit and error queues, you also need to make sure the audit and error queues are configured accordingly.

        var tenantIdentifier = Environment.GetEnvironmentVariable("TenantIdentifier");

        var endpointConfiguration = new EndpointConfiguration($"Endpoint1");
        // Override the local address
        endpointConfiguration.OverrideLocalAddress($"{tenantIdentifier}/Endpoint1");
        endpointConfiguration.EnableInstallers();

        // Override the diagnostic path to have unique paths for endpoint for demo purposes
        endpointConfiguration.SetDiagnosticsPath($".diagnostics/{tenantIdentifier}");

        // configure tenant specific error queue
        endpointConfiguration.SendFailedMessagesTo($"{tenantIdentifier}/error");
        // configure tenant specific audit queue
        endpointConfiguration.AuditProcessedMessagesTo($"{tenantIdentifier}/audit");

        // switch the topology to have a bundle per tenant
        // make sure the subscription doesn't contain illegal characters in the path
        var transport = new AzureServiceBusTransport(connectionString)
        {
            Topology = TopicTopology.Single($"{tenantIdentifier}/bundle1"),
            SubscriptionNamingConvention = subscription => subscription.Replace($"{tenantIdentifier}/", string.Empty)
        };
        var routing = endpointConfiguration.UseTransport(transport);
        // Carefully override each command routing to go to the right destination
        routing.RouteToEndpoint(typeof(Command1), $"{tenantIdentifier}/Endpoint2");

There is currently one downside to this approach. You have to be careful to configure the tenant identifier on all the sends; otherwise you might send to some "central" queue.

SQS as the concept of QueueNamePrefix that is applied on a transport level, which makes "isolating" the same endpoints on the same SQS account a breeze and doesn't require changing the routing tables, error and audit queues.

Describe the requested feature

Add a possibility to leverage hierarchies to facilitate grouping of the same endpoints within a hierarchy.

Describe alternatives you've considered

None

Additional Context

Sample implementation

TenantsWithAsbUsingHierarchy.zip

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

No branches or pull requests

1 participant