Neuron has a quite powerful and sometimes overlooked feature to securely store environment specific configurations such as URLs, Access Control lists and other parameters. And since we have experienced several customers that were not aware of this, we thought we would write a quick blog post.

Deployment Groups
When you initially create a new Neuron Solution, there will be only one Deployment Group named after your machine name:

Working in a multi-developer setup, we recommend renaming this to localhost or development. Additionaly then create Deployment Groups for your other environments:

Do not worry, if you do not know all relevant environments. They can easily be added later.

Now, to set the active Deployment Group, choose ‘Configure Server’ from Neuron ESB Explorer and select the desired group. This will take effect once you restart the service.

(If you need to set it programmatically as part of Deployment or for other reasons, this is stored in the ESBService.exe.config in the Neuron instance, eg. C:\Program Files\Neudesic\Neuron ESB v3\DEFAULT)

Environment Variables
Next, we create the environment variables for our services. In this example it is the URL to an external service.

We prefer to name it after the artifact where it is used with a suiting postfix, so if we are creating a parameter for a ‘ExternalSystem.GetCusomer.RestEndpoint’, then name it ‘ExternalSystem.GetCusomer.RestEndpoint.url’.

Create the variable and supply the values for the different environments/deployment groups.

Binding the variables to endpoints
Before using environment variables, be sure to save the Neuron ESB configuration. This will refresh the ESB Explorer. Then open the relevant service and click the Bindings button:

This will bring up the Bindings-dialog:

As you can see, you can bind several parameters. In this case, we chose Service Connector Url and hit CTRL-Space which will bring up the list of all environment variables. Choose the correct one, hit enter and then save.

Now, the URL will be the one for the active deployment group.

Using environment variables in processes
Accessing environment variables in a process is quite simple. From a C# code step, you simple access the context.EnvironmentVariables dictionary.

To test this, create a new Process and add a C# code step with the following content:

Now click Test Process (the green arrow) and here you can select which set of Environment Variables to use with the ‘Environment Variables’ button.

Click ok, and you should now see the relevant URL in the output window.

Using environment variables in workflows
You can also access environment variables in workflows. Default it is part of the arguments passed to workflows and you then use this dictionary.

And if your are calling processes from within workflows that need to access the Environment variables as well, be sure to set the EnvironmentVariables property:

Check if all values have been set
Before deploying it is always a good idea to check if all values have been set. This can be quickly be done by choosing the Deployment Group and then the Environment tab:

Custom patching of Environment Variables
Usually there should not be any need to patch the Neuron XML files, but in special cases, this can easily be done.

The values for the various Deployment Groups are stored in the DeploymentGroups folder below the ESB Configuration Folder.

Here you will find the values as part of the NeuronEnvironmentVariables element wrapper.

As you can see, the values are encrypted by default. However, Neuron will also read the values in plain text, so you can simply replace the encrypted value with whatever you like and it will be read correctly. If they are considered confidential, then you should open and save from within the Neuron Explorer and the values will be encrypted.

That is it. Remember that you can use Environment Variables for pretty much anything that is environment specific and let us know if you have any questions.