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

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?

Related

Grails 3 plugin using properties from application.yml

I am creating a plugin using Grail 3 (3.2.11). My plugin needs to access different properties (e.g. URLs) for each environment (e.g. development, staging, production). When writing a Grails application I add the properties to the application.yml file. Where do they go in the plugin? I tried adding them to application.yml of the plugin and that does not work as expected. If I add them to the application.yml file of the application using the plugin they work. But I want the properties to be part of the plugin so each person who uses the plugin does not need to provide the properties. I would expect it to work like message properties. Where a plugin can have message properties and an application can override them by providing the same property in their local application message.properties. What am I not understanding.
In the same conf directory as application.yml you can place a plugin.yml (or plugin.groovy) which should allow you to change the plugin configuration similar to the way its done in the application's config file(s).

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.

One properties configuration file for Multi Apps on Mule ESB runtime

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

Can't get a Mule flow-reference to recognize imported resource (external flow) from an external jar

I cannot get a flow or a sub-flow that is in an external Mule application to display in the Flow name: drop-down of the Flow-Reference component of another project (my main project).
I have closely followed the example here from the MuleSoft documentation regarding the sharing of fragments.
It all works as per the tutorial, except I cannot get the external flow/sub-flow's name to appear in the drop-down of the main project's Flow-Reference component.
All of the maven stuff is fine.
The dependency is properly coded in the main Project's POM.
The jar displays in the Referenced Libraries.
The jar contains the application file I need (common-mule.xml).
If I force an error, by temporarily changing the name of import
resource, it correctly throws a not-found message. So, I know the
classpath is finding this external resource just fine.
BUT... when I double-click my Flow-Reference in the main project, I am not able to see the external flow in the flow names drop down.
Am I wrong about how this should work?
I tried doing the same thing and it is possible using the XML editor. My findings were -
If you are using maven the referenced project must be packaged as a jar and must be available on the referencing project's classpath.
You can refer to these for linking details:
https://docs.mulesoft.com/mule-user-guide/v/3.7/sharing-custom-code
https://docs.mulesoft.com/mule-user-guide/v/3.5/sharing-custom-configuration-fragments
After importing the xml as resource, you can simply type in the flow name in flow-ref and use it. It will give an error in the studio UI but the project is successfully built and the referenced flow is used as expected at runtime.
Its the bug with Studio UI only.
Make sure to use import of the flows in jar in your main project.
<spring:beans>
<spring:import resource="classpath:source_flow.xml"/>
<spring:import resource="classpath:global-config.xml"/>
</spring:beans>
Studio doesn't load elements from configuration files in JARs located on the build-path, so what you're trying to do is impossible (at least, currently).

Add class to build path using Mule Studio

I'm using Anypoint Studio with Mule Server 3.5.0 CE.
I have a custom transformer named CustomAsyncTransformer which is defined in the class AsyncTransformer.
Within one of my Mule flows:
<custom-transformer name="CustomAsyncTransformer" class="ca.mpac.esb.component.webservice.AsyncTransformer">
</custom-transformer>
This causes the following message to be displayed:
Unable to find type 'ca.mpac.esb.component.webservice.AsyncTransformer' on build path of project TEST-PROJECT
However, AsyncTransformer.class has been added to the build path; it is located in src/main/app which is designated as a source folder. I've also tried adding it directly to the build path, creating a new source folder, and adding it to other source folders. Still no change.
What am I doing wrong? How can I add this class to the build path?
Java source code should be in src/main/java. So your approach to add add a new source folder is correct, just use src/main/java so your Maven build will pick it up too.
Studio should pick the class from it. If it's not the case, it's maybe a bug? Or maybe something else: to find out show a screenshot of your application directory layout.