Notifications could be a very powerful tool to get visibility into business-related events inside your application. They become especially useful in the following situations:
- your application is unable to connect to a remote service;
- an error that requires human intervention occurs, for example a problem with data mapping;
- you want to create an overview of what occurred inside your application, for instance retrieve a number of orders processed.
In my current project, we have a requirement to raise alerts like INFO, WARN, ERROR accompanied by custom messages. These alerts are particularly helpful to the development/support teams to act immediately instead of going through huge log files.
Here is another example from one of my projects. We had a requirement to synchronise data between two systems. As per API-led connectivity approach we used a 3-layered architecture: experience, process and system APIs, so I had to check all the 3(!) API logs to retrieve the below statuses:
- the initiation of data sync in the experience API,
- the completion of data chunks in the process API,
- the acknowledgement of data sync completion status in the system API,
- the error occurrences and connectivity related issues between the APIs/systems.
Using custom CloudHub notifications we could easily access the project status changes. To trigger alerts all we had to do is to click on the bell icon in the top-right corner of the Runtime Manager.
The screenshot bellow demonstrates how I raised INFO, WARN and ERROR custom messages. For the alerts I was using the default colours, black, yellow and red, depending on the severity of the problem. You can use your own custom payload based on your project requirements.
There are a few things you should be aware about:
- to create custom alerts, you need to get the CloudHub Connector and install it in your MuleSoft Anypoint Studio,
- custom alerts and notifications are available only for applications deployed to CloudHub workers. They are not available for applications that you deploy to your on-premises servers,
- CloudHub supports up to 1000 notifications per application and up to 10,000 characters per notification message.
And, finally the source code.
Define the 'CloudHub Config' and use the 'create notification' wherever needed.
You can download the source code here.
I hope you found this guide useful. Let me know if you have any questions or would like me to cover other topics.