Configure UniCastBus in NServiceBus using IWantToRunBeforeConfigurationIsFinalized

StackOverflow https://stackoverflow.com/questions/21735127

  •  10-10-2022
  •  | 
  •  

I would like to "hook in" and tweak configuration to UnicastBus and was looking at doing this using IWantToRunBeforeConfigurationIsFinalized.

I would like to tweak/set the value for: ForwardReceivedMessagesTo. Any ideas on how that should be done?

有帮助吗?

解决方案

Unfortunately due to a bug (see https://github.com/Particular/NServiceBus/issues/1960), the only possible way is to programmatically replace the whole UnicastBusConfig, eg:

class Foo : IProvideConfiguration<UnicastBusConfig>
{
    public UnicastBusConfig GetConfiguration()
    {
        var unicastBusConfig = new UnicastBusConfig
        {
            ForwardReceivedMessagesTo = "FooBar",
        };
        unicastBusConfig.MessageEndpointMappings = new MessageEndpointMappingCollection();
        unicastBusConfig.MessageEndpointMappings.Add(...);

        return unicastBusConfig;
    }
}

But that is quite ugly :(

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top