Masstransit: Subscription rules/filters?

Created on 11 Jan 2017  路  15Comments  路  Source: MassTransit/MassTransit

Hi

Azure Service Bus has this thing called Rules on a subscription, so two subscribers can subscribe to the same topic, but the first one only gets messages where Message.SomeProperty == "apple" and the other one only gets the "bananas".

This filtering isn't done by the subscribers, but takes place within ASB itself, so it's actually routing.

Can this be done with Masstransit?

Thanks

azure-servicebus

Most helpful comment

It cannot presently be configured using MassTransit, but it's one of the things I've look at making possible. The SubscriptionEndpoint in MassTransit will evolve at some point to allow the subscription to be configured in such a way.

All 15 comments

It cannot presently be configured using MassTransit, but it's one of the things I've look at making possible. The SubscriptionEndpoint in MassTransit will evolve at some point to allow the subscription to be configured in such a way.

This could be extremely helpful to those of us who like to penny pinch on Azure costs. Currently need each developer to have their own service bus instance so they don't accidentally pick up each others messages.

only $10 a month per developer, but it does add up.

We have a similar scenario where this would help SO... TL/DR +1 .

We are designing an app where separating customer data is super important, but we can't deploy a service bus per customer site install as there is an Azure limit of 100 service bus namespaces per Azure subscription.
We have thought about going CloudAMPQ and using VHosts, but its a preference to stick with Azure SB for a few reasons including data sensitivity (PHI) and that everything else we are doing in the cloud is Azure PaaS.

I hence created (aka hacked in :) ) a POC in the MT source creating a correlation filter on the topic's subscription to correlate a message to a customer (filtering on the TO field, picked at random as it is not used). Then I modified the message send to populate the TO field on a message with a matching key. Worked a treat.
But it would be lovely if this was out-of-the-box :)

@mjpearse care to share code? I don't need a prod ready solution just something to help devs a bit.

maybe we can get something started in thsi area.

@bzbetty Sorry for massive delay, saw this in an old email. This is a total hack but as you asked, we haven't used this at all was POCing about. It worked, though :)

_Topic Subscription creation...._
Customised ServiceBusHost.cs, CreateTopicSubscription method in Masstransit to pick up a configuration key.
Edited line
subscriptionDescription = await RootNamespaceManager.CreateSubscriptionAsync(description, new CorrelationFilter { To = THEKEYSVALUE}).ConfigureAwait(false);

_For when a message is sent...._
Customised TopicSendClient.cs Send method to populate the To property on the message getting sent to match the subscription's CorrelationFilter.

Use of the To property on the subscription was arbitrary, it could have been any unused property.

Any update on this ? I need also to specify a rule on a topic subscription but MassTransit still don't have functionality for this.

Nobody has worked on it yet.

Yes, it's in the latest release.

Could give an example of proper usage ?
I tried e.g :
cfg.SubscriptionEndpoint(host, "test", "test", x => { x.Rule = new RuleDescription { Name = "test", Filter = new SqlFilter("test= 'test'"))}; });

or

cfg.SubscriptionEndpoint(host, "test", "test", x => { x.Filter = new SqlFilter("test= 'test'") });

Nothing works unfortunately

@JakubSurfer I honestly don't have a clue, are you using the original package (AzureServiceBus) or the new one for .NET core?

I use the original MassTransit.AzureServiceBus package v5.1.4

@JakubSurfer What is the correct syntax to add a rule these days, with the new package?

I think you should try syntax from my older post :
cfg.SubscriptionEndpoint(host, "test", "test", x => { x.Rule = new RuleDescription { Name = "test", Filter = new SqlFilter("test= 'test'"))}; });

or

cfg.SubscriptionEndpoint(host, "test", "test", x => { x.Filter = new SqlFilter("test= 'test'") });

@JakubSurfer Thanks!

@JakubSurfer, I'm a bit confused about how to publish targeting different subscribers. like subscriber A accepts message where "test='a'" and B accepts message where "test = 'b'". Now, how to publish these messages?
Could you please help me with an example please. thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phatboyg picture phatboyg  路  6Comments

eggertcosta picture eggertcosta  路  4Comments

gschuager picture gschuager  路  7Comments

kirill-gerasimenko picture kirill-gerasimenko  路  4Comments

icsharp picture icsharp  路  4Comments