Endpoint config in code or app.config...what is best practice

Hi,
I doing a POC for a simple pub-sub. The sample i have found create endpointconfiguration using hard coded config values (i.e., queue name, transport, persistence etc). Isn’t it better to configure those in config file so that we can create seperate config file for Dev/Test/Prod environment? My plan is to deply those as Windows service.
Could you please send me link of any suitable sample that show this?
Also, any document to help to deploy the service in Dev/Test server.
Cheers,
Maz

Hi Maz,

Our samples try to focus on the least amount of things to keep a sample small and focused. That is why we want our customer to see all essential bits in one code section for an easy understanding whenever possible.

Yes, for some configuration values it makes sense to not hardcode these. This is just a matter of passing app setting and connection string values to your own liking to via the ConfigurationManager.

You state that you are considering hosting your endpoints as windows service. We recommend that you self-host your endpoint using code similar to the following sample:

Such a windows service can be installed easily via powershell or the command line

If you are looking for a way to automate your deployments. We are not affiliated with Octopus Deploy but that is a nice environment to do automated deployments. You can define different stating environments to which you can deploy your components.

Octopus Depoy deploys each version into its own new folder. In order for our platform tools to you do need to override the host identifier as shown in the following guidance:

We do not have any specific guidance on using octopus deploy but a lot of useful information can be found via google:

Regards,
Ramon

1 Like

Hi Ramon,
Thank you very much for your reply.
Is there any configuration (i.e., setting sql persistence using config file only,no code) that NSB read directly from config file instead of reading using ConfigurationManager and using that in code?
Could you please provide me if there is any production standard sample or project?
Regards,
Mazhar

Hi Ramon,
could you please provide link of a sample that used config values from config file? What is the best practices to configure NSB?
Regards,
Maz

Hi Maz,

From version 6 and onwards we are focussing on our code API to configure NServiceBus. It is up to you to decide if you want to store most configuration values as app settings, command line arguments, environment variables, an ini file, in the registry or maybe in a database.

Appsettings example:

var ci = System.Globalization.CultureInfo.InvariantCulture;
var settings = System.Configuration.ConfigurationManager.AppSettings;

NServiceBus.Logging.LogManager
    .Use<NServiceBus.Logging.DefaultFactory>()
    .Level((NServiceBus.Logging.LogLevel)Enum.Parse(typeof(NServiceBus.Logging.LogLevel), settings["NServiceBus/LogLevel"]));

endpointConfiguration.SetTimeToKeepDeduplicationData(TimeSpan.Parse(settings["NServiceBus/Outbox/SetTimeToKeepDeduplicationData"], ci));
endpointConfiguration.ForwardReceivedMessagesTo(settings["NServiceBus/ForwardReceivedMessagesTo"]);
endpointConfiguration.SendFailedMessagesTo(settings["NServiceBus/SendFailedMessagesTo"]);
endpointConfiguration.LimitMessageProcessingConcurrencyTo(int.Parse(settings["NServiceBus/LimitMessageProcessingConcurrencyTo"], ci));

This is just one of many options and every system being build has different requirements on how to store configuration value.

Does that help?

Regards,
Ramon

Hi Ramon,

Thank you very much for your support.

I have another query. I am planning to deploy both of my publisher and subscriber as Windows Service (i am following the way shown in NSB sample). Do I need to deploy/install NSB on the Test/Prod servers ? Or Is it OK to deploy the service using Service Control tool (SC.exe)?

Regards,
Maz

I think your question is if you should be using the NServiceBus.Host or if you should be self-hosting. Our current recommendation for windows services is to use self-hosting as documented at the following location:

The easiest way to install such an application is via sc.exe or via Powershell.

By using this approach you have much more flexibility and control over everything you want to do.

Regards,
Ramon

Hi Ramon,

Thanks. I wanted to know if i need to separately install any NSB component on the server box other than hosting it as Windows Service. I think not required but just to confirm.

Regards,
Maz

Hi Maz,

NServiceBus is a library that is deployed together with your application.

Our platform tools ServiceControl, ServicePulse, and ServiceInsight are installed separately.

The following link gives an overview of our platform

Does that help?

Regards,
Ramon