What are some common best practices one needs to consider while developing Apps in MuleSoft for clients, focusing Anypoint Studio 7.x.x and Mule 4.
List down your recommendations, which you have followed with any clients.
Please Note: I asked this general question to have a dedicated section of MuleSoft Development Best Practices on SO, rather than having similar titles where users having their personal agendas\user driven case scenario.
Mule Developers must considered this to be a critical topic.
Given below are the wide range of MuleSoft best practices which are involved during App development phase.
Development best practices are commonly divided into three categories:
Mule General Best Practices
Note: Suggestions are placed in <>. These are just best practices, not a compulsion.
Must use camelCase
>Must be all lower case with '-' in between words
>Must use camelCase
>First letters of each word must be capitalized. Spaces must be used between words
><All configurations must be declared as *key=value* in the property files>
Configuration properties must be segregated into files based on the *Environment* we deploy the app. Example "config-dev.properties", "config-qa.properties", "config-prod.properties"
><Should be used to fetch appropriate ".properties" files needed for the environment we deploy. Example, name your environment files as "/config-${env}.properties" using Configuration properties in global elements and pass 'env=dev' or 'env=qa' as a Runtime variables in Run Configurations. We can also pass global arguments like 'crypto.key=w4ref$%wrfw3', used to decrypt encrypted values>
A common rule of thumb is to use script files when the lines of code is greater than 10
>This keep the rest of mule xml files clean and tidy
>Using secure-properties-tools.jar or Mule property editor
>Achieved using 'mule-artifact.json'
>Helps you to have a clean process, removing unnecessary code manipulation and heap limitations
><Helps you by not over-burdening the Mule APP when deployed in cloudhub. Keeps the mule health monitor in check, so that the APP does not auto restart
>Mule Munits Best Practices
Have one major test case to run through the entire API once
><Have multiple test cases for each flow or subflows, testing for all possible failure situations, like testing mapping, choice routing etc>
<Never call your actual endpoints in Munits>
use #[MunitTools::getResourceAsString('testExample.json')]
>Mule Error Handling and Exception Scenario Best Practices
Source related data exceptions
>Target\End System exceptions (Not to be bothered by the Mule APP, but must be handled)
>Can you imagine all the hours of pain we can avoid by following some simple recommendations.
Hope you this helps !