ingenjoren
ingenjoren

Reputation: 87

Is there a way to define a Azure Service Bus rule/filter when setting up a consumer?

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.

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)

Upvotes: 6

Views: 2186

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33457

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 ...");
});

Upvotes: 5

Related Questions