I'm trying to find a way to support multiple configurations for nServiceBus from the same installation directory (but running as separate processes). How do folks do this at the moment?
I know that:
- you can programmatically change parameters using
NServiceBus.Configure .With() ... .MsmqTransport() .Configurer.ConfigureComponent<MsmqTransport> (NServiceBus.ObjectBuilder.Component开发者_运维技巧CallModelEnum.None) .ConfigureProperty(x => x.InputQueue, "DynamicInputQueue1") .ConfigureProperty(x => x.ErrorQueue, "DynamicErrorQueue1");
- and you can install multiple "instances" of a service using:
NServiceBus.Host.exe /install /serviceName:xyz /instance:abc
but I'd like to combine the two so the instance name influences which configuration route we take. So I guess it comes down to this - how can I fetch the instance name? Or are there alternative routes I could be taking for this, without resorting to multiple separate installation directories and app.configs per instance?
Thanks
I think from a maintenance standpoint, you may want different directories to make it simple for your administrative folks, but if you want a single directory, you can probably use one of the following methods.
You may want to consider implementing a custom Profile. The Profile name is supplied on the command line and allows you to tweak settings based on the Profile. OOTB NSB has 3 profiles, Lite, Integration, and Production which change settings based on an environment. You could create your own and supply different settings using the Profile. Just implement IProfile and then supply it on the command line.
Another option may be to implement IConfigurationSource and pull data from wherever you decide. This could be multiple files, a database, or something else.
Lastly you could put your configuration into different assemblies and leverage the NSB container to load the appropriate configuration in your bootstrap code above using .With(your list of assemblies here include the correct configuration assembly). This can probably be done implementing IWantToRunAtStartup, but check to make sure you are tweaking the config at the right point in the lifetime of the service.
精彩评论