5

I'm exploring my options when introducing Azure Service Bus with MassTransit in a multi-tenant system.

Basically the system consists of several services which some of them are tenant specific whilst some are shared.

  • Services keep data internally (tenant data is isolated).
  • Each tenant runs the same set of services, just their own instances of them.
  • Tenant should never consume each others data.

So far, creating a separate Azure Service Bus Namespace for each tenant seems like the safest option, although it complicates consuming in shared services.

I have considered using the GreenPipe filters but since those operate on the cosnumer level, from what I understand, there would be a considerable number of messages that just reaches the queue and gets discarded. I think however I would like to use a tenant filter nevertheless for extra safety.

I read about the topic filters concept in Azure Service Bus. From what I understand, it operate on the subscription level and the message would not be copied to the queue unless it passes that filter.

Currently, I setup my consumers like this:

cfg.ReceiveEndpoint(host, "customer_update_queue", e =>
{
  e.Consumer(() => new YourConsumer());
}

Is there a way to specify a topic subscription filter here?

(I'm also happy to know if I overlook some other option)

ingenjoren
  • 77
  • 6

1 Answers1

4

If you use a SubscriptionEndpoint, you can specify a Rule and Filter using the configurator:

cfg.SubscriptionEndpoint(..., cfg => cfg.Rule)

If you use a ReceiveEndpoint, you can manually subscribe topics and specify the rule/filter as well:

configurator.ConfigureConsumeTopology = false;
configurator.Subscribe<PingMessage>("johnson", x =>
{
    x.Rule = new RuleDescription();
    x.Filter = new SqlFilter("SELECT ...");
});
Chris Patterson
  • 28,659
  • 3
  • 47
  • 59