Mule 4 - Mule Server Notifications
Every API to be developed on any technology will have both Functional and Non Functional Requirements to it.
- Functional Requirements are defined by client who will use the API.
- Non Functional Requirements are mandatory for any API to make the API available, be consistent, scalable and perform efficiently.
- Performance is one such metric which define one of the non functional requirements.
API Performance
Performance is key factor to consider if an API is implemented and delivered efficiently and optimally. In any project life cycle, right before the production deployment or Go-Live Non Functional Requirements testing is a mandatory phase. Where performance testing is also carried out.
During design of any API we define SLAs with client systems on response time of an API which when breached is considered as a NFR defect.
And so response time is the base metric which defines the performance of the API.
Whenever we talk about an API, we know that it comprises of message processors, API invocations etc.
API invocations can be of different types like
- Invoking External or Third Party APIs
- Invoking Process API from Experience API, System API from Process API
Developer will not have any control on response time of external/third-party APIs since they are being developed by external vendors and they abide to their own SLAs
But when it comes to process APIs and system APIs, the response times have to be handled independently since they are internal and controlled by the internal developer.
So message processor optimizations are only the way to optimize the performance or response time of over all API.
This article explains on usage of Mule Server Notifications for logging and notifying response times of message processors present in Mule Flows using "Message Processor Notification"
This feature helps a developer during NFR testing if there are any SLA breaches with respect to performance metrics.
Use case:
As a developer I want to optimize the response times of each message processor in a mule flow so that overall response time of the API is largely optimized.
Implementation Steps :
- Create a Mule Project
- Create a Class - MuleComponentProcessListener in src/main/java folder.
- This class implements MessageProcessorNotificationListener Interface where we will be using onNotification() method to log and notify.
- Create beans.xml file in src/main/resources folder
- Create a bean as below in beans.xml specifying the class created in step 2 for the type of notification we want to receive.
<bean name="messageProcessorNotifications" class="message_processor_notifications.MuleComponentProcessListener" />
- Add beans.xml reference to Spring Configuration as below
<spring:config name="springConfig" doc:name="Spring Config" files="beans.xml" />
- Mule Configuration:
We have to specify notifications we want to receive using <notification> element and have to register the listener class bean using <notification-listener> as below in Mule Configuration File.
Note: Listener Class is the Spring bean which we created in beans.xml at step 4
<notifications>
<notification event="MESSAGE-PROCESSOR" />
<notification-listener ref="messageProcessorNotifications" />
</notifications>
- Listener Class:
Testing:
Please find the step by step guide, codebase and video tutorial links provided below for implementing mule server notifications in mule flows.
Guide: https://docs.google.com/presentation/d/1luonPyU1QfOCNNotgv6jR2v3kSt4Xo_0z1JjwKzHhQ8/edit?usp=sharing
Codebase: https://github.com/praneethveni/mule-artifacts/tree/master/message_processor_notifications
Video Tutorial: https://youtu.be/Pb313qfPOJk
Step by Step Implementation Guide:
Tutorial Video :
Codebase :