2

First of all, excuse my English, it's very bad. I am using MassTransit with Azure Service Bus for asynchronous communication between microservices. In my project I need to exclude some types of messages so that they are not created as topics. I have seen the section of the documentation (https://masstransit-project.com/releases/v7.0.4.html#rabbitmq-azure-service-bus) where this problem is discussed, and two methods are exposed, through an attribute in the class / interface, or through a method in the topology configuration.

Option 1

[ExcludeFromTopology]
public interface IEvent
{
    Guid TransactionId { get; }
}

Option 2

Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    cfg.Publish<IEvent>(p => p.Exclude = true);
});

My problem is that neither of the two methods works for me because some interfaces to exclude are in other libraries and I have no way to add the attribute to these types. Also, I can't add these types statically in the topology configuration either, because these types are not known before runtime. The idea would be to be able to have a method equivalent to the generic but not generic, but with a 'Type' parameter that configures this type to be excluded from the typology. Something like that:

Example

var faultType = typeof(Fault<>).MakeGenericType(concreteAggregateType);
var ieventType = typeof(IEvent);
Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    cfg.Publish(faultType, p => p.Exclude = true);
    cfg.Publish(ieventType, p => p.Exclude = true);
});

Also throughout my use of Mastransit I have found at various points with functionalities designed to be used in a generic way but that do not have a non-generic equivalent. Another example is the EndpointConvention.Map<>() method.

In the end I can't make a dynamic selection of the types to configure at runtime, it prevents me from doing something like this:

Example

IList<Type> typesToExcludeFromTopology = GetTypesToExcludeFromTopology(assembly);
Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    typesToExcludeFromTopology.ForEach(t => cfg.Publish(t, p=> p.Exclude = true));
});

Is there an alternative way for this problem?

Thank you. Greetings, Borja

  • 1
    Is it cool to [link my own answer](https://stackoverflow.com/questions/1606966/generic-method-executed-with-a-runtime-type/1606988#1606988) to calling generic methods with runtime types? – Chris Patterson May 11 '21 at 22:08
  • hahaha yeah, it's very cool! Thanks for this workaround. It is very useful. Greetings – Borja Fernández May 12 '21 at 20:50

0 Answers0