Polymorphic routing in NServiceBus's Azure Service Bus Transport version 6, how to do without enumerating all concrete types?

15 hours ago 1
ARTICLE AD BOX

We are trying to upgrade from NServiceBus 8 to NServiceBus 10, and along with it comes the new topology for the Azure Service Bus transport. We are running into some issues with how to migrate from the single-topic topology to the topic-per-event topology.

Our setup is roughly as follows. We have a base event class for when a product is ordered:

public class ProductOrdered : IEvent { public int OrderId { get; set; } }

For different product groups within our portfolio, we derive this type to include more specific properties.

We then have two types of subscribers:

Subscribers that are just interested in SomeConcreteProductOrdered event, and thus implement IHandleMessages<SomeConcreteProductOrdered>. Subscribers that don't need to know all the specifics of the different product groups, and just care about any ProductOrdered. These would implement IHandleMessages<ProductOrdered>.

According to the docs, the way to support this kind of polymorphism is to specify on the subscriber which queues to listen to:

topology.SubscribeTo<ProductOrdered>("SomeConcreteProductOrdered"); topology.SubscribeTo<ProductOrdered>("AnotherConcreteProductOrdered");

However, this would require us to fully enumerate the various implementations of ProductOrdered. Something that might change over time and would require maintaining in multiple places, but most of all also something that until now those subscribers had no business of knowing.

So we're left wondering, is there another way to set this up so that we don't have to enumerate all concrete implementations of this base class in consuming endpoints?

We were thinking about either having the publishing endpoints publish the message to both the SomeConcreteProductOrdered topic and to a ProductOrdered topic, so that the different consumers can just listen to the topics according to their IHandleMessages<T> implementations.

An alternative would be to create a subscription from the SomeConcreteProductOrdered topic to the ProductOrdered topic (basically rebuilding the inheritance tree in topics and subscriptions), but we were wondering whether it's possible to use endpoint installlers to automatically provision these resources.

Read Entire Article