One properties configuration file for Multi Apps on Mule ESB runtime - mule

Today I have the same properties configurated on mule-app.properties file for each Apps. Like this:
All Apps (+ that 5) are running on the same Mule ESB runtime (CE).
For example, when It is necessary to change a host or password, I need to change the properties file of the all apps.
I would like to have just one properties file on Mule ESB runtime shared by all apps.
Is there a form to make this?
Thanks!

You can create a new Mule project and call it "shared". Now, in this project, you can create a file src/main/resources/config.properties and there put all the settings you need.
To have these settings in your current project, just add the project "shared" in the "Projects" tab of the "Java Build Path". Then in the main file of your current project, write
< context: property-placeholder location="config.properties" />

Use a Spring Property Placeholder and read a single file from the filesystem:
<context:property-placeholder location="file:/path/to/myConfigFile.properties" />
https://docs.mulesoft.com/mule-user-guide/v/3.6/configuring-properties#properties-files

Related

How to view all properties from a configuration file in runtime manager

I use configuration files for all properties of my apps, that is working fine. Running them on cloud hub I would like to have these properties show up in the app settings of the runtime manager (for reviewing or editing the settings "on the fly" without a new deployment).
I know you can overwrite them via the settings, but I would like to see the list of all properties beforehand – like if you don't use configuration files but submit them via the deployment dialog.
Any way to archive this?
In Anypoint Runtime Manager you can only see the properties defined there. Properties files are not inspectable nor visible.

Dynamically selecting log4j2 configuration in Mule

I have gone through Mule Logging documentation but not clear on how to dynamically load different logging configuration files for each environments. Basically I want to control log verbosity and sync/async feature across environments so looking for similar feature of dynamically selecting property file based on server environment property variable.
2 ways you can load the log4j2 file dynamically in your application either from an external path or from your application classpath:-
setting the log4j2 file path in your application's mule-deploy.properties like :-
log.configFile=E:\common-log4j2.xml
Loading the log4j2.xml in your application programmatically by reconfiguring the log manager via Spring and load our own log4j2.xml file from your defined path:-
ref:- https://dzone.com/articles/getting-own-log4j2-file-for-mule-via-spring
I haven't tried it, but you should be able to set the log4j config file at the command line when launching Mule, using the log4j.configuration system property.
For example (in Windows) by adding -Dlog4j.configuration=c:\some-path\log4j-%MULE-ENV%.xml if your env variable is called MULE-ENV.
Note that there are several places this can be set - directly on the command line if using Mule standalone (in which case I believe you need -M-Dlog4j.configuration=...), in the wrapper.conf file if using standalone, or in the VM params section of the Arguments tab in Run Configurations when running in Studio.
You can have a bean in your application which can call the method to set the configuration. You can pass the environment name as an argument to this bean, it'll pick the configuration file associated with that environment. You can call the method using the invoke component and have this flow executed at the startup.
Till the flow is executed, default logging configuration can be used.

Accessing mule-app.properties in custom properties file located in src/main/resources on cloudhub

I have a mule application built using mule apikit. The mule-app.properties file contains below property:
orig.db.url=jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;
The custom properties file src/main/resources/dev.properties contains below property:
db.url=${orig.db.url}
And, the mule configuration xml file contains below property-placeholder:
<context:property-placeholder location="dev.properties"/>
Now, when I deploy it locally everything works fine and I am able to run the flow. But, at the same time when I deploy on Cloudhub it gives me below exception:
Invalid bean definition with name 'get:/total_amount:total_amount-db-config' defined in null: Could not resolve placeholder 'orig.db.url' in string value "jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;"
I am unable to understand what am I missing here?
How did you deploy to CloudHub? If you used the deployment tool from Anypoint Studio you have an option to set properties before deployment.
The mule-app.properties will get added to system properties instead of classpath properties. We can't refer to system properties from property files added to classpath. We need to move these properties to classpath to resolve these in runtime.
One way to override this behaviour by importing mule-app.properties using:
<context:property-placeholder location="mule-app.properties,dev.properties”/>
It tells spring to load properties in respective order. So, first mule-app.properties gets loaded and then dev.properties.
But, its not the best practice to include the mule-app.properties file in the classpath. Best way is to remove the dev properties from mule-app.properties and put it inside dev.properties.
By default when deploying to cloudhub all properties from the mule-app.properties should appear in the properties tab. Did you not see them when you deployed the first time?

How to override mule config file name in Mule Studio?

MuleStudio or its plugin for eclipse uses mule-config.xml file by default. Is there an option to override the file name?
There are two options.
Right click on the Mule Project and go to
Run As --> Run COnfigurations
Then Select Java Application. Then right click and select New
Add your config file name as shown in the picture and run it.
Create a mule-deploy.properties and keep it in the src/main/app folder.
Add the configuration resource entry to it. This will be helpful when you package and deploy mule application onto a mule standalone server.
config.resources=my-mule-config.xml
Refer to the following link for more detials on Mule in Eclipse.
Creating a Mule project in Eclipse
Hope this helps.
you can rename the file by right clicking on it and select refactor or select the file and click F2 to rename it and then run the application as Mule run configurations.

Mule Deployment properties file

I have seen some strange behaviour in Mule Application. I created a sample mule project(created flows) and opened mule-deploy.properties file "config.resources" value is empty.
But the same above mentioned key value is getting updated with "configuration xml file name" when i run my mule project.
Is this the behaviour or any updates need to be done.
Can some clarify?
Regards
Vikram
There are some known issues/features around mule-deploy.properties and Mule Studio.
Currently it is expected that when running your project from Mule Studio that mule-deploy.properties-config.resources is automatically populated with all your configuration files.
There are some open issues on this here: https://www.mulesoft.org/jira/browse/STUDIO-3297 that you can vote on.
Once you run the mule application it will automatically updated with the configuration file by default if you have only one main configuration file.But If you are using more configuration files in your application you should manually add all the filenames to the config.properties key separated by comma before run the application.